use of cz.o2.proxima.direct.view.CachedView in project proxima-platform by O2-Czech-Republic.
the class LocalKafkaCommitLogDescriptorTest method testCachedViewWriteAndListAll.
@Test(timeout = 10000)
public void testCachedViewWriteAndListAll() throws InterruptedException {
Accessor accessor = kafka.createAccessor(direct, createTestFamily(entity, storageUri, partitionsCfg(3, FirstBytePartitioner.class)));
CachedView view = Optionals.get(accessor.getCachedView(context()));
long now = System.currentTimeMillis();
CountDownLatch latch = new CountDownLatch(5);
Stream.of(StreamElement.upsert(entity, attr, UUID.randomUUID().toString(), "key1", attr.getName(), now - 2000, new byte[] { 0 }), StreamElement.upsert(entity, attrWildcard, UUID.randomUUID().toString(), "key1", "wildcard.1", now - 1000, new byte[] { 1, 2 }), StreamElement.deleteWildcard(entity, attrWildcard, UUID.randomUUID().toString(), "key1", now - 500), StreamElement.upsert(entity, attrWildcard, UUID.randomUUID().toString(), "key1", "wildcard.2", now, new byte[] { 1, 2 }), StreamElement.upsert(entity, attrWildcard, UUID.randomUUID().toString(), "key1", "wildcard.3", now - 499, new byte[] { 3, 4 })).forEach(update -> view.write(update, (succ, exc) -> {
assertTrue("Exception: " + exc, succ);
latch.countDown();
}));
latch.await();
List<KeyValue<?>> res = new ArrayList<>();
view.scanWildcardAll("key1", res::add);
assertEquals(3, res.size());
view.assign(IntStream.range(0, 3).mapToObj(this::getPartition).collect(Collectors.toList()));
res.clear();
view.scanWildcardAll("key1", res::add);
assertEquals(3, res.size());
}
use of cz.o2.proxima.direct.view.CachedView in project proxima-platform by O2-Czech-Republic.
the class LocalKafkaCommitLogDescriptorTest method testCachedViewWriteAndList.
@Test(timeout = 10000)
public void testCachedViewWriteAndList() throws InterruptedException {
Accessor accessor = kafka.createAccessor(direct, createTestFamily(entity, storageUri, partitionsCfg(3, FirstBytePartitioner.class)));
CachedView view = Optionals.get(accessor.getCachedView(context()));
long now = System.currentTimeMillis();
CountDownLatch latch = new CountDownLatch(5);
Stream.of(StreamElement.upsert(entity, attr, UUID.randomUUID().toString(), "key1", attr.getName(), now - 1000, new byte[] { 1, 2 }), StreamElement.upsert(entity, attrWildcard, UUID.randomUUID().toString(), "key1", "wildcard.1", now - 1000, new byte[] { 1, 2 }), StreamElement.deleteWildcard(entity, attrWildcard, UUID.randomUUID().toString(), "key1", now - 500), StreamElement.upsert(entity, attrWildcard, UUID.randomUUID().toString(), "key1", "wildcard.2", now, new byte[] { 1, 2 }), StreamElement.upsert(entity, attrWildcard, UUID.randomUUID().toString(), "key1", "wildcard.3", now - 499, new byte[] { 3, 4 })).forEach(update -> view.write(update, (succ, exc) -> {
assertTrue("Exception: ", succ);
latch.countDown();
}));
latch.await();
List<KeyValue<byte[]>> res = new ArrayList<>();
view.scanWildcard("key1", attrWildcard, res::add);
assertEquals(2, res.size());
view.assign(IntStream.range(0, 3).mapToObj(this::getPartition).collect(Collectors.toList()));
res.clear();
view.scanWildcard("key1", attrWildcard, res::add);
assertEquals(2, res.size());
}
use of cz.o2.proxima.direct.view.CachedView in project proxima-platform by O2-Czech-Republic.
the class LocalKafkaCommitLogDescriptorTest method testCachedViewWritePreUpdateAndDeleteWildcard.
@Test(timeout = 10000)
public void testCachedViewWritePreUpdateAndDeleteWildcard() throws InterruptedException {
Accessor accessor = kafka.createAccessor(direct, createTestFamily(entity, storageUri, partitionsCfg(3, KeyPartitioner.class)));
CachedView view = Optionals.get(accessor.getCachedView(context()));
long now = System.currentTimeMillis();
List<StreamElement> updates = Arrays.asList(StreamElement.upsert(entity, attrWildcard, UUID.randomUUID().toString(), "key1", "wildcard.1", now, new byte[] { 1, 2 }), StreamElement.deleteWildcard(entity, attrWildcard, UUID.randomUUID().toString(), "key1", now + 1000L), StreamElement.upsert(entity, attrWildcard, UUID.randomUUID().toString(), "key1", "wildcard.2", now + 500L, new byte[] { 2, 3 }));
CountDownLatch latch = new CountDownLatch(updates.size());
updates.forEach(update -> view.write(update, (succ, exc) -> {
assertTrue("Ex1ception: " + exc, succ);
latch.countDown();
}));
latch.await();
AtomicInteger calls = new AtomicInteger();
view.assign(IntStream.range(0, 3).mapToObj(this::getPartition).collect(Collectors.toList()), (e, c) -> calls.incrementAndGet());
assertEquals(3, calls.get());
}
use of cz.o2.proxima.direct.view.CachedView in project proxima-platform by O2-Czech-Republic.
the class LocalKafkaCommitLogDescriptorTest method testRewriteAndPrefetch.
@Test(timeout = 10000)
public void testRewriteAndPrefetch() throws InterruptedException {
Accessor accessor = kafka.createAccessor(direct, createTestFamily(entity, storageUri, partitionsCfg(3, KeyPartitioner.class)));
CachedView view = Optionals.get(accessor.getCachedView(context()));
long now = System.currentTimeMillis();
List<StreamElement> updates = Arrays.asList(// store first value
StreamElement.upsert(entity, attr, UUID.randomUUID().toString(), "key1", attr.getName(), now, new byte[] { 1, 2 }), // update the value at the same stamp
StreamElement.upsert(entity, attr, UUID.randomUUID().toString(), "key1", attr.getName(), now, new byte[] { 2, 3 }));
CountDownLatch latch = new CountDownLatch(updates.size());
updates.forEach(update -> view.write(update, (succ, exc) -> {
assertTrue("Exception: " + exc, succ);
latch.countDown();
}));
latch.await();
view.assign(IntStream.range(0, 3).mapToObj(this::getPartition).collect(Collectors.toList()));
assertArrayEquals(new byte[] { 2, 3 }, view.get("key1", attr).get().getValue());
view.write(StreamElement.upsert(entity, attr, UUID.randomUUID().toString(), "key1", attr.getName(), now, new byte[] { 3, 4 }), (succ, exc) -> assertTrue(succ));
assertArrayEquals(new byte[] { 3, 4 }, view.get("key1", attr).get().getValue());
view.close();
assertFalse(view.get("key1", attr).isPresent());
view.assign(IntStream.range(0, 3).mapToObj(this::getPartition).collect(Collectors.toList()));
assertArrayEquals(new byte[] { 3, 4 }, view.get("key1", attr).get().getValue());
}
Aggregations