geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [05/45] incubator-geode git commit: GEODE-982: refactor off-heap
Date Tue, 15 Mar 2016 18:38:43 GMT
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3087c86f/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
deleted file mode 100644
index 9271b53..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkJUnitTest.java
+++ /dev/null
@@ -1,902 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.gemstone.gemfire.internal.offheap;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.LogWriter;
-import com.gemstone.gemfire.compression.Compressor;
-import com.gemstone.gemfire.internal.DSCODE;
-import com.gemstone.gemfire.internal.HeapDataOutputStream;
-import com.gemstone.gemfire.internal.Version;
-import com.gemstone.gemfire.internal.cache.BytesAndBitsForCompactor;
-import com.gemstone.gemfire.internal.cache.CachePerfStats;
-import com.gemstone.gemfire.internal.cache.EntryEventImpl;
-import com.gemstone.gemfire.internal.cache.RegionEntryContext;
-import com.gemstone.gemfire.internal.offheap.MemoryBlock.State;
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
-
-@Category(UnitTest.class)
-public class ObjectChunkJUnitTest extends AbstractStoredObjectTestBase {
-
-  private MemoryAllocator ma;
-
-  static {
-    ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
-  }
-
-  @Before
-  public void setUp() {
-    OutOfOffHeapMemoryListener ooohml = mock(OutOfOffHeapMemoryListener.class);
-    OffHeapMemoryStats stats = mock(OffHeapMemoryStats.class);
-    LogWriter lw = mock(LogWriter.class);
-
-    ma = SimpleMemoryAllocatorImpl.create(ooohml, stats, lw, 3, OffHeapStorage.MIN_SLAB_SIZE * 3, OffHeapStorage.MIN_SLAB_SIZE);
-  }
-
-  @After
-  public void tearDown() {
-    SimpleMemoryAllocatorImpl.freeOffHeapMemory();
-  }
-
-  @Override
-  public Object getValue() {
-    return Long.valueOf(Long.MAX_VALUE);
-  }
-
-  @Override
-  public byte[] getValueAsByteArray() {
-    return convertValueToByteArray(getValue());
-  }
-
-  private byte[] convertValueToByteArray(Object value) {
-    return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong((Long) value).array();
-  }
-
-  @Override
-  public Object convertByteArrayToObject(byte[] valueInByteArray) {
-    return ByteBuffer.wrap(valueInByteArray).getLong();
-  }
-
-  @Override
-  public Object convertSerializedByteArrayToObject(byte[] valueInSerializedByteArray) {
-    return EntryEventImpl.deserialize(valueInSerializedByteArray);
-  }
-
-  @Override
-  public ObjectChunk createValueAsUnserializedStoredObject(Object value) {
-    byte[] valueInByteArray;
-    if (value instanceof Long) {
-      valueInByteArray = convertValueToByteArray(value);
-    } else {
-      valueInByteArray = (byte[]) value;
-    }
-
-    boolean isSerialized = false;
-    boolean isCompressed = false;
-
-    return createChunk(valueInByteArray, isSerialized, isCompressed);
-  }
-
-  @Override
-  public ObjectChunk createValueAsSerializedStoredObject(Object value) {
-    byte[] valueInSerializedByteArray = EntryEventImpl.serialize(value);
-
-    boolean isSerialized = true;
-    boolean isCompressed = false;
-
-    return createChunk(valueInSerializedByteArray, isSerialized, isCompressed);
-  }
-
-  private ObjectChunk createChunk(byte[] v, boolean isSerialized, boolean isCompressed) {
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(v, isSerialized, isCompressed);
-    return chunk;
-  }
-
-  @Test
-  public void chunkCanBeCreatedFromAnotherChunk() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-
-    ObjectChunk newChunk = new ObjectChunk(chunk);
-
-    assertNotNull(newChunk);
-    assertThat(newChunk.getMemoryAddress()).isEqualTo(chunk.getMemoryAddress());
-
-    chunk.release();
-  }
-
-  @Test
-  public void chunkCanBeCreatedWithOnlyMemoryAddress() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-
-    ObjectChunk newChunk = new ObjectChunk(chunk.getMemoryAddress());
-
-    assertNotNull(newChunk);
-    assertThat(newChunk.getMemoryAddress()).isEqualTo(chunk.getMemoryAddress());
-
-    chunk.release();
-  }
-
-  @Test
-  public void chunkSliceCanBeCreatedFromAnotherChunk() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-
-    int position = 1;
-    int end = 2;
-
-    ObjectChunk newChunk = (ObjectChunk) chunk.slice(position, end);
-
-    assertNotNull(newChunk);
-    assertThat(newChunk.getClass()).isEqualTo(ObjectChunkSlice.class);
-    assertThat(newChunk.getMemoryAddress()).isEqualTo(chunk.getMemoryAddress());
-
-    chunk.release();
-  }
-
-  @Test
-  public void fillSerializedValueShouldFillWrapperWithSerializedValueIfValueIsSerialized() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    // mock the things
-    BytesAndBitsForCompactor wrapper = mock(BytesAndBitsForCompactor.class);
-
-    byte userBits = 0;
-    byte serializedUserBits = 1;
-    chunk.fillSerializedValue(wrapper, userBits);
-
-    verify(wrapper, times(1)).setChunkData(chunk, serializedUserBits);
-
-    chunk.release();
-  }
-
-  @Test
-  public void fillSerializedValueShouldFillWrapperWithDeserializedValueIfValueIsNotSerialized() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-
-    // mock the things
-    BytesAndBitsForCompactor wrapper = mock(BytesAndBitsForCompactor.class);
-
-    byte userBits = 1;
-    chunk.fillSerializedValue(wrapper, userBits);
-
-    verify(wrapper, times(1)).setChunkData(chunk, userBits);
-
-    chunk.release();
-  }
-
-  @Test
-  public void getShortClassNameShouldReturnShortClassName() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    assertThat(chunk.getShortClassName()).isEqualTo("ObjectChunk");
-
-    chunk.release();
-  }
-
-  @Test
-  public void chunksAreEqualsOnlyByAddress() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    ObjectChunk newChunk = new ObjectChunk(chunk.getMemoryAddress());
-    assertThat(chunk.equals(newChunk)).isTrue();
-
-    ObjectChunk chunkWithSameValue = createValueAsUnserializedStoredObject(getValue());
-    assertThat(chunk.equals(chunkWithSameValue)).isFalse();
-
-    Object someObject = getValue();
-    assertThat(chunk.equals(someObject)).isFalse();
-
-    chunk.release();
-    chunkWithSameValue.release();
-  }
-
-  @Test
-  public void chunksShouldBeComparedBySize() {
-    ObjectChunk chunk1 = createValueAsSerializedStoredObject(getValue());
-
-    ObjectChunk chunk2 = chunk1;
-    assertThat(chunk1.compareTo(chunk2)).isEqualTo(0);
-
-    ObjectChunk chunkWithSameValue = createValueAsSerializedStoredObject(getValue());
-    assertThat(chunk1.compareTo(chunkWithSameValue)).isEqualTo(Long.signum(chunk1.getMemoryAddress() - chunkWithSameValue.getMemoryAddress()));
-
-    ObjectChunk chunk3 = createValueAsSerializedStoredObject(Long.MAX_VALUE);
-    ObjectChunk chunk4 = createValueAsSerializedStoredObject(Long.MAX_VALUE);
-
-    int newSizeForChunk3 = 2;
-    int newSizeForChunk4 = 3;
-
-    assertThat(chunk3.compareTo(chunk4)).isEqualTo(Integer.signum(newSizeForChunk3 - newSizeForChunk4));
-
-    chunk1.release();
-    chunk4.release();
-  }
-
-  @Test
-  public void setSerializedShouldSetTheSerializedBit() {
-    Object regionEntryValue = getValue();
-    byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
-
-    boolean isSerialized = false;
-    boolean isCompressed = false;
-
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(regionEntryValueAsBytes, isSerialized, isCompressed);
-
-    int headerBeforeSerializedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress() + ObjectChunk.REF_COUNT_OFFSET);
-
-    assertThat(chunk.isSerialized()).isFalse();
-
-    chunk.setSerialized(true); // set to true
-
-    assertThat(chunk.isSerialized()).isTrue();
-
-    int headerAfterSerializedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress() + ObjectChunk.REF_COUNT_OFFSET);
-
-    assertThat(headerAfterSerializedBitSet).isEqualTo(headerBeforeSerializedBitSet | ObjectChunk.IS_SERIALIZED_BIT);
-
-    chunk.release();
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void setSerialziedShouldThrowExceptionIfChunkIsAlreadyReleased() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.release();
-    chunk.setSerialized(true);
-
-    chunk.release();
-  }
-
-  @Test
-  public void setCompressedShouldSetTheCompressedBit() {
-    Object regionEntryValue = getValue();
-    byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
-
-    boolean isSerialized = false;
-    boolean isCompressed = false;
-
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(regionEntryValueAsBytes, isSerialized, isCompressed);
-
-    int headerBeforeCompressedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress() + ObjectChunk.REF_COUNT_OFFSET);
-
-    assertThat(chunk.isCompressed()).isFalse();
-
-    chunk.setCompressed(true); // set to true
-
-    assertThat(chunk.isCompressed()).isTrue();
-
-    int headerAfterCompressedBitSet = UnsafeMemoryChunk.readAbsoluteIntVolatile(chunk.getMemoryAddress() + ObjectChunk.REF_COUNT_OFFSET);
-
-    assertThat(headerAfterCompressedBitSet).isEqualTo(headerBeforeCompressedBitSet | ObjectChunk.IS_COMPRESSED_BIT);
-
-    chunk.release();
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void setCompressedShouldThrowExceptionIfChunkIsAlreadyReleased() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.release();
-    chunk.setCompressed(true);
-
-    chunk.release();
-  }
-
-  @Test
-  public void setDataSizeShouldSetTheDataSizeBits() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-
-    int beforeSize = chunk.getDataSize();
-
-    chunk.setDataSize(2);
-
-    int afterSize = chunk.getDataSize();
-
-    assertThat(afterSize).isEqualTo(2);
-    assertThat(afterSize).isNotEqualTo(beforeSize);
-
-    chunk.release();
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void setDataSizeShouldThrowExceptionIfChunkIsAlreadyReleased() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.release();
-    chunk.setDataSize(1);
-
-    chunk.release();
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void initializeUseCountShouldThrowIllegalStateExceptionIfChunkIsAlreadyRetained() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.retain();
-    chunk.initializeUseCount();
-
-    chunk.release();
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void initializeUseCountShouldThrowIllegalStateExceptionIfChunkIsAlreadyReleased() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.release();
-    chunk.initializeUseCount();
-
-    chunk.release();
-  }
-
-  @Test
-  public void isSerializedPdxInstanceShouldReturnTrueIfItsPDXInstance() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    byte[] serailizedValue = chunk.getSerializedValue();
-    serailizedValue[0] = DSCODE.PDX;
-    chunk.setSerializedValue(serailizedValue);
-
-    assertThat(chunk.isSerializedPdxInstance()).isTrue();
-
-    serailizedValue = chunk.getSerializedValue();
-    serailizedValue[0] = DSCODE.PDX_ENUM;
-    chunk.setSerializedValue(serailizedValue);
-
-    assertThat(chunk.isSerializedPdxInstance()).isTrue();
-
-    serailizedValue = chunk.getSerializedValue();
-    serailizedValue[0] = DSCODE.PDX_INLINE_ENUM;
-    chunk.setSerializedValue(serailizedValue);
-
-    assertThat(chunk.isSerializedPdxInstance()).isTrue();
-
-    chunk.release();
-  }
-
-  @Test
-  public void isSerializedPdxInstanceShouldReturnFalseIfItsNotPDXInstance() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    assertThat(chunk.isSerializedPdxInstance()).isFalse();
-
-    chunk.release();
-  }
-
-  @Test
-  public void checkDataEqualsByChunk() {
-    ObjectChunk chunk1 = createValueAsSerializedStoredObject(getValue());
-    ObjectChunk sameAsChunk1 = chunk1;
-
-    assertThat(chunk1.checkDataEquals(sameAsChunk1)).isTrue();
-
-    ObjectChunk unserializedChunk = createValueAsUnserializedStoredObject(getValue());
-    assertThat(chunk1.checkDataEquals(unserializedChunk)).isFalse();
-
-    ObjectChunk chunkDifferBySize = createValueAsSerializedStoredObject(getValue());
-    chunkDifferBySize.setSize(0);
-    assertThat(chunk1.checkDataEquals(chunkDifferBySize)).isFalse();
-
-    ObjectChunk chunkDifferByValue = createValueAsSerializedStoredObject(Long.MAX_VALUE - 1);
-    assertThat(chunk1.checkDataEquals(chunkDifferByValue)).isFalse();
-
-    ObjectChunk newChunk1 = createValueAsSerializedStoredObject(getValue());
-    assertThat(chunk1.checkDataEquals(newChunk1)).isTrue();
-
-    chunk1.release();
-    unserializedChunk.release();
-    chunkDifferBySize.release();
-    chunkDifferByValue.release();
-    newChunk1.release();
-  }
-
-  @Test
-  public void checkDataEqualsBySerializedValue() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    assertThat(chunk.checkDataEquals(new byte[1])).isFalse();
-
-    ObjectChunk chunkDifferByValue = createValueAsSerializedStoredObject(Long.MAX_VALUE - 1);
-    assertThat(chunk.checkDataEquals(chunkDifferByValue.getSerializedValue())).isFalse();
-
-    ObjectChunk newChunk = createValueAsSerializedStoredObject(getValue());
-    assertThat(chunk.checkDataEquals(newChunk.getSerializedValue())).isTrue();
-
-    chunk.release();
-    chunkDifferByValue.release();
-    newChunk.release();
-  }
-
-  @Test
-  public void getDecompressedBytesShouldReturnDecompressedBytesIfCompressed() {
-    Object regionEntryValue = getValue();
-    byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
-
-    boolean isSerialized = true;
-    boolean isCompressed = true;
-
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(regionEntryValueAsBytes, isSerialized, isCompressed);
-
-    RegionEntryContext regionContext = mock(RegionEntryContext.class);
-    CachePerfStats cacheStats = mock(CachePerfStats.class);
-    Compressor compressor = mock(Compressor.class);
-
-    long startTime = 10000L;
-
-    // mock required things
-    when(regionContext.getCompressor()).thenReturn(compressor);
-    when(compressor.decompress(regionEntryValueAsBytes)).thenReturn(regionEntryValueAsBytes);
-    when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
-    when(cacheStats.startDecompression()).thenReturn(startTime);
-
-    // invoke the thing
-    byte[] bytes = chunk.getDecompressedBytes(regionContext);
-
-    // verify the thing happened
-    verify(cacheStats, atLeastOnce()).startDecompression();
-    verify(compressor, times(1)).decompress(regionEntryValueAsBytes);
-    verify(cacheStats, atLeastOnce()).endDecompression(startTime);
-
-    assertArrayEquals(regionEntryValueAsBytes, bytes);
-
-    chunk.release();
-  }
-
-  @Test
-  public void incSizeShouldIncrementSize() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    int beforeSize = chunk.getSize();
-
-    chunk.incSize(1);
-    assertThat(chunk.getSize()).isEqualTo(beforeSize + 1);
-
-    chunk.incSize(2);
-    assertThat(chunk.getSize()).isEqualTo(beforeSize + 1 + 2);
-
-    chunk.release();
-  }
-
-  @Test
-  public void readyForFreeShouldResetTheRefCount() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    int refCountBeforeFreeing = chunk.getRefCount();
-    assertThat(refCountBeforeFreeing).isEqualTo(1);
-
-    chunk.readyForFree();
-
-    int refCountAfterFreeing = chunk.getRefCount();
-    assertThat(refCountAfterFreeing).isEqualTo(0);
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void readyForAllocationShouldThrowExceptionIfAlreadyAllocated() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    // chunk is already allocated when we created it, so calling readyForAllocation should throw exception.
-    chunk.readyForAllocation();
-
-    chunk.release();
-  }
-
-  @Test
-  public void checkIsAllocatedShouldReturnIfAllocated() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    chunk.checkIsAllocated();
-
-    chunk.release();
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void checkIsAllocatedShouldThrowExceptionIfNotAllocated() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    chunk.release();
-    chunk.checkIsAllocated();
-
-    chunk.release();
-  }
-
-  @Test
-  public void sendToShouldWriteSerializedValueToDataOutputIfValueIsSerialized() throws IOException {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    ObjectChunk spyChunk = spy(chunk);
-
-    HeapDataOutputStream dataOutput = mock(HeapDataOutputStream.class);
-    ByteBuffer directByteBuffer = ByteBuffer.allocate(1024);
-
-    doReturn(directByteBuffer).when(spyChunk).createDirectByteBuffer();
-    doNothing().when(dataOutput).write(directByteBuffer);
-
-    spyChunk.sendTo(dataOutput);
-
-    verify(dataOutput, times(1)).write(directByteBuffer);
-
-    chunk.release();
-  }
-
-  @Test
-  public void sendToShouldWriteUnserializedValueToDataOutputIfValueIsUnserialized() throws IOException {
-    byte[] regionEntryValue = getValueAsByteArray();
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(regionEntryValue);
-
-    // writeByte is a final method and cannot be mocked, so creating a real one
-    HeapDataOutputStream dataOutput = new HeapDataOutputStream(Version.CURRENT);
-
-    chunk.sendTo(dataOutput);
-
-    byte[] actual = dataOutput.toByteArray();
-
-    byte[] expected = new byte[regionEntryValue.length + 2];
-    expected[0] = DSCODE.BYTE_ARRAY;
-    expected[1] = (byte) regionEntryValue.length;
-    System.arraycopy(regionEntryValue, 0, expected, 2, regionEntryValue.length);
-
-    assertNotNull(dataOutput);
-    assertThat(actual).isEqualTo(expected);
-
-    chunk.release();
-  }
-
-  @Test
-  public void sendAsByteArrayShouldWriteValueToDataOutput() throws IOException {
-    byte[] regionEntryValue = getValueAsByteArray();
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(regionEntryValue);
-
-    // writeByte is a final method and cannot be mocked, so creating a real one
-    HeapDataOutputStream dataOutput = new HeapDataOutputStream(Version.CURRENT);
-
-    chunk.sendAsByteArray(dataOutput);
-
-    byte[] actual = dataOutput.toByteArray();
-
-    byte[] expected = new byte[regionEntryValue.length + 1];
-    expected[0] = (byte) regionEntryValue.length;
-    System.arraycopy(regionEntryValue, 0, expected, 1, regionEntryValue.length);
-
-    assertNotNull(dataOutput);
-    assertThat(actual).isEqualTo(expected);
-
-    chunk.release();
-  }
-
-  @Test
-  public void createDirectByteBufferShouldCreateAByteBuffer() {
-    byte[] regionEntryValue = getValueAsByteArray();
-
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(regionEntryValue);
-
-    ByteBuffer buffer = chunk.createDirectByteBuffer();
-
-    byte[] actual = new byte[regionEntryValue.length];
-    buffer.get(actual);
-
-    assertArrayEquals(regionEntryValue, actual);
-
-    chunk.release();
-  }
-
-  @Test
-  public void getDirectByteBufferShouldCreateAByteBuffer() {
-    byte[] regionEntryValue = getValueAsByteArray();
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(regionEntryValue);
-
-    ByteBuffer buffer = chunk.createDirectByteBuffer();
-    long bufferAddress = ObjectChunk.getDirectByteBufferAddress(buffer);
-
-    // returned address should be starting of the value (after skipping HEADER_SIZE bytes)
-    assertEquals(chunk.getMemoryAddress() + ObjectChunk.OFF_HEAP_HEADER_SIZE, bufferAddress);
-
-    chunk.release();
-  }
-
-  @Test(expected = AssertionError.class)
-  public void getAddressForReadingShouldFailIfItsOutsideOfChunk() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    chunk.getAddressForReading(0, chunk.getDataSize() + 1);
-
-    chunk.release();
-  }
-
-  @Test
-  public void getAddressForReadingShouldReturnDataAddressFromGivenOffset() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    int offset = 1;
-    long requestedAddress = chunk.getAddressForReading(offset, 1);
-
-    assertThat(requestedAddress).isEqualTo(chunk.getBaseDataAddress() + offset);
-
-    chunk.release();
-  }
-
-  @Test
-  public void getSizeInBytesShouldReturnSize() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    assertThat(chunk.getSizeInBytes()).isEqualTo(chunk.getSize());
-
-    chunk.release();
-  }
-
-  @Test(expected = AssertionError.class)
-  public void getUnsafeAddressShouldFailIfOffsetIsNegative() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    chunk.getUnsafeAddress(-1, 1);
-
-    chunk.release();
-  }
-
-  @Test(expected = AssertionError.class)
-  public void getUnsafeAddressShouldFailIfSizeIsNegative() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    chunk.getUnsafeAddress(1, -1);
-
-    chunk.release();
-  }
-
-  @Test(expected = AssertionError.class)
-  public void getUnsafeAddressShouldFailIfItsOutsideOfChunk() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-    chunk.getUnsafeAddress(0, chunk.getDataSize() + 1);
-
-    chunk.release();
-  }
-
-  @Test
-  public void getUnsafeAddressShouldReturnUnsafeAddress() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    int offset = 1;
-    long unsafeAddress = chunk.getUnsafeAddress(offset, 1);
-
-    assertThat(unsafeAddress).isEqualTo(chunk.getBaseDataAddress() + offset);
-
-    chunk.release();
-  }
-
-  @Test(expected = AssertionError.class)
-  public void readByteAndWriteByteShouldFailIfOffsetIsOutside() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    chunk.readByte(chunk.getDataSize() + 1);
-
-    chunk.writeByte(chunk.getDataSize() + 1, Byte.MAX_VALUE);
-
-    chunk.release();
-  }
-
-  @Test
-  public void writeByteShouldWriteAtCorrectLocation() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    byte valueBeforeWrite = chunk.readByte(2);
-
-    Byte expected = Byte.MAX_VALUE;
-    chunk.writeByte(2, expected);
-
-    Byte actual = chunk.readByte(2);
-
-    assertThat(actual).isNotEqualTo(valueBeforeWrite);
-    assertThat(actual).isEqualTo(expected);
-
-    chunk.release();
-  }
-
-  @Test
-  public void retainShouldIncrementRefCount() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    assertThat(chunk.getRefCount()).isEqualTo(1);
-
-    chunk.retain();
-    assertThat(chunk.getRefCount()).isEqualTo(2);
-
-    chunk.retain();
-    assertThat(chunk.getRefCount()).isEqualTo(3);
-
-    chunk.release();
-    chunk.release();
-    chunk.release();
-    boolean retainAfterRelease = chunk.retain();
-
-    assertThat(retainAfterRelease).isFalse();
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void retainShouldThrowExceptionAfterMaxNumberOfTimesRetained() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-
-    // loop though and invoke retain for MAX_REF_COUNT-1 times, as create chunk above counted as one reference
-    for (int i = 0; i < ObjectChunk.MAX_REF_COUNT - 1; i++)
-      chunk.retain();
-
-    // invoke for the one more time should throw exception
-    chunk.retain();
-  }
-
-  @Test
-  public void releaseShouldDecrementRefCount() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    assertThat(chunk.getRefCount()).isEqualTo(1);
-
-    chunk.retain();
-    chunk.retain();
-    assertThat(chunk.getRefCount()).isEqualTo(3);
-
-    chunk.release();
-    assertThat(chunk.getRefCount()).isEqualTo(2);
-
-    chunk.release();
-    assertThat(chunk.getRefCount()).isEqualTo(1);
-
-    chunk.retain();
-    chunk.release();
-    assertThat(chunk.getRefCount()).isEqualTo(1);
-
-    chunk.release();
-    assertThat(chunk.getRefCount()).isEqualTo(0);
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void releaseShouldThrowExceptionIfChunkIsAlreadyReleased() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.release();
-    chunk.release();
-  }
-
-  @Test
-  public void testToStringForOffHeapByteSource() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-
-    String expected = ":<dataSize=" + chunk.getDataSize() + " refCount=" + chunk.getRefCount() + " addr=" + Long.toHexString(chunk.getMemoryAddress()) + ">";
-    assertThat(chunk.toStringForOffHeapByteSource()).endsWith(expected);
-
-    // test toString
-    ObjectChunk spy = spy(chunk);
-    spy.toString();
-    verify(spy, times(1)).toStringForOffHeapByteSource();
-
-    chunk.release();
-  }
-
-  @Test
-  public void getStateShouldReturnAllocatedIfRefCountIsGreaterThanZero() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    assertEquals(State.ALLOCATED, chunk.getState());
-
-    chunk.release();
-  }
-
-  @Test
-  public void getStateShouldReturnDeallocatedIfRefCountIsZero() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.release();
-    assertEquals(State.DEALLOCATED, chunk.getState());
-  }
-
-  @Test(expected = UnsupportedOperationException.class)
-  public void getNextBlockShouldThrowUnSupportedOperationException() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.getNextBlock();
-
-    chunk.release();
-  }
-
-  @Test
-  public void getBlockSizeShouldBeSameSameGetSize() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    assertEquals(chunk.getSize(), chunk.getBlockSize());
-
-    chunk.release();
-  }
-
-  @Test(expected = UnsupportedOperationException.class)
-  public void copyBytesShouldThrowUnSupportedOperationException() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.copyBytes(1, 2, 1);
-
-    chunk.release();
-  }
-
-  @Test(expected = UnsupportedOperationException.class)
-  public void getSlabIdShouldThrowUnSupportedOperationException() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    chunk.getSlabId();
-
-    chunk.release();
-  }
-
-  @Test
-  public void getFreeListIdShouldReturnMinusOne() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    assertThat(chunk.getFreeListId()).isEqualTo(-1);
-
-    chunk.release();
-  }
-
-  @Test
-  public void getDataTypeShouldReturnNull() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    assertThat(chunk.getDataType()).isNull();
-
-    chunk.release();
-  }
-
-  @Test
-  public void getDataDataShouldReturnNull() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    assertThat(chunk.getDataValue()).isNull();
-  }
-
-  @Test(expected = UnsupportedOperationException.class)
-  public void getRawBytesShouldThrowExceptionIfValueIsCompressed() {
-    Object regionEntryValue = getValue();
-    byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
-
-    boolean isSerialized = true;
-    boolean isCompressed = true;
-
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(regionEntryValueAsBytes, isSerialized, isCompressed);
-
-    chunk.getRawBytes();
-
-    chunk.release();
-  }
-
-  @Test
-  public void getSerializedValueShouldSerializeTheValue() {
-    Object regionEntryValue = getValue();
-    byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
-
-    boolean isSerialized = false;
-    boolean isCompressed = false;
-
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(regionEntryValueAsBytes, isSerialized, isCompressed);
-
-    byte[] serializedValue = chunk.getSerializedValue();
-
-    assertThat(serializedValue).isEqualTo(EntryEventImpl.serialize(regionEntryValueAsBytes));
-
-    chunk.release();
-  }
-
-  @Test
-  public void fillShouldFillTheChunk() {
-    boolean isSerialized = false;
-    boolean isCompressed = false;
-
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(new byte[100], isSerialized, isCompressed);
-
-    // first fill the unused part with FILL_PATTERN
-    ObjectChunk.fill(chunk.getMemoryAddress());
-
-    // Validate that it is filled
-    chunk.validateFill();
-
-    chunk.release();
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3087c86f/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkSliceJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkSliceJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkSliceJUnitTest.java
deleted file mode 100644
index fe55910..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkSliceJUnitTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.gemstone.gemfire.internal.offheap;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
-
-@Category(UnitTest.class)
-public class ObjectChunkSliceJUnitTest extends ObjectChunkJUnitTest {
-
-  @Test
-  public void sliceShouldHaveAValidDataSize() {
-    int position = 1;
-    int end = 2;
-
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    ObjectChunkSlice slice = (ObjectChunkSlice) chunk.slice(position, end);
-
-    assertNotNull(slice);
-    assertEquals(ObjectChunkSlice.class, slice.getClass());
-
-    assertEquals(end - position, slice.getDataSize());
-  }
-
-  @Test
-  public void sliceShouldHaveAValidBaseDataAddress() {
-    int position = 1;
-    int end = 2;
-
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    ObjectChunkSlice slice = (ObjectChunkSlice) chunk.slice(position, end);
-
-    assertNotNull(slice);
-    assertEquals(ObjectChunkSlice.class, slice.getClass());
-
-    assertEquals(chunk.getBaseDataAddress() + position, slice.getBaseDataAddress());
-  }
-
-  @Test
-  public void sliceShouldHaveAValidBaseOffset() {
-    int position = 1;
-    int end = 2;
-
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-    ObjectChunkSlice slice = (ObjectChunkSlice) chunk.slice(position, end);
-
-    assertNotNull(slice);
-    assertEquals(ObjectChunkSlice.class, slice.getClass());
-
-    assertEquals(chunk.getBaseDataOffset() + position, slice.getBaseDataOffset());
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3087c86f/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkWithHeapFormJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkWithHeapFormJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkWithHeapFormJUnitTest.java
deleted file mode 100644
index 4486845..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/ObjectChunkWithHeapFormJUnitTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.gemstone.gemfire.internal.offheap;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
-
-@Category(UnitTest.class)
-public class ObjectChunkWithHeapFormJUnitTest extends ObjectChunkJUnitTest {
-
-  @Test
-  public void getRawBytesShouldReturnCachedHeapForm() {
-    ObjectChunk chunk = createValueAsUnserializedStoredObject(getValue());
-
-    byte[] valueInBytes = getValueAsByteArray();
-    ObjectChunkWithHeapForm heapForm = new ObjectChunkWithHeapForm(chunk, valueInBytes);
-
-    assertNotNull(heapForm);
-
-    assertSame(valueInBytes, heapForm.getRawBytes());
-  }
-
-  @Test
-  public void getChunkWithoutHeapFormShouldReturnGemFireChunk() {
-    ObjectChunk chunk = createValueAsSerializedStoredObject(getValue());
-
-    byte[] valueInBytes = getValueAsByteArray();
-    ObjectChunkWithHeapForm heapForm = new ObjectChunkWithHeapForm(chunk, valueInBytes);
-
-    ObjectChunk chunkWithOutHeapForm = heapForm.getChunkWithoutHeapForm();
-
-    assertNotNull(chunkWithOutHeapForm);
-    assertEquals(ObjectChunk.class, chunkWithOutHeapForm.getClass());
-
-    assertEquals(chunk, heapForm.getChunkWithoutHeapForm());
-
-    assertEquals(chunk.getMemoryAddress(), chunkWithOutHeapForm.getMemoryAddress());
-    assertArrayEquals(chunk.getRawBytes(), chunkWithOutHeapForm.getRawBytes());
-    assertNotSame(valueInBytes, chunkWithOutHeapForm.getRawBytes());
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3087c86f/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapHelperJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapHelperJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapHelperJUnitTest.java
index b1e3af0..989abfc 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapHelperJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapHelperJUnitTest.java
@@ -38,7 +38,7 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
 @Category(UnitTest.class)
 public class OffHeapHelperJUnitTest extends AbstractStoredObjectTestBase {
 
-  private MemoryChunkWithRefCount storedObject                 = null;
+  private StoredObject storedObject                 = null;
   private Object                  deserializedRegionEntryValue = null;
   private byte[]                  serializedRegionEntryValue   = null;
   private MemoryAllocator         ma;
@@ -102,7 +102,7 @@ public class OffHeapHelperJUnitTest extends AbstractStoredObjectTestBase {
   }
 
   @Override
-  protected MemoryChunkWithRefCount createValueAsUnserializedStoredObject(Object value) {
+  protected StoredObject createValueAsUnserializedStoredObject(Object value) {
     byte[] valueInByteArray;
     if (value instanceof Long) {
       valueInByteArray = convertValueToByteArray(value);
@@ -113,23 +113,23 @@ public class OffHeapHelperJUnitTest extends AbstractStoredObjectTestBase {
     boolean isSerialized = false;
     boolean isCompressed = false;
 
-    MemoryChunkWithRefCount createdObject = createChunk(valueInByteArray, isSerialized, isCompressed);
+    StoredObject createdObject = createChunk(valueInByteArray, isSerialized, isCompressed);
     return createdObject;
   }
 
   @Override
-  protected MemoryChunkWithRefCount createValueAsSerializedStoredObject(Object value) {
+  protected StoredObject createValueAsSerializedStoredObject(Object value) {
     byte[] valueInSerializedByteArray = EntryEventImpl.serialize(value);
 
     boolean isSerialized = true;
     boolean isCompressed = false;
 
-    MemoryChunkWithRefCount createdObject = createChunk(valueInSerializedByteArray, isSerialized, isCompressed);
+    StoredObject createdObject = createChunk(valueInSerializedByteArray, isSerialized, isCompressed);
     return createdObject;
   }
 
-  private ObjectChunk createChunk(byte[] v, boolean isSerialized, boolean isCompressed) {
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(v, isSerialized, isCompressed);
+  private OffHeapStoredObject createChunk(byte[] v, boolean isSerialized, boolean isCompressed) {
+    OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocateAndInitialize(v, isSerialized, isCompressed);
     return chunk;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3087c86f/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
index 8de0406..ae1b35d 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionBase.java
@@ -92,7 +92,7 @@ public abstract class OffHeapRegionBase {
       assertNotNull(ma);
       final long offHeapSize = ma.getFreeMemory();
       assertEquals(0, ma.getUsedMemory());
-      MemoryChunk mc1 = ma.allocate(64);
+      StoredObject mc1 = ma.allocate(64);
       assertEquals(64+perObjectOverhead(), ma.getUsedMemory());
       assertEquals(offHeapSize-(64+perObjectOverhead()), ma.getFreeMemory());
       mc1.release();
@@ -123,7 +123,7 @@ public abstract class OffHeapRegionBase {
       assertNotNull(ma);
       final long offHeapSize = ma.getFreeMemory();
       assertEquals(0, ma.getUsedMemory());
-      MemoryChunk mc1 = ma.allocate(64);
+      StoredObject mc1 = ma.allocate(64);
       assertEquals(64+perObjectOverhead(), ma.getUsedMemory());
       assertEquals(offHeapSize-(64+perObjectOverhead()), ma.getFreeMemory());
       mc1.release();
@@ -163,11 +163,11 @@ public abstract class OffHeapRegionBase {
       final long offHeapSize = ma.getFreeMemory();
       assertEquals(0, ma.getUsedMemory());
       byte[] data = new byte[] {1,2,3,4,5,6,7,8};
-      MemoryChunk mc1 = (MemoryChunk)ma.allocateAndInitialize(data, false, false);
+      StoredObject mc1 = (StoredObject)ma.allocateAndInitialize(data, false, false);
       assertEquals(data.length+perObjectOverhead(), ma.getUsedMemory());
       assertEquals(offHeapSize-(data.length+perObjectOverhead()), ma.getFreeMemory());
       byte[] data2 = new byte[data.length];
-      mc1.readBytes(0, data2);
+      mc1.readDataBytes(0, data2);
       assertTrue(Arrays.equals(data, data2));
       mc1.release();
       assertEquals(offHeapSize, ma.getFreeMemory());
@@ -540,11 +540,11 @@ public abstract class OffHeapRegionBase {
     @Released(OffHeapIdentifier.TEST_OFF_HEAP_REGION_BASE_LISTENER)
     @Override
     public void close() {
-      if (this.ohOldValue instanceof ObjectChunk) {
-        ((ObjectChunk)this.ohOldValue).release();
+      if (this.ohOldValue instanceof OffHeapStoredObject) {
+        ((OffHeapStoredObject)this.ohOldValue).release();
       }
-      if (this.ohNewValue instanceof ObjectChunk) {
-        ((ObjectChunk)this.ohNewValue).release();
+      if (this.ohNewValue instanceof OffHeapStoredObject) {
+        ((OffHeapStoredObject)this.ohNewValue).release();
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3087c86f/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 5d53109..540bba5 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
@@ -54,7 +54,7 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
 @Category(UnitTest.class)
 @RunWith(PowerMockRunner.class)
 @PowerMockIgnore("*.UnitTest")
-@PrepareForTest({ ObjectChunk.class, OffHeapRegionEntryHelper.class })
+@PrepareForTest({ OffHeapStoredObject.class, OffHeapRegionEntryHelper.class })
 public class OffHeapRegionEntryHelperJUnitTest {
 
   private static final Long VALUE_IS_NOT_ENCODABLE = 0L;
@@ -75,13 +75,13 @@ public class OffHeapRegionEntryHelperJUnitTest {
     SimpleMemoryAllocatorImpl.freeOffHeapMemory();
   }
 
-  private ObjectChunk createChunk(Object value) {
+  private OffHeapStoredObject createChunk(Object value) {
     byte[] v = EntryEventImpl.serialize(value);
 
     boolean isSerialized = true;
     boolean isCompressed = false;
 
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(v, isSerialized, isCompressed);
+    OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocateAndInitialize(v, isSerialized, isCompressed);
 
     return chunk;
   }
@@ -294,8 +294,8 @@ public class OffHeapRegionEntryHelperJUnitTest {
 
   @Test
   public void isOffHeapShouldReturnTrueIfAddressIsOnOffHeap() {
-    ObjectChunk value = createChunk(Long.MAX_VALUE);
-    assertThat(OffHeapRegionEntryHelper.isOffHeap(value.getMemoryAddress())).isTrue();
+    OffHeapStoredObject value = createChunk(Long.MAX_VALUE);
+    assertThat(OffHeapRegionEntryHelper.isOffHeap(value.getAddress())).isTrue();
   }
 
   @Test
@@ -327,28 +327,28 @@ public class OffHeapRegionEntryHelperJUnitTest {
     long oldAddress = 1L;
 
     // testing when the newValue is a chunk
-    ObjectChunk newValue = createChunk(Long.MAX_VALUE);
+    OffHeapStoredObject newValue = createChunk(Long.MAX_VALUE);
     // mock region entry methods required for test
     when(re.getAddress()).thenReturn(oldAddress);
-    when(re.setAddress(oldAddress, newValue.getMemoryAddress())).thenReturn(Boolean.TRUE);
+    when(re.setAddress(oldAddress, newValue.getAddress())).thenReturn(Boolean.TRUE);
 
     // invoke the method under test
     OffHeapRegionEntryHelper.setValue(re, newValue);
 
     // verify oldAddress is replaced with newAddress
-    verify(re, times(1)).setAddress(oldAddress, newValue.getMemoryAddress());
+    verify(re, times(1)).setAddress(oldAddress, newValue.getAddress());
     // resetting the spy in-order to re-use
     reset(re);
 
     // testing when the newValue is DataAsAddress
-    DataAsAddress newAddress1 = new DataAsAddress(2L);
+    TinyStoredObject newAddress1 = new TinyStoredObject(2L);
     // mock region entry methods required for test
     when(re.getAddress()).thenReturn(oldAddress);
-    when(re.setAddress(oldAddress, newAddress1.getEncodedAddress())).thenReturn(Boolean.TRUE);
+    when(re.setAddress(oldAddress, newAddress1.getAddress())).thenReturn(Boolean.TRUE);
     OffHeapRegionEntryHelper.setValue(re, newAddress1);
 
     // verify oldAddress is replaced with newAddress
-    verify(re, times(1)).setAddress(oldAddress, newAddress1.getEncodedAddress());
+    verify(re, times(1)).setAddress(oldAddress, newAddress1.getAddress());
     reset(re);
 
     // Testing when newValue is Token Objects
@@ -440,27 +440,27 @@ public class OffHeapRegionEntryHelperJUnitTest {
     // mock region entry
     OffHeapRegionEntry re = mock(OffHeapRegionEntry.class);
 
-    ObjectChunk oldValue = createChunk(Long.MAX_VALUE);
-    ObjectChunk newValue = createChunk(Long.MAX_VALUE - 1);
+    OffHeapStoredObject oldValue = createChunk(Long.MAX_VALUE);
+    OffHeapStoredObject newValue = createChunk(Long.MAX_VALUE - 1);
 
     // mock Chunk static methods - in-order to verify that release is called
-    PowerMockito.spy(ObjectChunk.class);
-    PowerMockito.doNothing().when(ObjectChunk.class);
-    ObjectChunk.release(oldValue.getMemoryAddress());
+    PowerMockito.spy(OffHeapStoredObject.class);
+    PowerMockito.doNothing().when(OffHeapStoredObject.class);
+    OffHeapStoredObject.release(oldValue.getAddress());
 
     // mock region entry methods required for test
-    when(re.getAddress()).thenReturn(oldValue.getMemoryAddress());
-    when(re.setAddress(oldValue.getMemoryAddress(), newValue.getMemoryAddress())).thenReturn(Boolean.TRUE);
+    when(re.getAddress()).thenReturn(oldValue.getAddress());
+    when(re.setAddress(oldValue.getAddress(), newValue.getAddress())).thenReturn(Boolean.TRUE);
 
     // invoke the method under test
     OffHeapRegionEntryHelper.setValue(re, newValue);
 
     // verify oldAddress is changed to newAddress
-    verify(re, times(1)).setAddress(oldValue.getMemoryAddress(), newValue.getMemoryAddress());
+    verify(re, times(1)).setAddress(oldValue.getAddress(), newValue.getAddress());
 
     // verify oldAddress is released
     PowerMockito.verifyStatic();
-    ObjectChunk.release(oldValue.getMemoryAddress());
+    OffHeapStoredObject.release(oldValue.getAddress());
   }
 
   @Test
@@ -472,26 +472,26 @@ public class OffHeapRegionEntryHelperJUnitTest {
     long oldAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(oldData, false, false);
 
     byte[] newData = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt((Integer) Integer.MAX_VALUE - 1).array();
-    DataAsAddress newAddress = new DataAsAddress(OffHeapRegionEntryHelper.encodeDataAsAddress(newData, false, false));
+    TinyStoredObject newAddress = new TinyStoredObject(OffHeapRegionEntryHelper.encodeDataAsAddress(newData, false, false));
 
     // mock Chunk static methods - in-order to verify that release is never called
-    PowerMockito.spy(ObjectChunk.class);
-    PowerMockito.doNothing().when(ObjectChunk.class);
-    ObjectChunk.release(oldAddress);
+    PowerMockito.spy(OffHeapStoredObject.class);
+    PowerMockito.doNothing().when(OffHeapStoredObject.class);
+    OffHeapStoredObject.release(oldAddress);
 
     // mock region entry methods required for test
     when(re.getAddress()).thenReturn(oldAddress);
-    when(re.setAddress(oldAddress, newAddress.getEncodedAddress())).thenReturn(Boolean.TRUE);
+    when(re.setAddress(oldAddress, newAddress.getAddress())).thenReturn(Boolean.TRUE);
 
     // invoke the method under test
     OffHeapRegionEntryHelper.setValue(re, newAddress);
 
     // verify oldAddress is changed to newAddress
-    verify(re, times(1)).setAddress(oldAddress, newAddress.getEncodedAddress());
+    verify(re, times(1)).setAddress(oldAddress, newAddress.getAddress());
 
     // verify that release is never called as the old address is not on offheap
     PowerMockito.verifyStatic(never());
-    ObjectChunk.release(oldAddress);
+    OffHeapStoredObject.release(oldAddress);
   }
 
   @Test
@@ -505,9 +505,9 @@ public class OffHeapRegionEntryHelperJUnitTest {
     long newAddress = OffHeapRegionEntryHelper.REMOVED_PHASE2_ADDRESS;
 
     // mock Chunk static methods - in-order to verify that release is never called
-    PowerMockito.spy(ObjectChunk.class);
-    PowerMockito.doNothing().when(ObjectChunk.class);
-    ObjectChunk.release(oldAddress);
+    PowerMockito.spy(OffHeapStoredObject.class);
+    PowerMockito.doNothing().when(OffHeapStoredObject.class);
+    OffHeapStoredObject.release(oldAddress);
 
     // mock region entry methods required for test
     when(re.getAddress()).thenReturn(oldAddress);
@@ -521,7 +521,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
 
     // verify that release is never called as the old address is not on offheap
     PowerMockito.verifyStatic(never());
-    ObjectChunk.release(oldAddress);
+    OffHeapStoredObject.release(oldAddress);
   }
 
   @Test(expected = IllegalStateException.class)
@@ -541,10 +541,10 @@ public class OffHeapRegionEntryHelperJUnitTest {
     // mock region entry
     OffHeapRegionEntry re = mock(OffHeapRegionEntry.class);
 
-    ObjectChunk chunk = createChunk(Long.MAX_VALUE);
+    OffHeapStoredObject chunk = createChunk(Long.MAX_VALUE);
 
     // mock region entry methods required for test
-    when(re.getAddress()).thenReturn(chunk.getMemoryAddress());
+    when(re.getAddress()).thenReturn(chunk.getAddress());
     Token token = OffHeapRegionEntryHelper.getValueAsToken(re);
 
     assertThat(token).isEqualTo(Token.NOT_A_TOKEN);
@@ -627,10 +627,10 @@ public class OffHeapRegionEntryHelperJUnitTest {
 
   @Test
   public void addressToObjectShouldReturnValueFromChunk() {
-    ObjectChunk expected = createChunk(Long.MAX_VALUE);
-    Object actual = OffHeapRegionEntryHelper.addressToObject(expected.getMemoryAddress(), false, null);
+    OffHeapStoredObject expected = createChunk(Long.MAX_VALUE);
+    Object actual = OffHeapRegionEntryHelper.addressToObject(expected.getAddress(), false, null);
 
-    assertThat(actual).isInstanceOf(ObjectChunk.class);
+    assertThat(actual).isInstanceOf(OffHeapStoredObject.class);
     assertThat(actual).isEqualTo(expected);
   }
 
@@ -640,7 +640,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
     boolean isSerialized = true;
     boolean isCompressed = true;
 
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(data, isSerialized, isCompressed);
+    OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocateAndInitialize(data, isSerialized, isCompressed);
 
     // create the mock context
     RegionEntryContext regionContext = mock(RegionEntryContext.class);
@@ -655,7 +655,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
     when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
     when(cacheStats.startDecompression()).thenReturn(startTime);
 
-    Object actual = OffHeapRegionEntryHelper.addressToObject(chunk.getMemoryAddress(), true, regionContext);
+    Object actual = OffHeapRegionEntryHelper.addressToObject(chunk.getAddress(), true, regionContext);
 
     assertThat(actual).isInstanceOf(VMCachedDeserializable.class);
 
@@ -669,7 +669,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
     boolean isSerialized = false;
     boolean isCompressed = true;
 
-    ObjectChunk chunk = (ObjectChunk) ma.allocateAndInitialize(data, isSerialized, isCompressed);
+    OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocateAndInitialize(data, isSerialized, isCompressed);
 
     // create the mock context
     RegionEntryContext regionContext = mock(RegionEntryContext.class);
@@ -684,7 +684,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
     when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
     when(cacheStats.startDecompression()).thenReturn(startTime);
 
-    Object actual = OffHeapRegionEntryHelper.addressToObject(chunk.getMemoryAddress(), true, regionContext);
+    Object actual = OffHeapRegionEntryHelper.addressToObject(chunk.getAddress(), true, regionContext);
 
     assertThat(actual).isInstanceOf(byte[].class);
     assertThat(actual).isEqualTo(data);
@@ -695,10 +695,10 @@ public class OffHeapRegionEntryHelperJUnitTest {
     byte[] data = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt(Integer.MAX_VALUE).array();
     long address = OffHeapRegionEntryHelper.encodeDataAsAddress(data, false, false);
 
-    DataAsAddress expected = new DataAsAddress(address);
+    TinyStoredObject expected = new TinyStoredObject(address);
     Object actual = OffHeapRegionEntryHelper.addressToObject(address, false, null);
 
-    assertThat(actual).isInstanceOf(DataAsAddress.class);
+    assertThat(actual).isInstanceOf(TinyStoredObject.class);
     assertThat(actual).isEqualTo(expected);
   }
 
@@ -795,7 +795,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
     boolean isCompressed = true;
 
     long address = OffHeapRegionEntryHelper.encodeDataAsAddress(data, isSerialized, isCompressed);
-    DataAsAddress daa = new DataAsAddress(address);
+    TinyStoredObject daa = new TinyStoredObject(address);
 
     int actualLength = OffHeapRegionEntryHelper.getSerializedLengthFromDataAsAddress(daa);
 
@@ -804,7 +804,7 @@ public class OffHeapRegionEntryHelperJUnitTest {
 
   @Test
   public void getSerializedLengthFromDataAsAddressShouldReturnZeroForNonEncodedAddress() {
-    DataAsAddress nonEncodedAddress = new DataAsAddress(100000L);
+    TinyStoredObject nonEncodedAddress = new TinyStoredObject(100000L);
     int actualLength = OffHeapRegionEntryHelper.getSerializedLengthFromDataAsAddress(nonEncodedAddress);
     assertThat(actualLength).isZero();
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3087c86f/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectAddressStackJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectAddressStackJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectAddressStackJUnitTest.java
new file mode 100644
index 0000000..8040bf7
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectAddressStackJUnitTest.java
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.offheap;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+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.mockito.listeners.InvocationListener;
+import org.mockito.listeners.MethodInvocationReport;
+
+import com.gemstone.gemfire.LogWriter;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class OffHeapStoredObjectAddressStackJUnitTest {
+  static {
+    ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
+  }
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+  }
+
+  @Before
+  public void setUp() throws Exception {
+  }
+
+  @After
+  public void tearDown() throws Exception {
+  }
+
+  @Test
+  public void addressZeroCausesStackToBeEmpty() {
+    OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack(0L);
+    assertEquals(true, stack.isEmpty());
+  }
+
+  @Test
+  public void defaultStackIsEmpty() {
+    OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+    assertEquals(true, stack.isEmpty());
+  }
+
+  @Test
+  public void defaultStackReturnsZeroFromTop() {
+    OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+    assertEquals(0L, stack.getTopAddress());
+  }
+  
+  @Test
+  public void defaultStackReturnsZeroFromPoll() {
+    OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+    assertEquals(0L, stack.poll());
+  }
+  
+  @Test
+  public void defaultStackReturnsZeroFromClear() {
+    OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+    assertEquals(0L, stack.clear());
+    assertEquals(true, stack.isEmpty());
+  }
+  
+  @Test
+  public void defaultStackLogsNothing() {
+    OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+    LogWriter lw = mock(LogWriter.class, withSettings().invocationListeners(new InvocationListener() {
+      @Override
+      public void reportInvocation(MethodInvocationReport methodInvocationReport) {
+        fail("Unexpected invocation");
+      }
+    }));
+    stack.logSizes(lw, "should not be used");
+  }
+  
+  @Test
+  public void defaultStackComputeSizeIsZero() {
+    OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+    assertEquals(0L, stack.computeTotalSize());
+  }
+  
+  @Test
+  public void stackCreatedWithAddressIsNotEmpty() {
+    SlabImpl slab = new SlabImpl(1024);
+    try {
+      SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[]{slab});
+      OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocate(100);
+
+      OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack(chunk.getAddress());
+      assertEquals(false, stack.isEmpty());
+    } finally {
+      SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    }
+  }
+
+  @Test
+  public void stackWithChunkIsNotEmpty() {
+    SlabImpl slab = new SlabImpl(1024);
+    try {
+      SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[]{slab});
+      OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocate(100);
+
+      OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+      stack.offer(chunk.getAddress());
+      assertEquals(false, stack.isEmpty());
+    } finally {
+      SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    }
+  }
+
+  @Test
+  public void stackWithChunkTopEqualsAddress() {
+    SlabImpl slab = new SlabImpl(1024);
+    try {
+      SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[]{slab});
+      OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocate(100);
+
+      long addr = chunk.getAddress();
+      OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+      stack.offer(addr);
+      assertEquals(addr, stack.getTopAddress());
+    } finally {
+      SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    }
+  }
+
+  @Test
+  public void addressZeroOfferCausesFailedAssertion() {
+    OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack(0L);
+    try {
+      stack.offer(0);
+      fail("expected AssertionError");
+    } catch (AssertionError expected) {
+    }
+  }
+
+
+  @Test
+  public void stackWithChunkClearReturnsAddressAndEmptiesStack() {
+    SlabImpl slab = new SlabImpl(1024);
+    try {
+      SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[]{slab});
+      OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocate(100);
+
+      long addr = chunk.getAddress();
+      OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+      stack.offer(addr);
+      long clearAddr = stack.clear();
+      assertEquals(addr, clearAddr);
+      assertEquals(true, stack.isEmpty());
+    } finally {
+      SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    }
+  }
+
+  @Test
+  public void stackWithChunkPollReturnsAddressAndEmptiesStack() {
+    SlabImpl slab = new SlabImpl(1024);
+    try {
+      SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[]{slab});
+      OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocate(100);
+
+      long addr = chunk.getAddress();
+      OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+      stack.offer(addr);
+      long pollAddr = stack.poll();
+      assertEquals(addr, pollAddr);
+      assertEquals(true, stack.isEmpty());
+    } finally {
+      SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    }
+  }
+
+  @Test
+  public void stackWithChunkTotalSizeIsChunkSize() {
+    SlabImpl slab = new SlabImpl(1024);
+    try {
+      SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[]{slab});
+      OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocate(100);
+      int chunkSize = chunk.getSize();
+
+      long addr = chunk.getAddress();
+      OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+      stack.offer(addr);
+      assertEquals(chunkSize, stack.computeTotalSize());
+    } finally {
+      SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    }
+  }
+
+
+  @Test
+  public void stackWithChunkLogShowsMsgAndSize() {
+    SlabImpl slab = new SlabImpl(1024);
+    try {
+      SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[]{slab});
+      OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocate(100);
+      int chunkSize = chunk.getSize();
+
+      long addr = chunk.getAddress();
+      OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
+      stack.offer(addr);
+      LogWriter lw = mock(LogWriter.class);
+      stack.logSizes(lw, "foo");
+      verify(lw).info("foo"+chunkSize);
+    } finally {
+      SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    }
+  }
+  
+  private class TestableSyncChunkStack extends OffHeapStoredObjectAddressStack {
+    public boolean doConcurrentMod = true;
+    public int chunk2Size;
+    private SimpleMemoryAllocatorImpl ma;
+    TestableSyncChunkStack(SimpleMemoryAllocatorImpl ma) {
+      this.ma = ma;
+    }
+    @Override
+    protected void testHookDoConcurrentModification() {
+      if (doConcurrentMod) {
+        doConcurrentMod = false;
+        OffHeapStoredObject chunk2 = (OffHeapStoredObject) ma.allocate(50);
+        this.chunk2Size = chunk2.getSize();
+        this.offer(chunk2.getAddress());
+      }
+    }
+  }
+  @Test
+  public void stackWithChunkTotalSizeIsChunkSizeWithConcurrentMod() {
+    SlabImpl slab = new SlabImpl(1024);
+    try {
+      SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[]{slab});
+      OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocate(100);
+      int chunkSize = chunk.getSize();
+
+      long addr = chunk.getAddress();
+      TestableSyncChunkStack stack = new TestableSyncChunkStack(ma);
+      stack.offer(addr);
+      long totalSize = stack.computeTotalSize();
+      assertEquals("chunkSize=" + chunkSize + " chunk2Size=" + stack.chunk2Size, chunkSize + stack.chunk2Size, totalSize);
+    } finally {
+      SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    }
+  }
+
+
+  @Test
+  public void stackWithChunkLogShowsMsgAndSizeWithConcurrentMod() {
+    SlabImpl slab = new SlabImpl(1024);
+    try {
+      SimpleMemoryAllocatorImpl ma = SimpleMemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[]{slab});
+      OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocate(100);
+      int chunkSize = chunk.getSize();
+
+      long addr = chunk.getAddress();
+      TestableSyncChunkStack stack = new TestableSyncChunkStack(ma);
+      stack.offer(addr);
+      LogWriter lw = mock(LogWriter.class);
+      stack.logSizes(lw, "foo");
+      verify(lw).info("foo"+chunkSize);
+      verify(lw).info("foo"+stack.chunk2Size);
+    } finally {
+      SimpleMemoryAllocatorImpl.freeOffHeapMemory();
+    }
+  }
+}


Mime
View raw message