Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5ED38200B21 for ; Thu, 26 May 2016 18:41:05 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5DA8C160A18; Thu, 26 May 2016 16:41:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 87613160A17 for ; Thu, 26 May 2016 18:41:04 +0200 (CEST) Received: (qmail 17940 invoked by uid 500); 26 May 2016 16:41:03 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 17927 invoked by uid 99); 26 May 2016 16:41:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 May 2016 16:41:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 3943218059A for ; Thu, 26 May 2016 16:41:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.221 X-Spam-Level: X-Spam-Status: No, score=-3.221 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 0hlBvGHkrBXI for ; Thu, 26 May 2016 16:41:01 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 10F235F4EA for ; Thu, 26 May 2016 16:41:00 +0000 (UTC) Received: (qmail 17603 invoked by uid 99); 26 May 2016 16:41:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 May 2016 16:41:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0CB26DFC6F; Thu, 26 May 2016 16:40:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.incubator.apache.org Date: Thu, 26 May 2016 16:40:59 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/3] incubator-geode git commit: GEODE-1296: change conditional in getRawBytes to assert archived-at: Thu, 26 May 2016 16:41:05 -0000 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 Authored: Thu May 12 15:04:16 2016 -0700 Committer: Darrel Schneider 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);