geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject incubator-geode git commit: GEODE-680: refactor Chunk to cleanup unit tests 1) Promoted constant fields to default access level. 2) Modified getAddressForReading to delegate to getUnsafeAddress.
Date Thu, 17 Dec 2015 22:26:43 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop d31a85ff7 -> bb794ee20


GEODE-680: refactor Chunk to cleanup unit tests
1) Promoted constant fields to default access level.
2) Modified getAddressForReading to delegate to getUnsafeAddress.


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

Branch: refs/heads/develop
Commit: bb794ee205400ac4e5655cc1e6410889d29f28b1
Parents: d31a85f
Author: Sai Boorlagadda <sboorlagadda@pivotal.io>
Authored: Wed Dec 16 13:03:19 2015 -0800
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Thu Dec 17 14:25:44 2015 -0800

----------------------------------------------------------------------
 .../gemfire/internal/offheap/Chunk.java         | 26 ++++++++++----------
 .../internal/offheap/GemFireChunkJUnitTest.java | 23 ++++++++---------
 2 files changed, 23 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb794ee2/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
index ed4bc43..4d1252d 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/Chunk.java
@@ -74,21 +74,21 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
      * a delta whose max value would be HUGE_MULTIPLE-1.
      * The lower two bytes contains the use count.
      */
-    private final static int REF_COUNT_OFFSET = 4;
+    final static int REF_COUNT_OFFSET = 4;
     /**
      * The upper two bits are used for the isSerialized
      * and isCompressed flags.
      */
-    private final static int IS_SERIALIZED_BIT =    0x80000000;
-    private final static int IS_COMPRESSED_BIT =    0x40000000;
-    private final static int SRC_TYPE_MASK = 0x38000000;
-    private final static int SRC_TYPE_SHIFT = 16/*refCount*/+8/*dataSize*/+3/*magicSize*/;
-    private final static int MAGIC_MASK = 0x07000000;
-    private final static int MAGIC_NUMBER = 0x05000000;
-    private final static int DATA_SIZE_DELTA_MASK = 0x00ff0000;
-    private final static int DATA_SIZE_SHIFT = 16;
-    private final static int REF_COUNT_MASK =       0x0000ffff;
-    private final static int MAX_REF_COUNT = 0xFFFF;
+    final static int IS_SERIALIZED_BIT =    0x80000000;
+    final static int IS_COMPRESSED_BIT =    0x40000000;
+    final static int SRC_TYPE_MASK = 0x38000000;
+    final static int SRC_TYPE_SHIFT = 16/*refCount*/+8/*dataSize*/+3/*magicSize*/;
+    final static int MAGIC_MASK = 0x07000000;
+    final static int MAGIC_NUMBER = 0x05000000;
+    final static int DATA_SIZE_DELTA_MASK = 0x00ff0000;
+    final static int DATA_SIZE_SHIFT = 16;
+    final static int REF_COUNT_MASK =       0x0000ffff;
+    final static int MAX_REF_COUNT = 0xFFFF;
     final static long FILL_PATTERN = 0x3c3c3c3c3c3c3c3cL;
     final static byte FILL_BYTE = 0x3c;
     
@@ -376,8 +376,8 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
     }
 
     public long getAddressForReading(int offset, int size) {
-      assert offset+size <= getDataSize();
-      return getBaseDataAddress() + offset;
+      //delegate to getUnsafeAddress - as both the methods does return the memory address
from given offset
+      return getUnsafeAddress(offset, size);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb794ee2/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/GemFireChunkJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/GemFireChunkJUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/GemFireChunkJUnitTest.java
index 20cb8dc..81a59e3 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/GemFireChunkJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/GemFireChunkJUnitTest.java
@@ -255,7 +255,7 @@ public class GemFireChunkJUnitTest extends AbstractStoredObjectTestBase
{
 
     GemFireChunk chunk = (GemFireChunk) ma.allocateAndInitialize(regionEntryValueAsBytes,
isSerialized, isCompressed, GemFireChunk.TYPE);
 
-    int headerBeforeSerializedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress()
+ 4/* REF_COUNT_OFFSET */);
+    int headerBeforeSerializedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress()
+ Chunk.REF_COUNT_OFFSET);
 
     assertThat(chunk.isSerialized()).isFalse();
 
