Search in sources :

Example 1 with RegionEntryContext

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

Example 2 with RegionEntryContext

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

Example 3 with RegionEntryContext

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);
}
Also used : CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) 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)

Example 4 with RegionEntryContext

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

Example 5 with RegionEntryContext

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