use of org.apache.geode.internal.cache.RegionEntryContext in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method addressToObjectShouldReturnCachedDeserializableFromChunkIfAskedToDecompress.
@Test
public void addressToObjectShouldReturnCachedDeserializableFromChunkIfAskedToDecompress() {
byte[] data = EntryEventImpl.serialize(Long.MAX_VALUE);
boolean isSerialized = true;
boolean isCompressed = true;
OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocateAndInitialize(data, isSerialized, isCompressed);
// create the mock context
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(data)).thenReturn(data);
when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
when(cacheStats.startDecompression()).thenReturn(startTime);
Object actual = OffHeapRegionEntryHelper.addressToObject(chunk.getAddress(), true, regionContext);
assertThat(actual).isInstanceOf(VMCachedDeserializable.class);
Long actualValue = (Long) ((VMCachedDeserializable) actual).getDeserializedForReading();
assertThat(actualValue).isEqualTo(Long.MAX_VALUE);
}
use of org.apache.geode.internal.cache.RegionEntryContext in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method addressToObjectShouldReturnDecompressedValueFromDataAsAddressIfAskedToDecompress.
@Test
public void addressToObjectShouldReturnDecompressedValueFromDataAsAddressIfAskedToDecompress() {
byte[] data = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt(Integer.MAX_VALUE).array();
boolean isSerialized = false;
boolean isCompressed = true;
long address = OffHeapRegionEntryHelper.encodeDataAsAddress(data, isSerialized, isCompressed);
// create the mock context
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(data)).thenReturn(data);
when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
when(cacheStats.startDecompression()).thenReturn(startTime);
Object actual = OffHeapRegionEntryHelper.addressToObject(address, true, regionContext);
assertThat(actual).isInstanceOf(byte[].class);
assertThat(actual).isEqualTo(data);
}
use of org.apache.geode.internal.cache.RegionEntryContext in project geode by apache.
the class TinyStoredObjectJUnitTest method getDecompressedBytesShouldReturnDecompressedBytesIfCompressed.
@Test
public void getDecompressedBytesShouldReturnDecompressedBytesIfCompressed() {
Object regionEntryValue = getValue();
byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
// encode a non-serialized and compressed entry value to address - last argument is to let that
// it is compressed
long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(regionEntryValueAsBytes, false, true);
TinyStoredObject offheapAddress = new TinyStoredObject(encodedAddress);
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 = offheapAddress.getDecompressedBytes(regionContext);
// verify the thing happened
verify(cacheStats, atLeastOnce()).startDecompression();
verify(compressor, times(1)).decompress(regionEntryValueAsBytes);
verify(cacheStats, atLeastOnce()).endDecompression(startTime);
assertArrayEquals(regionEntryValueAsBytes, bytes);
}
use of org.apache.geode.internal.cache.RegionEntryContext in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method addressToObjectShouldReturnDecompressedValueFromChunkIfAskedToDecompress.
@Test
public void addressToObjectShouldReturnDecompressedValueFromChunkIfAskedToDecompress() {
byte[] data = ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong(Long.MAX_VALUE).array();
boolean isSerialized = false;
boolean isCompressed = true;
OffHeapStoredObject chunk = (OffHeapStoredObject) ma.allocateAndInitialize(data, isSerialized, isCompressed);
// create the mock context
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(data)).thenReturn(data);
when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
when(cacheStats.startDecompression()).thenReturn(startTime);
Object actual = OffHeapRegionEntryHelper.addressToObject(chunk.getAddress(), true, regionContext);
assertThat(actual).isInstanceOf(byte[].class);
assertThat(actual).isEqualTo(data);
}
use of org.apache.geode.internal.cache.RegionEntryContext in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method addressToObjectShouldReturnCachedDeserializableFromSerializedDataAsAddressIfAskedToDecompress.
@Test
public void addressToObjectShouldReturnCachedDeserializableFromSerializedDataAsAddressIfAskedToDecompress() {
byte[] data = EntryEventImpl.serialize(Integer.MAX_VALUE);
boolean isSerialized = true;
boolean isCompressed = true;
long address = OffHeapRegionEntryHelper.encodeDataAsAddress(data, isSerialized, isCompressed);
// create the mock context
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(data)).thenReturn(data);
when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
when(cacheStats.startDecompression()).thenReturn(startTime);
Object actual = OffHeapRegionEntryHelper.addressToObject(address, true, regionContext);
assertThat(actual).isInstanceOf(VMCachedDeserializable.class);
Integer actualValue = (Integer) ((VMCachedDeserializable) actual).getDeserializedForReading();
assertThat(actualValue).isEqualTo(Integer.MAX_VALUE);
}
Aggregations