geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [2/2] incubator-geode git commit: review feedback, now uses assert keyword
Date Wed, 25 May 2016 22:39:18 GMT
review feedback, now uses assert keyword


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

Branch: refs/heads/feature/GEODE-1451
Commit: 9f4f1a97f86d8dbbe04c7412c8d27ea8c6fa64d0
Parents: 8178277
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Wed May 25 15:35:45 2016 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Wed May 25 15:35:45 2016 -0700

----------------------------------------------------------------------
 .../offheap/OffHeapRegionEntryHelper.java       |  5 +---
 .../OffHeapRegionEntryHelperJUnitTest.java      | 29 +++++++++++++++++---
 2 files changed, 26 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9f4f1a97/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 d90597f..0909306 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
@@ -286,10 +286,7 @@ public class OffHeapRegionEntryHelper {
    * @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");
-    }
+    assert (addr & COMPRESSED_BIT) == 0 : "Did not expect encoded address to be compressed";
     return decodeAddressToRawBytes(addr);
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9f4f1a97/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 0d60d0a..7190e8b 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
@@ -22,7 +22,9 @@ import static org.mockito.Mockito.*;
 import java.nio.ByteBuffer;
 
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
@@ -53,6 +55,25 @@ public class OffHeapRegionEntryHelperJUnitTest {
 
   private static final Long VALUE_IS_NOT_ENCODABLE = 0L;
 
+  private static Boolean assertionsEnabled;
+
+  @BeforeClass
+  public static void setUpOnce() {
+    try {
+      assert false;
+      assertionsEnabled = false;
+    } catch (AssertionError e) {
+      assertionsEnabled = true;
+    }
+    ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
+    System.out.println("assertionsEnabled = " + assertionsEnabled);
+  }
+
+  @AfterClass
+  public static void tearDownOnce() {
+    ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(assertionsEnabled);
+  }
+
   private MemoryAllocator ma;
 
   @Before
@@ -208,7 +229,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
   }
 
   @Test
-  public void decodeAddressToBytesShouldReturnActualBytes() {
+  public void decodeUncompressedAddressToBytesShouldReturnActualBytes() {
     long encodedAddress = 549755813697L;
     Integer value = Integer.MAX_VALUE;
 
@@ -219,7 +240,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
   }
 
   @Test
-  public void decodeDataAsAddressShouldDecodeLongIfItsSerializedAndIfItsNotTooBig() {
+  public void decodeUncompressedAddressToBytesShouldDecodeLongIfItsSerializedAndIfItsNotTooBig()
{
     Long value = 0L;
     long encodedAddress = 123L;
 
@@ -229,8 +250,8 @@ public class OffHeapRegionEntryHelperJUnitTest {
     assertThat(actual).isEqualTo(expectedValue);
   }
 
-  @Test(expected = UnsupportedOperationException.class)
-  public void decodeDataAsAddressShouldThrowExceptionIfDataIsCompressedAndItsNotOkToBeCompressed()
{
+  @Test(expected = AssertionError.class)
+  public void decodeUncompressedAddressToBytesWithCompressedAddressShouldThrowException()
{
     long encodedAddress = 549755813703L;
     OffHeapRegionEntryHelper.decodeUncompressedAddressToBytes(encodedAddress);
   }


Mime
View raw message