use of org.apache.apex.malhar.lib.utils.serde.AffixSerde in project apex-malhar by apache.
the class DefaultBucketTest method testFreeMemory.
@Test
public void testFreeMemory() throws IOException {
DefaultBucket.setDisableBloomFilterByDefault(false);
testMeta.defaultBucket.setup(testMeta.managedStateContext);
testGetFromReader();
long initSize = testMeta.defaultBucket.getSizeInBytes();
// The temporary memory generated by get was not managed by bucket, only put was managed by bucket
SerializationBuffer buffer = new SerializationBuffer(testMeta.defaultBucket.getKeyStream());
byte[] keyPrefix = new byte[] { 0 };
String key = "1";
String value = "2";
AffixSerde<String> keySerde = new AffixSerde<>(keyPrefix, new StringSerde(), null);
StringSerde valueSerde = new StringSerde();
testMeta.defaultBucket.getKeyStream().beginWindow(1);
testMeta.defaultBucket.getValueStream().beginWindow(1);
keySerde.serialize(key, buffer);
Slice keySlice = buffer.toSlice();
valueSerde.serialize(value, buffer);
Slice valueSlice = buffer.toSlice();
testMeta.defaultBucket.put(keySlice, 1, valueSlice);
testMeta.defaultBucket.getKeyStream().endWindow();
testMeta.defaultBucket.getValueStream().endWindow();
long currentSize = testMeta.defaultBucket.getSizeInBytes();
testMeta.defaultBucket.freeMemory(Long.MAX_VALUE);
// call this method to invoke the release memory
testMeta.defaultBucket.get(keySlice, -1, ReadSource.MEMORY);
long sizeFreed = currentSize - testMeta.defaultBucket.getSizeInBytes();
Assert.assertEquals("size freed", initSize, sizeFreed);
Assert.assertEquals("existing size", currentSize - initSize, testMeta.defaultBucket.getSizeInBytes());
testMeta.defaultBucket.teardown();
}
Aggregations