Search in sources :

Example 6 with RegionEntryContext

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();
}
Also used : CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) Compressor(org.apache.geode.compression.Compressor) RegionEntryContext(org.apache.geode.internal.cache.RegionEntryContext) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 7 with RegionEntryContext

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);
}
Also used : Compressor(org.apache.geode.compression.Compressor) RegionEntryContext(org.apache.geode.internal.cache.RegionEntryContext) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

Compressor (org.apache.geode.compression.Compressor)7 RegionEntryContext (org.apache.geode.internal.cache.RegionEntryContext)7 UnitTest (org.apache.geode.test.junit.categories.UnitTest)7 Test (org.junit.Test)7 CachePerfStats (org.apache.geode.internal.cache.CachePerfStats)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4