You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2016/02/19 02:05:50 UTC

[07/16] incubator-geode git commit: FragmentJUnitTest now works with new code

FragmentJUnitTest now works with new code


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

Branch: refs/heads/feature/GEODE-831
Commit: 58c8fc84d25656cd328d242757c14946ffd51b35
Parents: f86ff84
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Wed Feb 17 17:03:54 2016 -0800
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Wed Feb 17 17:03:54 2016 -0800

----------------------------------------------------------------------
 .../internal/offheap/FragmentJUnitTest.java     | 45 ++------------------
 1 file changed, 4 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/58c8fc84/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FragmentJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FragmentJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FragmentJUnitTest.java
index ccc6b67..a10564f 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FragmentJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/FragmentJUnitTest.java
@@ -33,19 +33,14 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.ExpectedException;
 
-import com.gemstone.gemfire.LogWriter;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
 public class FragmentJUnitTest {
 
-  private SimpleMemoryAllocatorImpl ma;
   private OutOfOffHeapMemoryListener ooohml;
   private OffHeapMemoryStats stats;
-  private LogWriter lw;
-  private UnsafeMemoryChunk.Factory umcFactory;
   private UnsafeMemoryChunk[] slabs;
-  private int numSlabs;
 
   static {
     ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
@@ -70,16 +65,11 @@ public class FragmentJUnitTest {
   public void setUp() throws Exception {
     ooohml = mock(OutOfOffHeapMemoryListener.class);
     stats = mock(OffHeapMemoryStats.class);
-    lw = mock(LogWriter.class);
     
-    numSlabs = 2;
-    umcFactory = new UnsafeMemoryChunk.Factory(){
-      @Override
-      public UnsafeMemoryChunk create(int size) {
-        return new UnsafeMemoryChunk(size);
-      }
-    };
-    slabs = allocateMemorySlabs();
+    UnsafeMemoryChunk slab1 = new UnsafeMemoryChunk((int)OffHeapStorage.MIN_SLAB_SIZE);
+    UnsafeMemoryChunk slab2 = new UnsafeMemoryChunk((int)OffHeapStorage.MIN_SLAB_SIZE);
+    slabs = new UnsafeMemoryChunk[]{slab1, slab2};
+    SimpleMemoryAllocatorImpl.createForUnitTest(ooohml, stats, slabs);
   }
 
   @After
@@ -87,11 +77,6 @@ public class FragmentJUnitTest {
     SimpleMemoryAllocatorImpl.freeOffHeapMemory();
   }
   
-  private UnsafeMemoryChunk[] allocateMemorySlabs() {
-    ma = SimpleMemoryAllocatorImpl.create(ooohml, stats, lw, numSlabs, OffHeapStorage.MIN_SLAB_SIZE * numSlabs, OffHeapStorage.MIN_SLAB_SIZE, umcFactory);
-    return ma.getSlabs();
-  }
-
   
   @Test
   public void fragmentConstructorThrowsExceptionForNon8ByteAlignedAddress() {
@@ -147,7 +132,6 @@ public class FragmentJUnitTest {
   
   @Test
   public void getStateIsAlwaysStateUNUSED() {
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     softly.assertThat(fragment.getState()).isEqualTo(MemoryBlock.State.UNUSED);
     fragment.allocate(fragment.getFreeIndex(), fragment.getFreeIndex() + 256);
@@ -156,7 +140,6 @@ public class FragmentJUnitTest {
 
   @Test
   public void getFreeListIdIsAlwaysMinus1() {
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     softly.assertThat(fragment.getFreeListId()).isEqualTo(-1);
     fragment.allocate(fragment.getFreeIndex(), fragment.getFreeIndex() + 256);
@@ -165,7 +148,6 @@ public class FragmentJUnitTest {
 
   @Test
   public void getRefCountIsAlwaysZero() {
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     softly.assertThat(fragment.getRefCount()).isEqualTo(0);
     fragment.allocate(fragment.getFreeIndex(), fragment.getFreeIndex() + 256);
@@ -174,7 +156,6 @@ public class FragmentJUnitTest {
 
   @Test
   public void getDataTypeIsAlwaysNA() {
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     softly.assertThat(fragment.getDataType()).isEqualTo("N/A");
     fragment.allocate(fragment.getFreeIndex(), fragment.getFreeIndex() + 256);
@@ -183,7 +164,6 @@ public class FragmentJUnitTest {
 
   @Test
   public void isSerializedIsAlwaysFalse() {
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     softly.assertThat(fragment.isSerialized()).isEqualTo(false);
     fragment.allocate(fragment.getFreeIndex(), fragment.getFreeIndex() + 256);
@@ -192,7 +172,6 @@ public class FragmentJUnitTest {
 
   @Test
   public void isCompressedIsAlwaysFalse() {
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     softly.assertThat(fragment.isCompressed()).isEqualTo(false);
     fragment.allocate(fragment.getFreeIndex(), fragment.getFreeIndex() + 256);
@@ -201,7 +180,6 @@ public class FragmentJUnitTest {
 
   @Test
   public void getDataValueIsAlwaysNull() {
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     softly.assertThat(fragment.getDataValue()).isNull();
     fragment.allocate(fragment.getFreeIndex(), fragment.getFreeIndex() + 256);
@@ -209,17 +187,7 @@ public class FragmentJUnitTest {
   }
 
   @Test
-  public void getChunkTypeIsAlwaysNull() {
-    slabs = allocateMemorySlabs();
-    Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
-    softly.assertThat(fragment.getChunkType()).isNull();
-    fragment.allocate(fragment.getFreeIndex(), fragment.getFreeIndex() + 256);
-    softly.assertThat(fragment.getChunkType()).isNull();
-  }
-
-  @Test
   public void fragmentEqualsComparesMemoryBlockAddresses() {
-    slabs = allocateMemorySlabs();
     Fragment fragment0 = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     Fragment sameFragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     Fragment fragment1 = new Fragment(slabs[1].getMemoryAddress(), slabs[1].getSize());
@@ -229,14 +197,12 @@ public class FragmentJUnitTest {
 
   @Test
   public void fragmentEqualsIsFalseForNonFragmentObjects() {
-    slabs = allocateMemorySlabs();
     Fragment fragment0 = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     assertThat(fragment0.equals(slabs[0]), is(false));
   }
 
   @Test
   public void fragmentHashCodeIsHashCodeOfItsMemoryAddress() {
-    slabs = allocateMemorySlabs();
     Fragment fragment0 = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     Fragment fragment1 = new Fragment(slabs[1].getMemoryAddress(), slabs[1].getSize());
     Long fragmentAddress = fragment0.getMemoryAddress();
@@ -246,7 +212,6 @@ public class FragmentJUnitTest {
 
   @Test
   public void fragmentFillSetsAllBytesToTheSameConstantValue() {
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     Long fragmentAddress = fragment.getMemoryAddress();
     byte[] bytes = new byte[(int)OffHeapStorage.MIN_SLAB_SIZE];
@@ -261,7 +226,6 @@ public class FragmentJUnitTest {
   public void getNextBlockThrowsExceptionForFragment() {
     expectedException.expect(UnsupportedOperationException.class);
 
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     fragment.getNextBlock();
     fail("getNextBlock failed to throw UnsupportedOperationException");
@@ -271,7 +235,6 @@ public class FragmentJUnitTest {
   public void getSlabIdThrowsExceptionForFragment() {
     expectedException.expect(UnsupportedOperationException.class);
 
-    slabs = allocateMemorySlabs();
     Fragment fragment = new Fragment(slabs[0].getMemoryAddress(), slabs[0].getSize());
     fragment.getSlabId();
     fail("getSlabId failed to throw UnsupportedOperationException");