public byte[] getDecompressedBytes(RegionEntryContext context) { byte[] result = getCompressedBytes(); long time = context.getCachePerfStats().startDecompression(); result = context.getCompressor().decompress(result); context.getCachePerfStats().endDecompression(time); return result; }
@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(); }
@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); }
/** * This method determines if the value is in a compressed representation and decompresses it if it * is. * * @param context the values context. * @param value a region entry value. * * @return the decompressed form of the value parameter. */ static Object decompress(RegionEntryContext context, Object value) { if (isCompressible(context, value)) { long time = context.getCachePerfStats().startDecompression(); value = EntryEventImpl.deserialize(context.getCompressor().decompress((byte[]) value)); context.getCachePerfStats().endDecompression(time); } return value; }
public byte[] getDecompressedBytes(RegionEntryContext r) { if (isCompressed()) { byte[] bytes = OffHeapRegionEntryHelper.decodeAddressToRawBytes(getAddress()); long time = r.getCachePerfStats().startDecompression(); bytes = r.getCompressor().decompress(bytes); r.getCachePerfStats().endDecompression(time); return bytes; } return getRawBytes(); }