@@ -263,9 +263,9 @@ public class GemFireChunkJUnitTest extends AbstractStoredObjectTestBase
{
 
     assertThat(chunk.isSerialized()).isTrue();
 
-    int headerAfterSerializedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress()
+ 4/* REF_COUNT_OFFSET */);
+    int headerAfterSerializedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress()
+ Chunk.REF_COUNT_OFFSET);
 
-    assertThat(headerAfterSerializedBitSet).isEqualTo(headerBeforeSerializedBitSet | 0x80000000/*
IS_SERIALIZED_BIT */);
+    assertThat(headerAfterSerializedBitSet).isEqualTo(headerBeforeSerializedBitSet | Chunk.IS_SERIALIZED_BIT);
 
     chunk.release();
   }
@@ -289,7 +289,7 @@ public class GemFireChunkJUnitTest extends AbstractStoredObjectTestBase
{
 
     GemFireChunk chunk = (GemFireChunk) ma.allocateAndInitialize(regionEntryValueAsBytes,
isSerialized, isCompressed, GemFireChunk.TYPE);
 
-    int headerBeforeCompressedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress()
+ 4/* REF_COUNT_OFFSET */);
+    int headerBeforeCompressedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress()
+ Chunk.REF_COUNT_OFFSET);
 
     assertThat(chunk.isCompressed()).isFalse();
 
@@ -297,9 +297,9 @@ public class GemFireChunkJUnitTest extends AbstractStoredObjectTestBase
{
 
     assertThat(chunk.isCompressed()).isTrue();
 
-    int headerAfterCompressedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress()
+ 4/* REF_COUNT_OFFSET */);
+    int headerAfterCompressedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress()
+ Chunk.REF_COUNT_OFFSET);
 
-    assertThat(headerAfterCompressedBitSet).isEqualTo(headerBeforeCompressedBitSet | 0x40000000/*
IS_SERIALIZED_BIT */);
+    assertThat(headerAfterCompressedBitSet).isEqualTo(headerBeforeCompressedBitSet | Chunk.IS_COMPRESSED_BIT);
 
     chunk.release();
   }
@@ -730,11 +730,8 @@ public class GemFireChunkJUnitTest extends AbstractStoredObjectTestBase
{
   public void retainShouldThrowExceptionAfterMaxNumberOfTimesRetained() {
     GemFireChunk chunk = createValueAsUnserializedStoredObject(getValue());
 
-    // max retain Chunk.MAX_REF_COUNT
-    int MAX_REF_COUNT = 0xFFFF;
-
     // loop though and invoke retain for MAX_REF_COUNT-1 times, as create chunk above counted
as one reference
-    for (int i = 0; i < MAX_REF_COUNT - 1; i++)
+    for (int i = 0; i < Chunk.MAX_REF_COUNT - 1; i++)
       chunk.retain();
 
     // invoke for the one more time should throw exception
@@ -891,7 +888,7 @@ public class GemFireChunkJUnitTest extends AbstractStoredObjectTestBase
{
   public void getSrcTypeOrdinalFromAddressShouldReturnOrdinal() {
     GemFireChunk chunk = createValueAsUnserializedStoredObject(getValue());
 
-    assertThat(Chunk.getSrcTypeOrdinal(chunk.getMemoryAddress())).isEqualTo(4);
+    assertThat(Chunk.getSrcTypeOrdinal(chunk.getMemoryAddress())).isEqualTo(Chunk.SRC_TYPE_GFE
>> Chunk.SRC_TYPE_SHIFT);
 
     chunk.release();
   }
@@ -900,8 +897,8 @@ public class GemFireChunkJUnitTest extends AbstractStoredObjectTestBase
{
   public void getSrcTypeOrdinalFromRawBitsShouldReturnOrdinal() {
     GemFireChunk chunk = createValueAsUnserializedStoredObject(getValue());
 
-    int rawBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress() + 4
/* REF_COUNT_OFFSET */);
-    assertThat(Chunk.getSrcTypeOrdinalFromRawBits(rawBits)).isEqualTo(4);
+    int rawBits = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress() + Chunk.REF_COUNT_OFFSET);
+    assertThat(Chunk.getSrcTypeOrdinalFromRawBits(rawBits)).isEqualTo(Chunk.SRC_TYPE_GFE
>> Chunk.SRC_TYPE_SHIFT);
 
     chunk.release();
   }


Mime
View raw message