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: refactor decodeAddressToBytes into two methods
Date Wed, 25 May 2016 00:25:16 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1451 [created] 9ef366e0c


refactor decodeAddressToBytes into two methods

The boolean parameters have been removed and two
methods now exist:
1. decodeAddressToRawBytes(long)
2. decodeUncompressedAddressToBytes(long)


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

Branch: refs/heads/feature/GEODE-1451
Commit: 9ef366e0c0dee93521bdbeb2361fe0dc2738d839
Parents: bd892f5
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Tue May 24 17:22:54 2016 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Tue May 24 17:22:54 2016 -0700

----------------------------------------------------------------------
 .../offheap/OffHeapRegionEntryHelper.java       | 27 ++++++++++++++------
 .../internal/offheap/TinyStoredObject.java      |  9 ++++---
 .../OffHeapRegionEntryHelperJUnitTest.java      | 17 +++++++++---
 3 files changed, 38 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9ef366e0/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
index 8b57c43..d90597f 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
@@ -261,7 +261,7 @@ public class OffHeapRegionEntryHelper {
   }
 
   static Object decodeAddressToObject(long ohAddress) {
-      byte[] bytes = decodeAddressToBytes(ohAddress, true, false);
+      byte[] bytes = decodeUncompressedAddressToBytes(ohAddress);
 
       boolean isSerialized = (ohAddress & SERIALIZED_BIT) != 0;
       if (isSerialized) {
@@ -280,9 +280,25 @@ public class OffHeapRegionEntryHelper {
     return (int) ((addr & SIZE_MASK) >> SIZE_SHIFT);
   }
   
-  static byte[] decodeAddressToBytes(long addr, boolean decompress, boolean compressedOk)
{
-    assert (addr & ENCODED_BIT) != 0;
+  /**
+   * Returns the bytes encoded in the given address.
+   * Note that compressed addresses are not supported by this method.
+   * @throws UnsupportedOperationException if the address has compressed data
+   */
+  static byte[] decodeUncompressedAddressToBytes(long addr) {
     boolean isCompressed = (addr & COMPRESSED_BIT) != 0;
+    if (isCompressed) {
+      throw new UnsupportedOperationException("Did not expect encoded address to be compressed");
+    }
+    return decodeAddressToRawBytes(addr);
+  }
+  
+  /**
+   * Returns the "raw" bytes that have been encoded in the given address.
+   * Note that if address is compressed then the raw bytes are the compressed bytes.
+   */
+  static byte[] decodeAddressToRawBytes(long addr) {
+    assert (addr & ENCODED_BIT) != 0;
     int size = (int) ((addr & SIZE_MASK) >> SIZE_SHIFT);
     boolean isLong = (addr & LONG_BIT) != 0;
     byte[] bytes;
@@ -305,11 +321,6 @@ public class OffHeapRegionEntryHelper {
         bytes[i] = (byte) (addr & 0x00ff);
       }
     }
-    if (decompress && isCompressed) {
-      if (!compressedOk) {
-        throw new UnsupportedOperationException("Did not expect encoded address to be compressed");
-      }
-    }
     return bytes;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9ef366e0/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/TinyStoredObject.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/TinyStoredObject.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/TinyStoredObject.java
index aee1b15..9404865 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/TinyStoredObject.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/TinyStoredObject.java
@@ -74,13 +74,14 @@ public class TinyStoredObject extends AbstractStoredObject {
   }
 
   public byte[] getDecompressedBytes(RegionEntryContext r) {
-    byte[] bytes = OffHeapRegionEntryHelper.decodeAddressToBytes(getAddress(), true, true);
     if (isCompressed()) {
+        byte[] bytes = OffHeapRegionEntryHelper.decodeAddressToRawBytes(getAddress());
         long time = r.getCachePerfStats().startDecompression();
         bytes = r.getCompressor().decompress(bytes);
         r.getCachePerfStats().endDecompression(time);
+        return bytes;
     }
-    return bytes;
+    return getRawBytes();
   }
 
   /**
@@ -88,12 +89,12 @@ public class TinyStoredObject extends AbstractStoredObject {
    * Otherwise return the serialize bytes in us in a byte array.
    */
   public byte[] getRawBytes() {
-    return OffHeapRegionEntryHelper.decodeAddressToBytes(getAddress(), true, false);
+    return OffHeapRegionEntryHelper.decodeUncompressedAddressToBytes(getAddress());
   }
   
   @Override
   public byte[] getSerializedValue() {
-    byte[] value = OffHeapRegionEntryHelper.decodeAddressToBytes(this.address, true, false);
+    byte[] value = getRawBytes();
     if (!isSerialized()) {
       value = EntryEventImpl.serialize(value);
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9ef366e0/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelperJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelperJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelperJUnitTest.java
index b9b3dfc..f3ee7c4 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelperJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelperJUnitTest.java
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*;
 import static org.mockito.Mockito.*;
 
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 
 import org.junit.After;
 import org.junit.Before;
@@ -212,7 +213,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
     long encodedAddress = 549755813697L;
     Integer value = Integer.MAX_VALUE;
 
-    byte[] actual = OffHeapRegionEntryHelper.decodeAddressToBytes(encodedAddress, false,
false);
+    byte[] actual = OffHeapRegionEntryHelper.decodeUncompressedAddressToBytes(encodedAddress);
     byte[] expectedValue = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt(value).array();
 
     assertThat(actual).isEqualTo(expectedValue);
@@ -223,7 +224,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
     Long value = 0L;
     long encodedAddress = 123L;
 
-    byte[] actual = OffHeapRegionEntryHelper.decodeAddressToBytes(encodedAddress, false,
false);
+    byte[] actual = OffHeapRegionEntryHelper.decodeUncompressedAddressToBytes(encodedAddress);
     byte[] expectedValue = EntryEventImpl.serialize(value);
 
     assertThat(actual).isEqualTo(expectedValue);
@@ -232,7 +233,17 @@ public class OffHeapRegionEntryHelperJUnitTest {
   @Test(expected = UnsupportedOperationException.class)
   public void decodeDataAsAddressShouldThrowExceptionIfDataIsCompressedAndItsNotOkToBeCompressed()
{
     long encodedAddress = 549755813703L;
-    OffHeapRegionEntryHelper.decodeAddressToBytes(encodedAddress, true, false);
+    OffHeapRegionEntryHelper.decodeUncompressedAddressToBytes(encodedAddress);
+  }
+  
+  @Test
+  public void decodeCompressedDataAsAddressToRawBytes() {
+    long encodedAddress = 549755813703L;
+    byte[] expected = new byte[]{127, -1, -1, -1};
+
+    byte[] bytes = OffHeapRegionEntryHelper.decodeAddressToRawBytes(encodedAddress);
+
+    assertThat(bytes).isEqualTo(expected);
   }
 
   @Test


Mime
View raw message