geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [1/3] incubator-geode git commit: GEODE-1296: change conditional in getRawBytes to assert
Date Thu, 26 May 2016 16:40:59 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-1452 ff8348e03 -> 7bf730044


GEODE-1296: change conditional in getRawBytes to assert


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

Branch: refs/heads/feature/GEODE-1452
Commit: 6c626b7ebc134d85160ff2d253ed12762fe49728
Parents: 1d11d94
Author: Ken Howe <khowe@pivotal.io>
Authored: Thu May 12 15:04:16 2016 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Wed May 25 15:03:41 2016 -0700

----------------------------------------------------------------------
 .../internal/offheap/OffHeapStoredObject.java   | 11 +++++-----
 .../offheap/MemoryBlockNodeJUnitTest.java       | 14 +++++++------
 .../offheap/OffHeapStoredObjectJUnitTest.java   | 22 +++++++++++++++++++-
 3 files changed, 35 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c626b7e/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObject.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObject.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObject.java
index c2066b4..47b12b2 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObject.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObject.java
@@ -417,12 +417,13 @@ import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
       MemoryAllocatorImpl.getAllocator().getStats().incReads();
       return result;
     }
+    /**
+     * This method should only be called on uncompressed objects
+     * @return byte array of the StoredObject value. 
+     */
     protected byte[] getRawBytes() {
-      byte[] result = getCompressedBytes();
-      if (isCompressed()) {
-        throw new UnsupportedOperationException();
-      }
-      return result;
+      assert !isCompressed();
+      return getCompressedBytes(); 
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c626b7e/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java
index 7648169..4e7c827 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/MemoryBlockNodeJUnitTest.java
@@ -336,11 +336,12 @@ public class MemoryBlockNodeJUnitTest {
   public void getDataValueCatchesCacheClosedException() {
     Object obj = getValue();
     storedObject = createValueAsSerializedStoredObject(obj);
-    StoredObject spyStoredObject = spy(storedObject);
-    MemoryBlock mb = new MemoryBlockNode(ma, (MemoryBlock) spyStoredObject);
-    when(((OffHeapStoredObject)spyStoredObject).getRawBytes()).thenCallRealMethod().thenThrow(new
CacheClosedException("Unit test forced exception"));
+    OffHeapStoredObject spyStoredObject = spy((OffHeapStoredObject) storedObject);
+    doReturn("java.lang.Long").when(spyStoredObject).getDataType();
+    doThrow(new CacheClosedException("Unit test forced exception")).when(spyStoredObject).getRawBytes();
     ByteArrayOutputStream errContent = new ByteArrayOutputStream();
     System.setErr(new PrintStream(errContent));
+    MemoryBlock mb = new MemoryBlockNode(ma, spyStoredObject);
     softly.assertThat(mb.getDataValue()).isEqualTo("CacheClosedException:Unit test forced
exception");
   }
   
@@ -349,11 +350,12 @@ public class MemoryBlockNodeJUnitTest {
   public void getDataValueCatchesClassNotFoundException() throws Exception {
     Object obj = getValue();
     storedObject = createValueAsSerializedStoredObject(obj);
-    StoredObject spyStoredObject = spy(storedObject);
-    MemoryBlock mb = new MemoryBlockNode(ma, (MemoryBlock) spyStoredObject);
-    when(((OffHeapStoredObject)spyStoredObject).getRawBytes()).thenCallRealMethod().thenThrow(ClassNotFoundException.class);
+    OffHeapStoredObject spyStoredObject = spy((OffHeapStoredObject)storedObject);
+    doReturn("java.lang.Long").when(spyStoredObject).getDataType();
+    doThrow(ClassNotFoundException.class).when(spyStoredObject).getRawBytes();
     ByteArrayOutputStream errContent = new ByteArrayOutputStream();
     System.setErr(new PrintStream(errContent));
+    MemoryBlock mb = new MemoryBlockNode(ma, (MemoryBlock) spyStoredObject);
     softly.assertThat(mb.getDataValue()).isEqualTo("ClassNotFoundException:null");
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c626b7e/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectJUnitTest.java
index 23d72f5..07487a1 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectJUnitTest.java
@@ -24,7 +24,9 @@ import java.io.IOException;
 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;
 
@@ -43,6 +45,24 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
 public class OffHeapStoredObjectJUnitTest extends AbstractStoredObjectTestBase {
 
   private MemoryAllocator ma;
+  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);
+  }
 
   @Before
   public void setUp() {
@@ -803,7 +823,7 @@ public class OffHeapStoredObjectJUnitTest extends AbstractStoredObjectTestBase
{
     assertThat(chunk.getDataValue()).isNull();
   }
 
-  @Test(expected = UnsupportedOperationException.class)
+  @Test(expected = AssertionError.class)
   public void getRawBytesShouldThrowExceptionIfValueIsCompressed() {
     Object regionEntryValue = getValue();
     byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);


Mime
View raw message