Search in sources :

Example 21 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class ManagedTimeUnifiedStateImplTest method testAsyncGet.

@Test
public void testAsyncGet() throws ExecutionException, InterruptedException {
    Slice one = ManagedStateTestUtils.getSliceFor("1");
    testMeta.managedState.setup(testMeta.operatorContext);
    long time = System.currentTimeMillis();
    testMeta.managedState.beginWindow(0);
    testMeta.managedState.put(time, one, one);
    Future<Slice> valFuture = testMeta.managedState.getAsync(time, one);
    Slice value = valFuture.get();
    Assert.assertEquals("value of one", one, value);
    testMeta.managedState.teardown();
}
Also used : Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 22 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class StateTrackerTest method testEviction.

@Test
public void testEviction() throws InterruptedException {
    testMeta.managedState.latch = new CountDownLatch(1);
    testMeta.managedState.setup(testMeta.operatorContext);
    Slice one = ManagedStateTestUtils.getSliceFor("1");
    testMeta.managedState.beginWindow(System.currentTimeMillis());
    testMeta.managedState.put(1, one, one);
    testMeta.managedState.endWindow();
    testMeta.managedState.latch.await();
    testMeta.managedState.teardown();
    Assert.assertEquals("freed bucket", Sets.newHashSet(1L), testMeta.managedState.freedBuckets);
}
Also used : Slice(com.datatorrent.netlet.util.Slice) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 23 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class DefaultBucketTest method testGetFromReader.

@Test
public void testGetFromReader() throws IOException {
    testMeta.defaultBucket.setup(testMeta.managedStateContext);
    Slice one = ManagedStateTestUtils.getSliceFor("1");
    Map<Slice, Bucket.BucketedValue> unsavedBucket0 = ManagedStateTestUtils.getTestBucketData(0, 100);
    testMeta.managedStateContext.getBucketsFileSystem().writeBucketData(1, 1, unsavedBucket0, -1);
    ManagedStateTestUtils.validateBucketOnFileSystem(testMeta.managedStateContext.getFileAccess(), 1, unsavedBucket0, 1);
    Slice value = testMeta.defaultBucket.get(one, -1, Bucket.ReadSource.READERS);
    Assert.assertEquals("value one", one, value);
    testMeta.defaultBucket.teardown();
}
Also used : Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 24 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class DefaultBucketTest method testCommitted.

@Test
public void testCommitted() {
    testMeta.defaultBucket.setup(testMeta.managedStateContext);
    Slice one = ManagedStateTestUtils.getSliceFor("1");
    testCheckpointed();
    testMeta.defaultBucket.committed(10);
    Slice value = testMeta.defaultBucket.get(one, -1, Bucket.ReadSource.MEMORY);
    Assert.assertEquals("value one", one, value);
    testMeta.defaultBucket.teardown();
}
Also used : Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 25 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class DefaultBucketTest method testPut.

@Test
public void testPut() {
    testMeta.defaultBucket.setup(testMeta.managedStateContext);
    Slice one = ManagedStateTestUtils.getSliceFor("1");
    testMeta.defaultBucket.put(one, 1, one);
    Slice value = testMeta.defaultBucket.get(one, 1, Bucket.ReadSource.MEMORY);
    Assert.assertEquals("value one", one, value);
    value = testMeta.defaultBucket.get(one, 1, Bucket.ReadSource.READERS);
    Assert.assertNull("value not present", value);
    Assert.assertEquals("size of bucket", one.length * 2 + Longs.BYTES, testMeta.defaultBucket.getSizeInBytes());
    testMeta.defaultBucket.teardown();
}
Also used : Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Aggregations

Slice (com.datatorrent.netlet.util.Slice)114 Test (org.junit.Test)65 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Input (com.esotericsoftware.kryo.io.Input)9 IOException (java.io.IOException)6 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 BufferSlice (org.apache.apex.malhar.lib.utils.serde.BufferSlice)4 Path (org.apache.hadoop.fs.Path)4 ObjectMapperString (com.datatorrent.common.util.ObjectMapperString)3 SerializationBuffer (org.apache.apex.malhar.lib.utils.serde.SerializationBuffer)3 StringSerde (org.apache.apex.malhar.lib.utils.serde.StringSerde)3 Attribute (com.datatorrent.api.Attribute)2 OperatorContext (com.datatorrent.api.Context.OperatorContext)2 Output (com.esotericsoftware.kryo.io.Output)2 RandomAccessFile (java.io.RandomAccessFile)2 Serializable (java.io.Serializable)2 HashSet (java.util.HashSet)2