Search in sources :

Example 6 with SerializationBuffer

use of org.apache.apex.malhar.lib.utils.serde.SerializationBuffer 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();
}
Also used : SerializationBuffer(org.apache.apex.malhar.lib.utils.serde.SerializationBuffer) StringSerde(org.apache.apex.malhar.lib.utils.serde.StringSerde) Slice(com.datatorrent.netlet.util.Slice) AffixSerde(org.apache.apex.malhar.lib.utils.serde.AffixSerde) Test(org.junit.Test)

Aggregations

SerializationBuffer (org.apache.apex.malhar.lib.utils.serde.SerializationBuffer)6 StringSerde (org.apache.apex.malhar.lib.utils.serde.StringSerde)4 Slice (com.datatorrent.netlet.util.Slice)3 WindowedBlockStream (org.apache.apex.malhar.lib.utils.serde.WindowedBlockStream)3 Test (org.junit.Test)3 Attribute (com.datatorrent.api.Attribute)1 OperatorContext (com.datatorrent.api.Context.OperatorContext)1 IOException (java.io.IOException)1 Parameters (junitparams.Parameters)1 OperatorContextTestHelper.mockOperatorContext (org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext)1 InMemSpillableStateStore (org.apache.apex.malhar.lib.state.spillable.inmem.InMemSpillableStateStore)1 AffixSerde (org.apache.apex.malhar.lib.utils.serde.AffixSerde)1 IntSerde (org.apache.apex.malhar.lib.utils.serde.IntSerde)1