Search in sources :

Example 6 with Compressor

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

Example 7 with Compressor

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

Example 8 with Compressor

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

Example 9 with Compressor

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);
}
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 10 with Compressor

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);
}
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)23 SnappyCompressor (org.apache.geode.compression.SnappyCompressor)13 Test (org.junit.Test)13 RegionEntryContext (org.apache.geode.internal.cache.RegionEntryContext)7 UnitTest (org.apache.geode.test.junit.categories.UnitTest)7 CachePerfStats (org.apache.geode.internal.cache.CachePerfStats)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 RegionAttributes (org.apache.geode.cache.RegionAttributes)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 RegionShortcut (org.apache.geode.cache.RegionShortcut)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EmptyStackException (java.util.EmptyStackException)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 CacheException (org.apache.geode.cache.CacheException)1 CacheListener (org.apache.geode.cache.CacheListener)1 CacheLoader (org.apache.geode.cache.CacheLoader)1 CacheWriter (org.apache.geode.cache.CacheWriter)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1