// Path: src/test/java/org/sharedmq/test/CommonTests.java
// public interface CommonTests {
// }
// 
// Path: src/test/java/org/sharedmq/test/TestFolder.java
// public class TestFolder implements Closeable {
// 
//     private final File root;
// 
//     /**
//      * Creates an new folder in the default temporary-file directory.
//      *
//      * @param prefix The prefix for the new folder name.
//      * @param suffix The suffix for the new folder name.
//      * @throws IOException If folder creation fails.
//      */
//     public TestFolder(String prefix, String suffix) throws IOException {
//         root = File.createTempFile(prefix, suffix);
//         if (!root.delete() || !root.mkdir()) {
//             throw new IOException("Failed to prepare test folder.");
//         }
//     }
// 
//     /**
//      * Returns a {@link File} object matching this folder location.
//      */
//     public File getRoot() {
//         return root;
//     }
// 
//     /**
//      * Returns an {@link File} instance for the file with the given name in this test folder.
//      *
//      * @param filename The name of the faile.
//      */
//     public File getFile(String filename) {
//         return new File(root, filename);
//     }
// 
//     /**
//      * Deletes this test folder and all its content.
//      *
//      * @throws IOException
//      */
//     @Override
//     public void close() throws IOException {
// 
//         // A mapped byte buffer and the file mapping that it represents
//         // remain valid until the buffer itself is garbage-collected.
//         System.gc();
// 
//         IOUtils.deleteTree(root);
//     }
// }
// 
// Path: src/test/java/org/sharedmq/test/TestUtils.java
// public class TestUtils {
// 
//     // random is only used for quick generation of non-empty arrays
//     private static final Random random = new Random();
// 
//     public static <T extends Exception> void assertThrows(
//             Class<T> errorClass,
//             String expectedMessagePart,
//             TestedAction action
//     ) {
//         try {
//             action.invoke();
//             fail("an exception was expected");
//         } catch (AssertionError e) {
//             throw e;
//         } catch (Throwable e) {
//             if (!errorClass.isInstance(e)) {
//                 throw new AssertionError("Expected '" + errorClass.getName() + "'" +
//                         ", but encountered '" + e.getClass().getName() + "'."
//                         , e);
//             }
//             if (expectedMessagePart != null) {
//                 String message = e.getMessage();
//                 if (message == null || !message.contains(expectedMessagePart)) {
//                     throw new AssertionError("Expected an exception" +
//                             " with the message '..." + expectedMessagePart + "...'" +
//                             ", but encountered '" + e.getMessage() + "'."
//                             , e);
//                 }
//             }
//         }
//     }
// 
//     public interface TestedAction {
//         void invoke() throws Exception;
//     }
// 
//     public static byte[] generateArray(int length) {
//         byte[] array = new byte[length];
//         random.nextBytes(array);
//         return array;
//     }
// 
//     public static void printResult(String prefix, Stopwatch timer, int operationCount) {
//         printResult(prefix, timer.elapsed(TimeUnit.MILLISECONDS), operationCount);
//     }
// 
//     public static void printResult(String prefix, long timeSpent, int operationCount) {
//         String messagesPerSecond = timeSpent == 0 ? "unknown" : String.valueOf(operationCount * 1000L / timeSpent);
// 
//         long operationTime = timeSpent * 1000L / operationCount;
// 
//         System.out.println(Strings.padEnd(prefix, 39, ' ') +
//                 ": " + operationCount + " operations" +
//                 ", " + Strings.padStart(String.valueOf(timeSpent), 5, ' ') + "ms" +
//                 " (" + Strings.padStart(String.valueOf(operationTime), 5, ' ') + "\u00B5s per op." +
//                 ", " + Strings.padStart(messagesPerSecond, 6, ' ') + " op/second).");
//     }
// }


import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sharedmq.test.CommonTests;
import org.sharedmq.test.TestFolder;
import org.sharedmq.test.TestUtils;
import java.io.IOException;
import java.util.Arrays;
import static org.junit.Assert.*;
package org.sharedmq.primitives;




@Category(CommonTests.class)
public class MappedByteArrayStorageTest {

