geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [18/50] [abbrv] incubator-geode git commit: GEODE-626: add unit tests for MemoryChunk
Date Fri, 11 Dec 2015 21:22:52 GMT
GEODE-626: add unit tests for MemoryChunk

Added testGetSize and testCopyBytes.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/9283282c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/9283282c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/9283282c

Branch: refs/heads/feature/GEODE-217
Commit: 9283282c64076c5f8e599f3d47895f3c48e205e8
Parents: 3259c02
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Fri Dec 4 16:33:50 2015 -0800
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Fri Dec 4 16:47:24 2015 -0800

----------------------------------------------------------------------
 .../offheap/MemoryChunkJUnitTestBase.java       | 47 ++++++++++++++++++++
 1 file changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9283282c/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryChunkJUnitTestBase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryChunkJUnitTestBase.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryChunkJUnitTestBase.java
index 2e4eabb..c8c0b2b 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryChunkJUnitTestBase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryChunkJUnitTestBase.java
@@ -50,6 +50,53 @@ public abstract class MemoryChunkJUnitTestBase {
   }
   
   @Test
+  public void testGetSize() {
+    MemoryChunk mc = createChunk(5);
+    try {
+      assertEquals(5, mc.getSize());
+    } finally {
+      mc.release();
+    }
+    mc = createChunk(0);
+    try {
+      assertEquals(0, mc.getSize());
+    } finally {
+      mc.release();
+    }
+    mc = createChunk(1024);
+    try {
+      assertEquals(1024, mc.getSize());
+    } finally {
+      mc.release();
+    }
+  }
+  
+  @Test
+  public void testCopyBytes() {
+    int CHUNK_SIZE = 1024;
+    MemoryChunk mc = createChunk(CHUNK_SIZE*2);
+    try {
+      for (int i=0; i<CHUNK_SIZE; i++) {
+        mc.writeByte(i, (byte)(i%128));
+      }
+      for (int i=0; i<CHUNK_SIZE; i++) {
+        assertEquals(i%128, mc.readByte(i));
+      }
+      mc.copyBytes(0, CHUNK_SIZE, CHUNK_SIZE);
+      for (int i=0; i<CHUNK_SIZE; i++) {
+        assertEquals(i%128, mc.readByte(CHUNK_SIZE+i));
+      }
+      mc.copyBytes(0, 1, CHUNK_SIZE);
+      for (int i=0; i<CHUNK_SIZE; i++) {
+        assertEquals(i%128, mc.readByte(1+i));
+      }
+    } finally {
+      mc.release();
+    }
+  }
+ 
+  
+  @Test
   public void testByteArrayReadWrite() {
     byte[] writeBytes = new byte[256];
     int v = Byte.MIN_VALUE;


Mime
View raw message