http://git-wip-us.apache.org/repos/asf/flink/blob/e83217bd/flink-core/src/test/java/org/apache/flink/core/memory/MemorySegmentTestBase.java
----------------------------------------------------------------------
diff --git 
a/flink-core/src/test/java/org/apache/flink/core/memory/MemorySegmentTestBase.java
 
b/flink-core/src/test/java/org/apache/flink/core/memory/MemorySegmentTestBase.java
index 10c3622..8c10902 100644
--- 
a/flink-core/src/test/java/org/apache/flink/core/memory/MemorySegmentTestBase.java
+++ 
b/flink-core/src/test/java/org/apache/flink/core/memory/MemorySegmentTestBase.java
@@ -18,7 +18,6 @@
 
 package org.apache.flink.core.memory;
 
-import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runners.Parameterized;
 
@@ -67,1508 +66,1675 @@ public abstract class MemorySegmentTestBase {
 
        @Test
        public void testByteAccess() {
-               try {
-                       final MemorySegment segment = createSegment(pageSize);
-
-                       // test exceptions
-                       try {
-                               segment.put(-1, (byte) 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               final MemorySegment segment = createSegment(pageSize);
 
-                       try {
-                               segment.put(pageSize, (byte) 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // test exceptions
+               try {
+                       segment.put(-1, (byte) 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.put(Integer.MAX_VALUE, (byte) 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.put(pageSize, (byte) 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.put(Integer.MIN_VALUE, (byte) 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.put(Integer.MAX_VALUE, (byte) 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.get(-1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.put(Integer.MIN_VALUE, (byte) 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.get(pageSize);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(-1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.get(Integer.MAX_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(pageSize);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.get(Integer.MIN_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(Integer.MAX_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       // test expected correct behavior, sequential access
+               try {
+                       segment.get(Integer.MIN_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       long seed = random.nextLong();
+               // test expected correct behavior, sequential access
 
-                       random.setSeed(seed);
-                       for (int i = 0; i < pageSize; i++) {
-                               segment.put(i, (byte) random.nextInt());
-                       }
+               long seed = random.nextLong();
 
-                       random.setSeed(seed);
-                       for (int i = 0; i < pageSize; i++) {
-                               assertEquals((byte) random.nextInt(), 
segment.get(i));
-                       }
+               random.setSeed(seed);
+               for (int i = 0; i < pageSize; i++) {
+                       segment.put(i, (byte) random.nextInt());
+               }
 
-                       // test expected correct behavior, random access
+               random.setSeed(seed);
+               for (int i = 0; i < pageSize; i++) {
+                       assertEquals((byte) random.nextInt(), segment.get(i));
+               }
 
-                       random.setSeed(seed);
-                       boolean[] occupied = new boolean[pageSize];
+               // test expected correct behavior, random access
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize);
+               random.setSeed(seed);
+               boolean[] occupied = new boolean[pageSize];
 
-                               if (occupied[pos]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                               }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize);
 
-                               segment.put(pos, (byte) random.nextInt());
+                       if (occupied[pos]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
                        }
 
-                       random.setSeed(seed);
-                       occupied = new boolean[pageSize];
+                       segment.put(pos, (byte) random.nextInt());
+               }
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize);
+               random.setSeed(seed);
+               occupied = new boolean[pageSize];
 
-                               if (occupied[pos]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                               }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize);
 
-                               assertEquals((byte) random.nextInt(), 
segment.get(pos));
+                       if (occupied[pos]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
                        }
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+
+                       assertEquals((byte) random.nextInt(), segment.get(pos));
                }
 
        }
 
        @Test
        public void testBooleanAccess() {
-               try {
-                       final MemorySegment segment = createSegment(pageSize);
-
-                       // test exceptions
-                       try {
-                               segment.putBoolean(-1, false);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               final MemorySegment segment = createSegment(pageSize);
 
-                       try {
-                               segment.putBoolean(pageSize, false);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // test exceptions
+               try {
+                       segment.putBoolean(-1, false);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putBoolean(Integer.MAX_VALUE, false);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putBoolean(pageSize, false);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putBoolean(Integer.MIN_VALUE, false);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putBoolean(Integer.MAX_VALUE, false);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getBoolean(-1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putBoolean(Integer.MIN_VALUE, false);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getBoolean(pageSize);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getBoolean(-1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getBoolean(Integer.MAX_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getBoolean(pageSize);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getBoolean(Integer.MIN_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getBoolean(Integer.MAX_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       // test expected correct behavior, sequential access
+               try {
+                       segment.getBoolean(Integer.MIN_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       long seed = random.nextLong();
+               // test expected correct behavior, sequential access
 
-                       random.setSeed(seed);
-                       for (int i = 0; i < pageSize; i++) {
-                               segment.putBoolean(i, random.nextBoolean());
-                       }
+               long seed = random.nextLong();
 
-                       random.setSeed(seed);
-                       for (int i = 0; i < pageSize; i++) {
-                               assertEquals(random.nextBoolean(), 
segment.getBoolean(i));
-                       }
+               random.setSeed(seed);
+               for (int i = 0; i < pageSize; i++) {
+                       segment.putBoolean(i, random.nextBoolean());
+               }
 
-                       // test expected correct behavior, random access
+               random.setSeed(seed);
+               for (int i = 0; i < pageSize; i++) {
+                       assertEquals(random.nextBoolean(), 
segment.getBoolean(i));
+               }
 
-                       random.setSeed(seed);
-                       boolean[] occupied = new boolean[pageSize];
+               // test expected correct behavior, random access
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize);
+               random.setSeed(seed);
+               boolean[] occupied = new boolean[pageSize];
 
-                               if (occupied[pos]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                               }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize);
 
-                               segment.putBoolean(pos, random.nextBoolean());
+                       if (occupied[pos]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
                        }
 
-                       random.setSeed(seed);
-                       occupied = new boolean[pageSize];
+                       segment.putBoolean(pos, random.nextBoolean());
+               }
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize);
+               random.setSeed(seed);
+               occupied = new boolean[pageSize];
 
-                               if (occupied[pos]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                               }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize);
 
-                               assertEquals(random.nextBoolean(), 
segment.getBoolean(pos));
+                       if (occupied[pos]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
                        }
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+
+                       assertEquals(random.nextBoolean(), 
segment.getBoolean(pos));
                }
        }
 
        @Test
        public void testCharAccess() {
+               final MemorySegment segment = createSegment(pageSize);
+
+               // test exceptions
+
                try {
-                       final MemorySegment segment = createSegment(pageSize);
+                       segment.putChar(-1, 'a');
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       // test exceptions
+               try {
+                       segment.putChar(pageSize, 'a');
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putChar(-1, 'a');
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putChar(Integer.MIN_VALUE, 'a');
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putChar(pageSize, 'a');
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putChar(Integer.MAX_VALUE, 'a');
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putChar(Integer.MIN_VALUE, 'a');
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putChar(Integer.MAX_VALUE - 1, 'a');
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putChar(Integer.MAX_VALUE, 'a');
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getChar(-1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putChar(Integer.MAX_VALUE - 1, 'a');
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getChar(pageSize);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getChar(-1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getChar(Integer.MIN_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getChar(pageSize);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getChar(Integer.MAX_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getChar(Integer.MIN_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getChar(Integer.MAX_VALUE - 1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getChar(Integer.MAX_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // test expected correct behavior, sequential access
 
-                       try {
-                               segment.getChar(Integer.MAX_VALUE - 1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               long seed = random.nextLong();
 
-                       // test expected correct behavior, sequential access 
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 2; i += 2) {
+                       segment.putChar(i, (char) 
(random.nextInt(Character.MAX_VALUE)));
+               }
 
-                       long seed = random.nextLong();
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 2; i += 2) {
+                       assertEquals((char) 
(random.nextInt(Character.MAX_VALUE)), segment.getChar(i));
+               }
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 2; i += 2) {
-                               segment.putChar(i, (char) 
(random.nextInt(Character.MAX_VALUE)));
-                       }
+               // test expected correct behavior, random access
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 2; i += 2) {
-                               assertEquals((char) 
(random.nextInt(Character.MAX_VALUE)), segment.getChar(i));
-                       }
+               random.setSeed(seed);
+               boolean[] occupied = new boolean[pageSize];
 
-                       // test expected correct behavior, random access 
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 1);
 
-                       random.setSeed(seed);
-                       boolean[] occupied = new boolean[pageSize];
+                       if (occupied[pos] || occupied[pos + 1]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                       }
+
+                       segment.putChar(pos, (char) 
(random.nextInt(Character.MAX_VALUE)));
+               }
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 1);
+               random.setSeed(seed);
+               occupied = new boolean[pageSize];
 
-                               if (occupied[pos] || occupied[pos + 1]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                               }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 1);
 
-                               segment.putChar(pos, (char) 
(random.nextInt(Character.MAX_VALUE)));
+                       if (occupied[pos] || occupied[pos + 1]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
                        }
 
-                       random.setSeed(seed);
-                       occupied = new boolean[pageSize];
+                       assertEquals((char) 
(random.nextInt(Character.MAX_VALUE)), segment.getChar(pos));
+               }
+       }
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 1);
+       @Test
+       public void testShortAccess() {
+               final MemorySegment segment = createSegment(pageSize);
 
-                               if (occupied[pos] || occupied[pos + 1]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                               }
+               // test exceptions
 
-                               assertEquals((char) 
(random.nextInt(Character.MAX_VALUE)), segment.getChar(pos));
-                       }
+               try {
+                       segment.putShort(-1, (short) 0);
+                       fail("IndexOutOfBoundsException expected");
                }
                catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+                       assertTrue(e instanceof IndexOutOfBoundsException);
                }
-       }
 
-       @Test
-       public void testShortAccess() {
                try {
-                       final MemorySegment segment = createSegment(pageSize);
+                       segment.putShort(pageSize, (short) 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       // test exceptions
+               try {
+                       segment.putShort(Integer.MIN_VALUE, (short) 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putShort(-1, (short) 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putShort(Integer.MAX_VALUE, (short) 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putShort(pageSize, (short) 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putShort(Integer.MAX_VALUE - 1, (short) 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putShort(Integer.MIN_VALUE, (short) 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getShort(-1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putShort(Integer.MAX_VALUE, (short) 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getShort(pageSize);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putShort(Integer.MAX_VALUE - 1, (short) 
0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getShort(Integer.MIN_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getShort(-1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getShort(Integer.MAX_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getShort(pageSize);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getShort(Integer.MAX_VALUE - 1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getShort(Integer.MIN_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // test expected correct behavior, sequential access
 
-                       try {
-                               segment.getShort(Integer.MAX_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               long seed = random.nextLong();
 
-                       try {
-                               segment.getShort(Integer.MAX_VALUE - 1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 2; i += 2) {
+                       segment.putShort(i, (short) random.nextInt());
+               }
 
-                       // test expected correct behavior, sequential access
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 2; i += 2) {
+                       assertEquals((short) random.nextInt(), 
segment.getShort(i));
+               }
 
-                       long seed = random.nextLong();
+               // test expected correct behavior, random access
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 2; i += 2) {
-                               segment.putShort(i, (short) random.nextInt());
-                       }
+               random.setSeed(seed);
+               boolean[] occupied = new boolean[pageSize];
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 2; i += 2) {
-                               assertEquals((short) random.nextInt(), 
segment.getShort(i));
-                       }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 1);
 
-                       // test expected correct behavior, random access
+                       if (occupied[pos] || occupied[pos + 1]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                       }
 
-                       random.setSeed(seed);
-                       boolean[] occupied = new boolean[pageSize];
+                       segment.putShort(pos, (short) random.nextInt());
+               }
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 1);
+               random.setSeed(seed);
+               occupied = new boolean[pageSize];
 
-                               if (occupied[pos] || occupied[pos + 1]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                               }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 1);
 
-                               segment.putShort(pos, (short) random.nextInt());
+                       if (occupied[pos] || occupied[pos + 1]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
                        }
 
-                       random.setSeed(seed);
-                       occupied = new boolean[pageSize];
+                       assertEquals((short) random.nextInt(), 
segment.getShort(pos));
+               }
+       }
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 1);
+       @Test
+       public void testIntAccess() {
+               final MemorySegment segment = createSegment(pageSize);
 
-                               if (occupied[pos] || occupied[pos + 1]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                               }
+               // test exceptions
 
-                               assertEquals((short) random.nextInt(), 
segment.getShort(pos));
-                       }
+               try {
+                       segment.putInt(-1, 0);
+                       fail("IndexOutOfBoundsException expected");
                }
                catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+                       assertTrue(e instanceof IndexOutOfBoundsException);
                }
-       }
 
-       @Test
-       public void testIntAccess() {
                try {
-                       final MemorySegment segment = createSegment(pageSize);
+                       segment.putInt(pageSize, 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       // test exceptions
+               try {
+                       segment.putInt(pageSize - 3, 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putInt(-1, 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putInt(Integer.MIN_VALUE, 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putInt(pageSize, 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putInt(Integer.MAX_VALUE, 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putInt(pageSize - 3, 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putInt(Integer.MAX_VALUE - 3, 0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putInt(Integer.MIN_VALUE, 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getInt(-1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putInt(Integer.MAX_VALUE, 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getInt(pageSize);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putInt(Integer.MAX_VALUE - 3, 0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getInt(pageSize - 3);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getInt(-1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getInt(Integer.MIN_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getInt(pageSize);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getInt(Integer.MAX_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getInt(pageSize - 3);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getInt(Integer.MAX_VALUE - 3);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getInt(Integer.MIN_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // test expected correct behavior, sequential access
 
-                       try {
-                               segment.getInt(Integer.MAX_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               long seed = random.nextLong();
 
-                       try {
-                               segment.getInt(Integer.MAX_VALUE - 3);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 4; i += 4) {
+                       segment.putInt(i, random.nextInt());
+               }
 
-                       // test expected correct behavior, sequential access
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 4; i += 4) {
+                       assertEquals(random.nextInt(), segment.getInt(i));
+               }
 
-                       long seed = random.nextLong();
+               // test expected correct behavior, random access
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 4; i += 4) {
-                               segment.putInt(i, random.nextInt());
-                       }
+               random.setSeed(seed);
+               boolean[] occupied = new boolean[pageSize];
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 4; i += 4) {
-                               assertEquals(random.nextInt(), 
segment.getInt(i));
-                       }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 3);
 
-                       // test expected correct behavior, random access
+                       if (occupied[pos] || occupied[pos + 1] || occupied[pos 
+ 2] || occupied[pos + 3]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                               occupied[pos+2] = true;
+                               occupied[pos+3] = true;
+                       }
 
-                       random.setSeed(seed);
-                       boolean[] occupied = new boolean[pageSize];
-
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 3);
-
-                               if (occupied[pos] || occupied[pos + 1] || 
occupied[pos + 2] || occupied[pos + 3]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                                       occupied[pos+2] = true;
-                                       occupied[pos+3] = true;
-                               }
+                       segment.putInt(pos, random.nextInt());
+               }
 
-                               segment.putInt(pos, random.nextInt());
-                       }
+               random.setSeed(seed);
+               occupied = new boolean[pageSize];
 
-                       random.setSeed(seed);
-                       occupied = new boolean[pageSize];
-
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 3);
-
-                               if (occupied[pos] || occupied[pos + 1] || 
occupied[pos + 2] || occupied[pos + 3]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                                       occupied[pos+2] = true;
-                                       occupied[pos+3] = true;
-                               }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 3);
 
-                               assertEquals(random.nextInt(), 
segment.getInt(pos));
+                       if (occupied[pos] || occupied[pos + 1] || occupied[pos 
+ 2] || occupied[pos + 3]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                               occupied[pos+2] = true;
+                               occupied[pos+3] = true;
                        }
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+
+                       assertEquals(random.nextInt(), segment.getInt(pos));
                }
        }
 
        @Test
        public void testLongAccess() {
-               try {
-                       final MemorySegment segment = createSegment(pageSize);
+               final MemorySegment segment = createSegment(pageSize);
 
-                       // test exceptions
-
-                       try {
-                               segment.putLong(-1, 0L);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // test exceptions
 
-                       try {
-                               segment.putLong(pageSize, 0L);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putLong(-1, 0L);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putLong(pageSize - 7, 0L);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putLong(pageSize, 0L);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putLong(Integer.MIN_VALUE, 0L);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putLong(pageSize - 7, 0L);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putLong(Integer.MAX_VALUE, 0L);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putLong(Integer.MIN_VALUE, 0L);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putLong(Integer.MAX_VALUE - 7, 0L);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putLong(Integer.MAX_VALUE, 0L);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getLong(-1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putLong(Integer.MAX_VALUE - 7, 0L);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getLong(pageSize);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getLong(-1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getLong(pageSize - 7);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getLong(pageSize);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getLong(Integer.MIN_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getLong(pageSize - 7);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getLong(Integer.MAX_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getLong(Integer.MIN_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getLong(Integer.MAX_VALUE - 7);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getLong(Integer.MAX_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       // test expected correct behavior, sequential access
+               try {
+                       segment.getLong(Integer.MAX_VALUE - 7);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       long seed = random.nextLong();
+               // test expected correct behavior, sequential access
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 8; i += 8) {
-                               segment.putLong(i, random.nextLong());
-                       }
+               long seed = random.nextLong();
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 8; i += 8) {
-                               assertEquals(random.nextLong(), 
segment.getLong(i));
-                       }
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 8; i += 8) {
+                       segment.putLong(i, random.nextLong());
+               }
 
-                       // test expected correct behavior, random access
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 8; i += 8) {
+                       assertEquals(random.nextLong(), segment.getLong(i));
+               }
 
-                       random.setSeed(seed);
-                       boolean[] occupied = new boolean[pageSize];
+               // test expected correct behavior, random access
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 7);
+               random.setSeed(seed);
+               boolean[] occupied = new boolean[pageSize];
 
-                               if (occupied[pos] || occupied[pos + 1] || 
occupied[pos + 2] || occupied[pos + 3] ||
-                                               occupied[pos + 4] || 
occupied[pos + 5] || occupied[pos + 6] || occupied[pos + 7])
-                               {
-                                       continue;
-                               }
-                               else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                                       occupied[pos+2] = true;
-                                       occupied[pos+3] = true;
-                                       occupied[pos+4] = true;
-                                       occupied[pos+5] = true;
-                                       occupied[pos+6] = true;
-                                       occupied[pos+7] = true;
-                               }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 7);
 
-                               segment.putLong(pos, random.nextLong());
+                       if (occupied[pos] || occupied[pos + 1] || occupied[pos 
+ 2] || occupied[pos + 3] ||
+                                       occupied[pos + 4] || occupied[pos + 5] 
|| occupied[pos + 6] || occupied[pos + 7])
+                       {
+                               continue;
+                       }
+                       else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                               occupied[pos+2] = true;
+                               occupied[pos+3] = true;
+                               occupied[pos+4] = true;
+                               occupied[pos+5] = true;
+                               occupied[pos+6] = true;
+                               occupied[pos+7] = true;
                        }
 
-                       random.setSeed(seed);
-                       occupied = new boolean[pageSize];
+                       segment.putLong(pos, random.nextLong());
+               }
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 7);
+               random.setSeed(seed);
+               occupied = new boolean[pageSize];
 
-                               if (occupied[pos] || occupied[pos + 1] || 
occupied[pos + 2] || occupied[pos + 3] ||
-                                               occupied[pos + 4] || 
occupied[pos + 5] || occupied[pos + 6] || occupied[pos + 7])
-                               {
-                                       continue;
-                               }
-                               else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                                       occupied[pos+2] = true;
-                                       occupied[pos+3] = true;
-                                       occupied[pos+4] = true;
-                                       occupied[pos+5] = true;
-                                       occupied[pos+6] = true;
-                                       occupied[pos+7] = true;
-                               }
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 7);
 
-                               assertEquals(random.nextLong(), 
segment.getLong(pos));
+                       if (occupied[pos] || occupied[pos + 1] || occupied[pos 
+ 2] || occupied[pos + 3] ||
+                                       occupied[pos + 4] || occupied[pos + 5] 
|| occupied[pos + 6] || occupied[pos + 7])
+                       {
+                               continue;
                        }
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+                       else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                               occupied[pos+2] = true;
+                               occupied[pos+3] = true;
+                               occupied[pos+4] = true;
+                               occupied[pos+5] = true;
+                               occupied[pos+6] = true;
+                               occupied[pos+7] = true;
+                       }
+
+                       assertEquals(random.nextLong(), segment.getLong(pos));
                }
        }
 
        @Test
        public void testFloatAccess() {
-               try {
-                       final MemorySegment segment = createSegment(pageSize);
+               final MemorySegment segment = createSegment(pageSize);
 
-                       // test exceptions
+               // test exceptions
 
-                       try {
-                               segment.putFloat(-1, 0.0f);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putFloat(-1, 0.0f);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putFloat(pageSize, 0.0f);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putFloat(pageSize, 0.0f);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putFloat(pageSize - 3, 0.0f);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putFloat(pageSize - 3, 0.0f);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putFloat(Integer.MIN_VALUE, 0.0f);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putFloat(Integer.MIN_VALUE, 0.0f);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putFloat(Integer.MAX_VALUE, 0.0f);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putFloat(Integer.MAX_VALUE, 0.0f);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putFloat(Integer.MAX_VALUE - 3, 0.0f);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putFloat(Integer.MAX_VALUE - 3, 0.0f);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getFloat(-1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getFloat(-1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getFloat(pageSize);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getFloat(pageSize);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getFloat(pageSize - 3);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getFloat(pageSize - 3);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getFloat(Integer.MIN_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getFloat(Integer.MIN_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getFloat(Integer.MAX_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getFloat(Integer.MAX_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getFloat(Integer.MAX_VALUE - 3);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getFloat(Integer.MAX_VALUE - 3);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       // test expected correct behavior, sequential access
+               // test expected correct behavior, sequential access
 
-                       long seed = random.nextLong();
+               long seed = random.nextLong();
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 4; i += 4) {
-                               segment.putFloat(i, random.nextFloat());
-                       }
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 4; i += 4) {
+                       segment.putFloat(i, random.nextFloat());
+               }
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 4; i += 4) {
-                               assertEquals(random.nextFloat(), 
segment.getFloat(i), 0.0);
-                       }
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 4; i += 4) {
+                       assertEquals(random.nextFloat(), segment.getFloat(i), 
0.0);
+               }
 
-                       // test expected correct behavior, random access
+               // test expected correct behavior, random access
 
-                       random.setSeed(seed);
-                       boolean[] occupied = new boolean[pageSize];
-
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 3);
-
-                               if (occupied[pos] || occupied[pos + 1] || 
occupied[pos + 2] || occupied[pos + 3]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                                       occupied[pos+2] = true;
-                                       occupied[pos+3] = true;
-                               }
+               random.setSeed(seed);
+               boolean[] occupied = new boolean[pageSize];
 
-                               segment.putFloat(pos, random.nextFloat());
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 3);
+
+                       if (occupied[pos] || occupied[pos + 1] || occupied[pos 
+ 2] || occupied[pos + 3]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                               occupied[pos+2] = true;
+                               occupied[pos+3] = true;
                        }
 
-                       random.setSeed(seed);
-                       occupied = new boolean[pageSize];
-
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 3);
-
-                               if (occupied[pos] || occupied[pos + 1] || 
occupied[pos + 2] || occupied[pos + 3]) {
-                                       continue;
-                               } else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                                       occupied[pos+2] = true;
-                                       occupied[pos+3] = true;
-                               }
+                       segment.putFloat(pos, random.nextFloat());
+               }
+
+               random.setSeed(seed);
+               occupied = new boolean[pageSize];
+
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 3);
 
-                               assertEquals(random.nextFloat(), 
segment.getFloat(pos), 0.0);
+                       if (occupied[pos] || occupied[pos + 1] || occupied[pos 
+ 2] || occupied[pos + 3]) {
+                               continue;
+                       } else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                               occupied[pos+2] = true;
+                               occupied[pos+3] = true;
                        }
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+
+                       assertEquals(random.nextFloat(), segment.getFloat(pos), 
0.0);
                }
        }
 
        @Test
        public void testDoubleAccess() {
+               final MemorySegment segment = createSegment(pageSize);
+
+               // test exceptions
                try {
-                       final MemorySegment segment = createSegment(pageSize);
+                       segment.putDouble(-1, 0.0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       // test exceptions
-                       try {
-                               segment.putDouble(-1, 0.0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putDouble(pageSize, 0.0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putDouble(pageSize, 0.0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putDouble(pageSize - 7, 0.0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putDouble(pageSize - 7, 0.0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putDouble(Integer.MIN_VALUE, 0.0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putDouble(Integer.MIN_VALUE, 0.0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putDouble(Integer.MAX_VALUE, 0.0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putDouble(Integer.MAX_VALUE, 0.0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.putDouble(Integer.MAX_VALUE - 7, 0.0);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.putDouble(Integer.MAX_VALUE - 7, 0.0);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getDouble(-1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getDouble(-1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getDouble(pageSize);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getDouble(pageSize);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getDouble(pageSize - 7);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getDouble(pageSize - 7);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getDouble(Integer.MIN_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getDouble(Integer.MIN_VALUE);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.getDouble(Integer.MAX_VALUE);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.getDouble(Integer.MAX_VALUE);
-                               fail("IndexOutOfBoundsException expected");
+               try {
+                       segment.getDouble(Integer.MAX_VALUE - 7);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               // test expected correct behavior, sequential access
+
+               long seed = random.nextLong();
+
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 8; i += 8) {
+                       segment.putDouble(i, random.nextDouble());
+               }
+
+               random.setSeed(seed);
+               for (int i = 0; i <= pageSize - 8; i += 8) {
+                       assertEquals(random.nextDouble(), segment.getDouble(i), 
0.0);
+               }
+
+               // test expected correct behavior, random access
+
+               random.setSeed(seed);
+               boolean[] occupied = new boolean[pageSize];
+
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 7);
+
+                       if (occupied[pos] || occupied[pos + 1] || occupied[pos 
+ 2] || occupied[pos + 3] ||
+                                       occupied[pos + 4] || occupied[pos + 5] 
|| occupied[pos + 6] || occupied[pos + 7])
+                       {
+                               continue;
                        }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                       else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                               occupied[pos+2] = true;
+                               occupied[pos+3] = true;
+                               occupied[pos+4] = true;
+                               occupied[pos+5] = true;
+                               occupied[pos+6] = true;
+                               occupied[pos+7] = true;
                        }
 
-                       try {
-                               segment.getDouble(Integer.MAX_VALUE - 7);
-                               fail("IndexOutOfBoundsException expected");
+                       segment.putDouble(pos, random.nextDouble());
+               }
+
+               random.setSeed(seed);
+               occupied = new boolean[pageSize];
+
+               for (int i = 0; i < 1000; i++) {
+                       int pos = random.nextInt(pageSize - 7);
+
+                       if (occupied[pos] || occupied[pos + 1] || occupied[pos 
+ 2] || occupied[pos + 3] ||
+                                       occupied[pos + 4] || occupied[pos + 5] 
|| occupied[pos + 6] || occupied[pos + 7])
+                       {
+                               continue;
                        }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                       else {
+                               occupied[pos] = true;
+                               occupied[pos+1] = true;
+                               occupied[pos+2] = true;
+                               occupied[pos+3] = true;
+                               occupied[pos+4] = true;
+                               occupied[pos+5] = true;
+                               occupied[pos+6] = true;
+                               occupied[pos+7] = true;
                        }
 
-                       // test expected correct behavior, sequential access
+                       assertEquals(random.nextDouble(), 
segment.getDouble(pos), 0.0);
+               }
+       }
 
-                       long seed = random.nextLong();
+       // 
------------------------------------------------------------------------
+       //  Bulk Byte Movements
+       // 
------------------------------------------------------------------------
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 8; i += 8) {
-                               segment.putDouble(i, random.nextDouble());
-                       }
+       @Test
+       public void testBulkBytePutExceptions() {
+               final MemorySegment segment = createSegment(pageSize);
 
-                       random.setSeed(seed);
-                       for (int i = 0; i <= pageSize - 8; i += 8) {
-                               assertEquals(random.nextDouble(), 
segment.getDouble(i), 0.0);
-                       }
+               byte[] bytes = new byte[pageSize / 4 + (pageSize%4)];
+               random.nextBytes(bytes);
 
-                       // test expected correct behavior, random access
+               // wrong positions into memory segment
 
-                       random.setSeed(seed);
-                       boolean[] occupied = new boolean[pageSize];
+               try {
+                       segment.put(-1, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 7);
+               try {
+                       segment.put(-1, bytes, 4, 5);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                               if (occupied[pos] || occupied[pos + 1] || 
occupied[pos + 2] || occupied[pos + 3] ||
-                                               occupied[pos + 4] || 
occupied[pos + 5] || occupied[pos + 6] || occupied[pos + 7])
-                               {
-                                       continue;
-                               }
-                               else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                                       occupied[pos+2] = true;
-                                       occupied[pos+3] = true;
-                                       occupied[pos+4] = true;
-                                       occupied[pos+5] = true;
-                                       occupied[pos+6] = true;
-                                       occupied[pos+7] = true;
-                               }
+               try {
+                       segment.put(Integer.MIN_VALUE, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                               segment.putDouble(pos, random.nextDouble());
-                       }
+               try {
+                       segment.put(Integer.MIN_VALUE, bytes, 4, 5);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       random.setSeed(seed);
-                       occupied = new boolean[pageSize];
+               try {
+                       segment.put(pageSize, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       for (int i = 0; i < 1000; i++) {
-                               int pos = random.nextInt(pageSize - 7);
+               try {
+                       segment.put(pageSize, bytes, 6, 44);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                               if (occupied[pos] || occupied[pos + 1] || 
occupied[pos + 2] || occupied[pos + 3] ||
-                                               occupied[pos + 4] || 
occupied[pos + 5] || occupied[pos + 6] || occupied[pos + 7])
-                               {
-                                       continue;
-                               }
-                               else {
-                                       occupied[pos] = true;
-                                       occupied[pos+1] = true;
-                                       occupied[pos+2] = true;
-                                       occupied[pos+3] = true;
-                                       occupied[pos+4] = true;
-                                       occupied[pos+5] = true;
-                                       occupied[pos+6] = true;
-                                       occupied[pos+7] = true;
-                               }
+               try {
+                       segment.put(pageSize - bytes.length + 1, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                               assertEquals(random.nextDouble(), 
segment.getDouble(pos), 0.0);
-                       }
+               try {
+                       segment.put(pageSize - 5, bytes, 3, 6);
+                       fail("IndexOutOfBoundsException expected");
                }
                catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+                       assertTrue(e instanceof IndexOutOfBoundsException);
                }
-       }
 
-       // 
------------------------------------------------------------------------
-       //  Bulk Byte Movements
-       // 
------------------------------------------------------------------------
+               try {
+                       segment.put(Integer.MAX_VALUE, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(Integer.MAX_VALUE, bytes, 10, 20);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(Integer.MAX_VALUE - bytes.length + 1, 
bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(Integer.MAX_VALUE - 11, bytes, 11, 11);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(3 * (pageSize / 4) + 1, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(3 * (pageSize / 4) + 2, bytes, 0, 
bytes.length - 1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(7 * (pageSize / 8) + 1, bytes, 0, 
bytes.length / 2);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               // wrong source array positions / lengths
+
+               try {
+                       segment.put(0, bytes, -1, 1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(0, bytes, -1, bytes.length + 1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(0, bytes, Integer.MIN_VALUE, bytes.length);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(0, bytes, Integer.MAX_VALUE, bytes.length);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.put(0, bytes, Integer.MAX_VALUE - bytes.length 
+ 1, bytes.length);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               // case where negative offset and negative index compensate 
each other
+               try {
+                       segment.put(-2, bytes, -1, bytes.length / 2);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+       }
 
        @Test
-       public void testBulkBytePutExceptions() {
+       public void testBulkByteGetExceptions() {
+               final MemorySegment segment = createSegment(pageSize);
+
+               byte[] bytes = new byte[pageSize / 4];
+
+               // wrong positions into memory segment
+
                try {
-                       final MemorySegment segment = createSegment(pageSize);
+                       segment.get(-1, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       byte[] bytes = new byte[pageSize / 4 + (pageSize%4)];
-                       random.nextBytes(bytes);
+               try {
+                       segment.get(-1, bytes, 4, 5);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       // wrong positions into memory segment
+               try {
+                       segment.get(Integer.MIN_VALUE, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.put(-1, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(Integer.MIN_VALUE, bytes, 4, 5);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.put(-1, bytes, 4, 5);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(pageSize, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.put(Integer.MIN_VALUE, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(pageSize, bytes, 6, 44);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.put(Integer.MIN_VALUE, bytes, 4, 5);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(pageSize - bytes.length + 1, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.put(pageSize, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(pageSize - 5, bytes, 3, 6);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.put(pageSize, bytes, 6, 44);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(Integer.MAX_VALUE, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
 
-                       try {
-                               segment.put(pageSize - bytes.length + 1, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               try {
+                       segment.get(Integer.MAX_VALUE, bytes, 10, 20);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.get(Integer.MAX_VALUE - bytes.length + 1, 
bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.get(Integer.MAX_VALUE - 11, bytes, 11, 11);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.get(3 * (pageSize / 4) + 1, bytes);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.get(3 * (pageSize / 4) + 2, bytes, 0, 
bytes.length - 1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.get(7 * (pageSize / 8) + 1, bytes, 0, 
bytes.length / 2);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               // wrong source array positions / lengths
+
+               try {
+                       segment.get(0, bytes, -1, 1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.get(0, bytes, -1, bytes.length + 1);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.get(0, bytes, Integer.MIN_VALUE, bytes.length);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.get(0, bytes, Integer.MAX_VALUE, bytes.length);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               try {
+                       segment.get(0, bytes, Integer.MAX_VALUE - bytes.length 
+ 1, bytes.length);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+
+               // case where negative offset and negative index compensate 
each other
+               try {
+                       segment.get(-2, bytes, -1, bytes.length / 2);
+                       fail("IndexOutOfBoundsException expected");
+               }
+               catch (Exception e) {
+                       assertTrue(e instanceof IndexOutOfBoundsException);
+               }
+       }
+
+       @Test
+       public void testBulkByteAccess() {
+               // test expected correct behavior with default offset / length
+               {
+                       final MemorySegment segment = createSegment(pageSize);
+                       long seed = random.nextLong();
 
-                       try {
-                               segment.put(pageSize - 5, bytes, 3, 6);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                       random.setSeed(seed);
+                       byte[] src = new byte[pageSize / 8];
+                       for (int i = 0; i < 8; i++) {
+                               random.nextBytes(src);
+                               segment.put(i * (pageSize / 8), src);
                        }
 
-                       try {
-                               segment.put(Integer.MAX_VALUE, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+                       random.setSeed(seed);
+                       byte[] expected = new byte[pageSize / 8];
+                       byte[] actual = new byte[pageSize / 8];
+                       for (int i = 0; i < 8; i++) {
+                               random.nextBytes(expected);
+                               segment.get(i * (pageSize / 8), actual);
 
-                       try {
-                               segment.put(Integer.MAX_VALUE, bytes, 10, 20);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                               assertArrayEquals(expected, actual);
                        }
+               }
 
-                       try {
-                               segment.put(Integer.MAX_VALUE - bytes.length + 
1, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // test expected correct behavior with specific offset / length
+               {
+                       final MemorySegment segment = createSegment(pageSize);
+                       byte[] expected = new byte[pageSize];
+                       random.nextBytes(expected);
 
-                       try {
-                               segment.put(Integer.MAX_VALUE - 11, bytes, 11, 
11);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                       for (int i = 0; i < 16; i++) {
+                               segment.put(i * (pageSize / 16), expected, i * 
(pageSize / 16),
+                                               pageSize / 16);
                        }
 
-                       try {
-                               segment.put(3 * (pageSize / 4) + 1, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                       byte[] actual = new byte[pageSize];
+                       for (int i = 0; i < 16; i++) {
+                               segment.get(i * (pageSize / 16), actual, i * 
(pageSize / 16),
+                                               pageSize / 16);
                        }
 
-                       try {
-                               segment.put(3 * (pageSize / 4) + 2, bytes, 0, 
bytes.length - 1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+                       assertArrayEquals(expected, actual);
+               }
 
-                       try {
-                               segment.put(7 * (pageSize / 8) + 1, bytes, 0, 
bytes.length / 2);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // put segments of various lengths to various positions
+               {
+                       final MemorySegment segment = createSegment(pageSize);
+                       byte[] expected = new byte[pageSize];
 
-                       // wrong source array positions / lengths
+                       for (int i = 0; i < 200; i++) {
+                               int numBytes = random.nextInt(pageSize - 10) + 
1;
+                               int pos = random.nextInt(pageSize - numBytes + 
1);
 
-                       try {
-                               segment.put(0, bytes, -1, 1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+                               byte[] data = new byte[(random.nextInt(3) + 1) 
* numBytes];
+                               int dataStartPos = random.nextInt(data.length - 
numBytes + 1);
 
-                       try {
-                               segment.put(0, bytes, -1, bytes.length + 1);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+                               random.nextBytes(data);
 
-                       try {
-                               segment.put(0, bytes, Integer.MIN_VALUE, 
bytes.length);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+                               // copy to the expected
+                               System.arraycopy(data, dataStartPos, expected, 
pos, numBytes);
 
-                       try {
-                               segment.put(0, bytes, Integer.MAX_VALUE, 
bytes.length);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                               // put to the memory segment
+                               segment.put(pos, data, dataStartPos, numBytes);
                        }
 
-                       try {
-                               segment.put(0, bytes, Integer.MAX_VALUE - 
bytes.length + 1, bytes.length);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+                       byte[] validation = new byte[pageSize];
+                       segment.get(0, validation);
 
-                       // case where negative offset and negative index 
compensate each other
-                       try {
-                               segment.put(-2, bytes, -1, bytes.length / 2);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+                       assertArrayEquals(expected, validation);
                }
-       }
 
-       @Test
-       public void testBulkByteGetExceptions() {
-               try {
+               // get segments with various contents
+               {
                        final MemorySegment segment = createSegment(pageSize);
+                       byte[] contents = new byte[pageSize];
+                       random.nextBytes(contents);
+                       segment.put(0, contents);
 
-                       byte[] bytes = new byte[pageSize / 4];
+                       for (int i = 0; i < 200; i++) {
+                               int numBytes = random.nextInt(pageSize / 8) + 1;
+                               int pos = random.nextInt(pageSize - numBytes + 
1);
 
-                       // wrong positions into memory segment
+                               byte[] data = new byte[(random.nextInt(3) + 1) 
* numBytes];
+                               int dataStartPos = random.nextInt(data.length - 
numBytes + 1);
 
-                       try {
-                               segment.get(-1, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+                               segment.get(pos, data, dataStartPos, numBytes);
 
-                       try {
-                               segment.get(-1, bytes, 4, 5);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                               byte[] expected = Arrays.copyOfRange(contents, 
pos, pos + numBytes);
+                               byte[] validation = Arrays.copyOfRange(data, 
dataStartPos, dataStartPos + numBytes);
+                               assertArrayEquals(expected, validation);
                        }
+               }
+       }
 
-                       try {
-                               segment.get(Integer.MIN_VALUE, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+       // 
------------------------------------------------------------------------
+       //  Writing / Reading to/from DataInput / DataOutput
+       // 
------------------------------------------------------------------------
 
-                       try {
-                               segment.get(Integer.MIN_VALUE, bytes, 4, 5);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+       @Test
+       public void testDataInputOutput() throws IOException {
+               MemorySegment seg = createSegment(pageSize);
+               byte[] contents = new byte[pageSize];
+               random.nextBytes(contents);
+               seg.put(0, contents);
 
-                       try {
-                               segment.get(pageSize, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               ByteArrayOutputStream buffer = new 
ByteArrayOutputStream(pageSize);
+               DataOutputStream out = new DataOutputStream(buffer);
 
-                       try {
-                               segment.get(pageSize, bytes, 6, 44);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // write the segment in chunks into the stream
+               int pos = 0;
+               while (pos < pageSize) {
+                       int len = random.nextInt(200);
+                       len = Math.min(len, pageSize - pos);
+                       seg.get(out, pos, len);
+                       pos += len;
+               }
 
-                       try {
-                               segment.get(pageSize - bytes.length + 1, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // verify that we wrote the same bytes
+               byte[] result = buffer.toByteArray();
+               assertArrayEquals(contents, result);
 
-                       try {
-                               segment.get(pageSize - 5, bytes, 3, 6);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // re-read the bytes into a new memory segment
+               MemorySegment reader = createSegment(pageSize);
+               DataInputStream in = new DataInputStream(new 
ByteArrayInputStream(result));
 
-                       try {
-                               segment.get(Integer.MAX_VALUE, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               pos = 0;
+               while (pos < pageSize) {
+                       int len = random.nextInt(200);
+                       len = Math.min(len, pageSize - pos);
+                       reader.put(in, pos, len);
+                       pos += len;
+               }
 
-                       try {
-                               segment.get(Integer.MAX_VALUE, bytes, 10, 20);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               byte[] targetBuffer = new byte[pageSize];
+               reader.get(0, targetBuffer);
 
-                       try {
-                               segment.get(Integer.MAX_VALUE - bytes.length + 
1, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               assertArrayEquals(contents, targetBuffer);
+       }
 
-                       try {
-                               segment.get(Integer.MAX_VALUE - 11, bytes, 11, 
11);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+       @Test
+       public void testDataInputOutputOutOfBounds() {
+               final int segmentSize = 52;
 
-                       try {
-                               segment.get(3 * (pageSize / 4) + 1, bytes);
-                               fail("IndexOutOfBoundsException expected");
-                       }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
+               // segment with random contents
+               MemorySegment seg = createSegment(segmentSize);
+               byte[] bytes = new byte[segmentSize];
+               random.nextBytes(bytes);
+               seg.put(0, bytes);
+
+               // out of bounds when writing
+               {
+                       DataOutputStream out = new DataOutputStream(new 
ByteArrayOutputStream());
 
                        try {
-                               segment.get(3 * (pageSize / 4) + 2, bytes, 0, 
bytes.length - 1);
+                               seg.get(out, -1, segmentSize / 2);
                                fail("IndexOutOfBoundsException expected");
                        }
                        catch (Exception e) {
@@ -1576,17 +1742,15 @@ public abstract class MemorySegmentTestBase {
                        }
 
                        try {
-                               segment.get(7 * (pageSize / 8) + 1, bytes, 0, 
bytes.length / 2);
+                               seg.get(out, segmentSize, segmentSize / 2);
                                fail("IndexOutOfBoundsException expected");
                        }
                        catch (Exception e) {
                                assertTrue(e instanceof 
IndexOutOfBoundsException);
                        }
 
-                       // wrong source array positions / lengths
-
                        try {
-                               segment.get(0, bytes, -1, 1);
+                               seg.get(out, -segmentSize, segmentSize / 2);
                                fail("IndexOutOfBoundsException expected");
                        }
                        catch (Exception e) {
@@ -1594,7 +1758,7 @@ public abstract class MemorySegmentTestBase {
                        }
 
                        try {
-                               segment.get(0, bytes, -1, bytes.length + 1);
+                               seg.get(out, Integer.MIN_VALUE, segmentSize / 
2);
                                fail("IndexOutOfBoundsException expected");
                        }
                        catch (Exception e) {
@@ -1602,15 +1766,20 @@ public abstract class MemorySegmentTestBase {
                        }
 
                        try {
-                               segment.get(0, bytes, Integer.MIN_VALUE, 
bytes.length);
+                               seg.get(out, Integer.MAX_VALUE, segmentSize / 
2);
                                fail("IndexOutOfBoundsException expected");
                        }
                        catch (Exception e) {
                                assertTrue(e instanceof 
IndexOutOfBoundsException);
                        }
+               }
+
+               // out of bounds when reading
+               {
+                       DataInputStream in = new DataInputStream(new 
ByteArrayInputStream(new byte[segmentSize]));
 
                        try {
-                               segment.get(0, bytes, Integer.MAX_VALUE, 
bytes.length);
+                               seg.put(in, -1, segmentSize / 2);
                                fail("IndexOutOfBoundsException expected");
                        }
                        catch (Exception e) {
@@ -1618,345 +1787,91 @@ public abstract class MemorySegmentTestBase {
                        }
 
                        try {
-                               segment.get(0, bytes, Integer.MAX_VALUE - 
bytes.length + 1, bytes.length);
+                               seg.put(in, segmentSize, segmentSize / 2);
                                fail("IndexOutOfBoundsException expected");
                        }
                        catch (Exception e) {
                                assertTrue(e instanceof 
IndexOutOfBoundsException);
                        }
 
-                       // case where negative offset and negative index 
compensate each other
                        try {
-                               segment.get(-2, bytes, -1, bytes.length / 2);
+                               seg.put(in, -segmentSize, segmentSize / 2);
                                fail("IndexOutOfBoundsException expected");
                        }
-                       catch (Exception e) {
-                               assertTrue(e instanceof 
IndexOutOfBoundsException);
-                       }
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
-               }
-       }
-
-       @Test
-       public void testBulkByteAccess() {
-               try {
-                       // test expected correct behavior with default offset / 
length
-                       {
-                               final MemorySegment segment = 
createSegment(pageSize);
-                               long seed = random.nextLong();
-
-                               random.setSeed(seed);
-                               byte[] src = new byte[pageSize / 8];
-                               for (int i = 0; i < 8; i++) {
-                                       random.nextBytes(src);
-                                       segment.put(i * (pageSize / 8), src);
-                               }
-
-                               random.setSeed(seed);
-                               byte[] expected = new byte[pageSize / 8];
-                               byte[] actual = new byte[pageSize / 8];
-                               for (int i = 0; i < 8; i++) {
-                                       random.nextBytes(expected);
-                                       segment.get(i * (pageSize / 8), actual);
-
-                                       assertArrayEquals(expected, actual);
-                               }
-                       }
-
-                       // test expected correct behavior with specific offset 
/ length
-                       {
-                               final MemorySegment segment = 
createSegment(pageSize);
-                               byte[] expected = new byte[pageSize];
-                               random.nextBytes(expected);
-
-                               for (int i = 0; i < 16; i++) {
-                                       segment.put(i * (pageSize / 16), 
expected, i * (pageSize / 16),
-                                                       pageSize / 16);
-                               }
-
-                               byte[] actual = new byte[pageSize];
-                               for (int i = 0; i < 16; i++) {
-                                       segment.get(i * (pageSize / 16), 
actual, i * (pageSize / 16),
-                                                       pageSize / 16);
-                               }
-
-                               assertArrayEquals(expected, actual);
-                       }
-                       
-                       // put segments of various lengths to various positions
-                       {
-                               final MemorySegment segment = 
createSegment(pageSize);
-                               byte[] expected = new byte[pageSize];
-                               
-                               for (int i = 0; i < 200; i++) {
-                                       int numBytes = random.nextInt(pageSize 
- 10) + 1;
-                                       int pos = random.nextInt(pageSize - 
numBytes + 1);
-                                       
-                                       byte[] data = new 
byte[(random.nextInt(3) + 1) * numBytes];
-                                       int dataStartPos = 
random.nextInt(data.length - numBytes + 1);
-                                       
-                                       random.nextBytes(data);
-                                       
-                                       // copy to the expected
-                                       System.arraycopy(data, dataStartPos, 
expected, pos, numBytes);
-                                       
-                                       // put to the memory segment
-                                       segment.put(pos, data, dataStartPos, 
numBytes);
-                               }
-                               
-                               byte[] validation = new byte[pageSize];
-                               segment.get(0, validation);
-                               
-                               assertArrayEquals(expected, validation);
-                       }
-                       
-                       // get segments with various contents
-                       {
-                               final MemorySegment segment = 
createSegment(pageSize);
-                               byte[] contents = new byte[pageSize];
-                               random.nextBytes(contents);
-                               segment.put(0, contents);
-
-                               for (int i = 0; i < 200; i++) {
-                                       int numBytes = random.nextInt(pageSize 
/ 8) + 1;
-                                       int pos = random.nextInt(pageSize - 
numBytes + 1);
-
-                                       byte[] data = new 
byte[(random.nextInt(3) + 1) * numBytes];
-                                       int dataStartPos = 
random.nextInt(data.length - numBytes + 1);
-
-                                       segment.get(pos, data, dataStartPos, 
numBytes);
-                                       
-                                       byte[] expected = 
Arrays.copyOfRange(contents, pos, pos + numBytes);
-                                       byte[] validation = 
Arrays.copyOfRange(data, dataStartPos, dataStartPos + numBytes);
-                                       assertArrayEquals(expected, validation);
-                               }
-                       }
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
-               }
-       }
-
-       // 
------------------------------------------------------------------------
-       //  Writing / Reading to/from DataInput / DataOutput
-       // 
------------------------------------------------------------------------
-
-       @Test
-       public void testDataInputOutput() {
-               try {
-                       MemorySegment seg = createSegment(pageSize);
-                       byte[] contents = new byte[pageSize];
-                       random.nextBytes(contents);
-                       seg.put(0, contents);
-
-                       ByteArrayOutputStream buffer = new 
ByteArrayOutputStream(pageSize);
-                       DataOutputStream out = new DataOutputStream(buffer);
-
-                       // write the segment in chunks into the stream
-                       int pos = 0;
-                       while (pos < pageSize) {
-                               int len = random.nextInt(200);
-                               len = Math.min(len, pageSize - pos);
-                               seg.get(out, pos, len);
-                               pos += len;
-                       }
-
-                       // verify that we wrote the same bytes
-                       byte[] result = buffer.toByteArray();
-                       assertArrayEquals(contents, result);
-
-                       // re-read the bytes into a new memory segment
-                       MemorySegment reader = createSegment(pageSize);
-                       DataInputStream in = new DataInputStream(new 
ByteArrayInputStream(result));
+                       catch (Exception e) {
+                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                       }
 
-                       pos = 0;
-                       while (pos < pageSize) {
-                               int len = random.nextInt(200);
-                               len = Math.min(len, pageSize - pos);
-                               reader.put(in, pos, len);
-                               pos += len;
+                       try {
+                               seg.put(in, Integer.MIN_VALUE, segmentSize / 2);
+                               fail("IndexOutOfBoundsException expected");
+                       }
+                       catch (Exception e) {
+                               assertTrue(e instanceof 
IndexOutOfBoundsException);
                        }
 
-                       byte[] targetBuffer = new byte[pageSize];
-                       reader.get(0, targetBuffer);
-                       
-                       assertArrayEquals(contents, targetBuffer);
-               }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+                       try {
+                               seg.put(in, Integer.MAX_VALUE, segmentSize / 2);
+                               fail("IndexOutOfBoundsException expected");
+                       }
+                       catch (Exception e) {
+                               assertTrue(e instanceof 
IndexOutOfBoundsException);
+                       }
                }
        }
 
        @Test
-       public void testDataInputOutputOutOfBounds() {
-               try {
-                       final int segmentSize = 52;
-                       
-                       // segment with random contents
-                       MemorySegment seg = createSegment(segmentSize);
-                       byte[] bytes = new byte[segmentSize];
-                       random.nextBytes(bytes);
-                       seg.put(0, bytes);
-                       
-                       // out of bounds when writing
-                       {
-                               DataOutputStream out = new DataOutputStream(new 
ByteArrayOutputStream());
-                                       
-                               try {
-                                       seg.get(out, -1, segmentSize / 2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
-                               }
-       
-                               try {
-                                       seg.get(out, segmentSize, segmentSize / 
2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
-                               }
-       
-                               try {
-                                       seg.get(out, -segmentSize, segmentSize 
/ 2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
-                               }
-       
-                               try {
-                                       seg.get(out, Integer.MIN_VALUE, 
segmentSize / 2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
-                               }
-       
-                               try {
-                                       seg.get(out, Integer.MAX_VALUE, 
segmentSize / 2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
-                               }
-                       }
-
-                       // out of bounds when reading
-                       {
-                               DataInputStream in = new DataInputStream(new 
ByteArrayInputStream(new byte[segmentSize]));
-
-                               try {
-                                       seg.put(in, -1, segmentSize / 2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
-                               }
+       public void testDataInputOutputStreamUnderflowOverflow() throws 
IOException {
+               final int segmentSize = 1337;
 
-                               try {
-                                       seg.put(in, segmentSize, segmentSize / 
2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
-                               }
+               // segment with random contents
+               MemorySegment seg = createSegment(segmentSize);
+               byte[] bytes = new byte[segmentSize];
+               random.nextBytes(bytes);
+               seg.put(0, bytes);
 
-                               try {
-                                       seg.put(in, -segmentSize, segmentSize / 
2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
-                               }
+               // a stream that we cannot fully write to
+               DataOutputStream out = new DataOutputStream(new OutputStream() {
 
-                               try {
-                                       seg.put(in, Integer.MIN_VALUE, 
segmentSize / 2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
+                       int bytesSoFar = 0;
+                       @Override
+                       public void write(int b) throws IOException {
+                               bytesSoFar++;
+                               if (bytesSoFar > segmentSize / 2) {
+                                       throw new IOException("overflow");
                                }
+                       }
+               });
 
-                               try {
-                                       seg.put(in, Integer.MAX_VALUE, 
segmentSize / 2);
-                                       fail("IndexOutOfBoundsException 
expected");
-                               }
-                               catch (Exception e) {
-                                       assertTrue(e instanceof 
IndexOutOfBoundsException);
-                               }
+               // write the segment in chunks into the stream
+               try {
+                       int pos = 0;
+                       while (pos < pageSize) {
+                               int len = random.nextInt(segmentSize / 10);
+                               len = Math.min(len, pageSize - pos);
+                               seg.get(out, pos, len);
+                               pos += len;
                        }
+                       fail("Should fail with an IOException");
                }
-               catch (Exception e) {
-                       e.printStackTrace();
-                       fail(e.getMessage());
+               catch (IOException e) {
+                       // expected
                }
-       }
-
-       @Test
-       public void testDataInputOutputStreamUnderflowOverflow() {
-               try {
-                       final int segmentSize = 1337;
-
-                       // segment with random contents
-                       MemorySegment seg = createSegment(segmentSize);
-                       byte[] bytes = new byte[segmentSize];
-                       random.nextBytes(bytes);
-                       seg.put(0, bytes);
-                       
-                       // a stream that we cannot fully write to
-                       DataOutputStream out = new DataOutputStream(new 
OutputStream() {
-       

<TRUNCATED>

Reply via email to