use of org.apache.geode.internal.cache.RegionEntryContext in project geode by apache.
the class OffHeapStoredObjectJUnitTest method getDecompressedBytesShouldReturnDecompressedBytesIfCompressed.
@Test
public void getDecompressedBytesShouldReturnDecompressedBytesIfCompressed() {
Object regionEntryValue = getValue();
byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
boolean isSerialized = true;
boolean isCompressed = true;
OffHeapStoredObject chunk = (OffHeapStoredObject) 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();
}
use of org.apache.geode.internal.cache.RegionEntryContext in project geode by apache.
the class TinyStoredObjectJUnitTest method getDecompressedBytesShouldNotTryToDecompressIfNotCompressed.
@Test
public void getDecompressedBytesShouldNotTryToDecompressIfNotCompressed() {
Object regionEntryValue = getValue();
TinyStoredObject offheapAddress = createValueAsUncompressedStoredObject(regionEntryValue);
// mock the thing
RegionEntryContext regionContext = mock(RegionEntryContext.class);
Compressor compressor = mock(Compressor.class);
when(regionContext.getCompressor()).thenReturn(compressor);
// invoke the thing
byte[] actualValueInBytes = offheapAddress.getDecompressedBytes(regionContext);
// createValueAsUncompressedStoredObject does uses a serialized value - so convert it to object
Object actualRegionValue = convertSerializedByteArrayToObject(actualValueInBytes);
// verify the thing happened
verify(regionContext, never()).getCompressor();
assertEquals(regionEntryValue, actualRegionValue);
}
Aggregations