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);
}
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();
}
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();
}
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();
}
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();
}
Aggregations