Search in sources :

Example 16 with Slice

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

the class KryoStreamCodecTest method testSomeMethod.

@Test
public void testSomeMethod() throws IOException {
    TestKryoStreamCodec coder = new TestKryoStreamCodec();
    TestKryoStreamCodec decoder = new TestKryoStreamCodec();
    KryoSerializableStreamCodec<Object> objCoder = new KryoSerializableStreamCodec<Object>();
    Slice sliceOfObj = objCoder.toByteArray(10);
    Integer decodedObj = (Integer) objCoder.fromByteArray(sliceOfObj);
    Assert.assertEquals("codec", decodedObj.intValue(), 10);
    TestTuple tp = new TestTuple(5);
    Slice dsp1 = coder.toByteArray(tp);
    Slice dsp2 = coder.toByteArray(tp);
    Assert.assertEquals(dsp1, dsp2);
    Object tcObject1 = decoder.fromByteArray(dsp1);
    assert (tp.equals(tcObject1));
    Object tcObject2 = decoder.fromByteArray(dsp2);
    assert (tp.equals(tcObject2));
    dsp1 = coder.toByteArray(tp);
    dsp2 = coder.toByteArray(tp);
    Assert.assertEquals(dsp1, dsp2);
}
Also used : Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 17 with Slice

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

the class BucketsFileSystemTest method testGetAllTimeBucketMeta.

@Test
public void testGetAllTimeBucketMeta() throws IOException {
    testMeta.bucketsFileSystem.setup(testMeta.managedStateContext);
    BucketsFileSystem.MutableTimeBucketMeta tbm1 = new BucketsFileSystem.MutableTimeBucketMeta(1, 1);
    tbm1.updateTimeBucketMeta(10, 100, new Slice("1".getBytes()));
    testMeta.bucketsFileSystem.updateTimeBuckets(tbm1);
    BucketsFileSystem.MutableTimeBucketMeta tbm2 = new BucketsFileSystem.MutableTimeBucketMeta(1, 2);
    tbm2.updateTimeBucketMeta(10, 100, new Slice("2".getBytes()));
    testMeta.bucketsFileSystem.updateTimeBuckets(tbm2);
    testMeta.bucketsFileSystem.updateBucketMetaFile(1);
    TreeMap<Long, BucketsFileSystem.TimeBucketMeta> timeBucketMetas = testMeta.bucketsFileSystem.getAllTimeBuckets(1);
    Iterator<Map.Entry<Long, BucketsFileSystem.TimeBucketMeta>> iterator = timeBucketMetas.entrySet().iterator();
    int i = 2;
    while (iterator.hasNext()) {
        BucketsFileSystem.TimeBucketMeta tbm = iterator.next().getValue();
        Assert.assertEquals("time bucket " + i, i, tbm.getTimeBucketId());
        i--;
    }
    testMeta.bucketsFileSystem.teardown();
}
Also used : Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 18 with Slice

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

the class ManagedTimeUnifiedStateImplTest method testSyncGetFromFiles.

@Test
public void testSyncGetFromFiles() throws IOException, ExecutionException, InterruptedException {
    DefaultBucket.setDisableBloomFilterByDefault(true);
    Slice zero = ManagedStateTestUtils.getSliceFor("0");
    long time = System.currentTimeMillis();
    testMeta.managedState.setup(testMeta.operatorContext);
    long timeBucket = testMeta.managedState.getTimeBucketAssigner().getTimeBucket(time);
    Map<Slice, Bucket.BucketedValue> unsavedBucket0 = ManagedStateTestUtils.getTestBucketData(0, timeBucket);
    // write data to disk explicitly
    testMeta.managedState.bucketsFileSystem.writeBucketData(time, 0, unsavedBucket0, -1);
    ManagedStateTestUtils.validateBucketOnFileSystem(testMeta.managedState.getFileAccess(), testMeta.operatorContext.getId(), unsavedBucket0, 1);
    Slice value = testMeta.managedState.getSync(time, zero);
    Assert.assertEquals("value of zero", zero, value);
    testMeta.managedState.teardown();
}
Also used : Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 19 with Slice

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

the class ManagedTimeUnifiedStateImplTest method testAsyncSyncGetFromFiles.

@Test
public void testAsyncSyncGetFromFiles() throws IOException, ExecutionException, InterruptedException {
    DefaultBucket.setDisableBloomFilterByDefault(true);
    Slice zero = ManagedStateTestUtils.getSliceFor("0");
    long time = System.currentTimeMillis();
    testMeta.managedState.setup(testMeta.operatorContext);
    long timeBucket = testMeta.managedState.getTimeBucketAssigner().getTimeBucket(time);
    Map<Slice, Bucket.BucketedValue> unsavedBucket0 = ManagedStateTestUtils.getTestBucketData(0, timeBucket);
    // write data to disk explicitly
    testMeta.managedState.bucketsFileSystem.writeBucketData(time, 0, unsavedBucket0, -1);
    ManagedStateTestUtils.validateBucketOnFileSystem(testMeta.managedState.getFileAccess(), testMeta.operatorContext.getId(), unsavedBucket0, 1);
    Future<Slice> valFuture = testMeta.managedState.getAsync(time, zero);
    Assert.assertEquals("value of zero", zero, valFuture.get());
    testMeta.managedState.teardown();
}
Also used : Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 20 with Slice

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

the class ManagedTimeUnifiedStateImplTest method testSimplePutGet.

@Test
public void testSimplePutGet() {
    Slice one = ManagedStateTestUtils.getSliceFor("1");
    testMeta.managedState.setup(testMeta.operatorContext);
    long time = System.currentTimeMillis();
    testMeta.managedState.beginWindow(0);
    testMeta.managedState.put(time, one, one);
    Slice value = testMeta.managedState.getSync(time, one);
    testMeta.managedState.endWindow();
    Assert.assertEquals("value of one", one, value);
    testMeta.managedState.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