    @Test
    public void testSmoke() throws IOException {
        try (
                TestFolder testFolder = new TestFolder("MappedByteArrayStorageTest", "testSmoke");
                MemoryMappedFile file = new MemoryMappedFile(testFolder.getFile("test.dat"));
                MappedByteArrayStorage storage = new MappedByteArrayStorage(file)
        ) {
// Path: src/test/java/org/sharedmq/test/CommonTests.java
// public interface CommonTests {
// }
// 
// Path: src/test/java/org/sharedmq/test/TestFolder.java
// public class TestFolder implements Closeable {
// 
//     private final File root;
// 
//     /**
//      * Creates an new folder in the default temporary-file directory.
//      *
//      * @param prefix The prefix for the new folder name.
//      * @param suffix The suffix for the new folder name.
//      * @throws IOException If folder creation fails.
//      */
//     public TestFolder(String prefix, String suffix) throws IOException {
//         root = File.createTempFile(prefix, suffix);
//         if (!root.delete() || !root.mkdir()) {
//             throw new IOException("Failed to prepare test folder.");
//         }
//     }
// 
//     /**
//      * Returns a {@link File} object matching this folder location.
//      */
//     public File getRoot() {
//         return root;
//     }
// 
//     /**
//      * Returns an {@link File} instance for the file with the given name in this test folder.
//      *
//      * @param filename The name of the faile.
//      */
//     public File getFile(String filename) {
//         return new File(root, filename);
//     }
// 
//     /**
//      * Deletes this test folder and all its content.
//      *
//      * @throws IOException
//      */
//     @Override
//     public void close() throws IOException {
// 
//         // A mapped byte buffer and the file mapping that it represents
//         // remain valid until the buffer itself is garbage-collected.
//         System.gc();
// 
//         IOUtils.deleteTree(root);
//     }
// }
// 
// Path: src/test/java/org/sharedmq/test/TestUtils.java
// public class TestUtils {
// 
//     // random is only used for quick generation of non-empty arrays
//     private static final Random random = new Random();
// 
//     public static <T extends Exception> void assertThrows(
//             Class<T> errorClass,
//             String expectedMessagePart,
//             TestedAction action
//     ) {
//         try {
//             action.invoke();
//             fail("an exception was expected");
//         } catch (AssertionError e) {
//             throw e;
//         } catch (Throwable e) {
//             if (!errorClass.isInstance(e)) {
//                 throw new AssertionError("Expected '" + errorClass.getName() + "'" +
//                         ", but encountered '" + e.getClass().getName() + "'."
//                         , e);
//             }
//             if (expectedMessagePart != null) {
//                 String message = e.getMessage();
//                 if (message == null || !message.contains(expectedMessagePart)) {
//                     throw new AssertionError("Expected an exception" +
//                             " with the message '..." + expectedMessagePart + "...'" +
//                             ", but encountered '" + e.getMessage() + "'."
//                             , e);
//                 }
//             }
//         }
//     }
// 
//     public interface TestedAction {
//         void invoke() throws Exception;
//     }
// 
//     public static byte[] generateArray(int length) {
//         byte[] array = new byte[length];
//         random.nextBytes(array);
//         return array;
//     }
// 
//     public static void printResult(String prefix, Stopwatch timer, int operationCount) {
//         printResult(prefix, timer.elapsed(TimeUnit.MILLISECONDS), operationCount);
//     }
// 
//     public static void printResult(String prefix, long timeSpent, int operationCount) {
//         String messagesPerSecond = timeSpent == 0 ? "unknown" : String.valueOf(operationCount * 1000L / timeSpent);
// 
//         long operationTime = timeSpent * 1000L / operationCount;
// 
//         System.out.println(Strings.padEnd(prefix, 39, ' ') +
//                 ": " + operationCount + " operations" +
//                 ", " + Strings.padStart(String.valueOf(timeSpent), 5, ' ') + "ms" +
//                 " (" + Strings.padStart(String.valueOf(operationTime), 5, ' ') + "\u00B5s per op." +
//                 ", " + Strings.padStart(messagesPerSecond, 6, ' ') + " op/second).");
//     }
// }


// Path: src/test/java/org/sharedmq/primitives/MappedByteArrayStorageTest.java
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.sharedmq.test.CommonTests;
import org.sharedmq.test.TestFolder;
import org.sharedmq.test.TestUtils;
import java.io.IOException;
import java.util.Arrays;
import static org.junit.Assert.*;

package org.sharedmq.primitives;




@Category(CommonTests.class)
public class MappedByteArrayStorageTest {

    @Test
    public void testSmoke() throws IOException {
        try (
                TestFolder testFolder = new TestFolder("MappedByteArrayStorageTest", "testSmoke");
                MemoryMappedFile file = new MemoryMappedFile(testFolder.getFile("test.dat"));
                MappedByteArrayStorage storage = new MappedByteArrayStorage(file)
        ) {
            byte[] originalArray1 = TestUtils.generateArray(20);