use of org.apache.geode.compression.Compressor in project geode by apache.
the class CompressionRegionConfigDUnitTest method testPartitionedRegion.
/**
* Sanity check for two peers hosting a partitioned region.
*/
@Test
public void testPartitionedRegion() {
Compressor compressor = new SnappyCompressor();
assertTrue(createCompressedRegionOnVm(getVM(0), REGION_NAME, DataPolicy.PARTITION, compressor));
assertTrue(createCompressedRegionOnVm(getVM(1), REGION_NAME, DataPolicy.PARTITION, compressor));
assertNull(putUsingVM(getVM(0), KEY_1, VALUE_1));
waitOnPut(getVM(1), KEY_1);
assertEquals(VALUE_1, getUsingVM(getVM(1), KEY_1));
cleanup(getVM(0));
}
use of org.apache.geode.compression.Compressor in project geode by apache.
the class CompressionRegionConfigDUnitTest method testCachingClientProxyRegion.
/**
* Sanity check for a caching client and a cache server.
*/
@Test
public void testCachingClientProxyRegion() {
Compressor compressor = new SnappyCompressor();
assertTrue(createCompressedServerRegionOnVm(getVM(0), REGION_NAME, DataPolicy.REPLICATE, compressor));
assertTrue(createCompressedClientRegionOnVm(getVM(1), REGION_NAME, compressor, ClientRegionShortcut.CACHING_PROXY));
assertNull(putUsingClientVM(getVM(1), KEY_1, VALUE_1));
assertEquals(VALUE_1, getUsingClientVM(getVM(1), KEY_1));
assertEquals(VALUE_1, getUsingVM(getVM(0), KEY_1));
cleanupClient(getVM(1));
cleanup(getVM(0));
}
use of org.apache.geode.compression.Compressor in project geode by apache.
the class CompressionRegionConfigDUnitTest method testClientProxyRegion.
/**
* Sanity check for a non caching client and a cache server.
*/
@Test
public void testClientProxyRegion() {
Compressor compressor = new SnappyCompressor();
assertTrue(createCompressedServerRegionOnVm(getVM(0), REGION_NAME, DataPolicy.REPLICATE, compressor));
assertTrue(createCompressedClientRegionOnVm(getVM(1), REGION_NAME, compressor, ClientRegionShortcut.PROXY));
assertNull(putUsingClientVM(getVM(1), KEY_1, VALUE_1));
assertEquals(VALUE_1, getUsingClientVM(getVM(1), KEY_1));
assertEquals(VALUE_1, getUsingVM(getVM(0), KEY_1));
cleanupClient(getVM(1));
cleanup(getVM(0));
}
use of org.apache.geode.compression.Compressor 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.compression.Compressor 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);
}
Aggregations