use of cz.o2.proxima.direct.randomaccess.RandomAccessReader in project proxima-platform by O2-Czech-Republic.
the class ConsoleRandomReader method listKeys.
public void listKeys(Consumer<Pair<RandomOffset, String>> consumer) {
RandomAccessReader reader = getRandomAccessForListKeys(entityDesc);
reader.listEntities(p -> {
RandomOffset off = p.getFirst();
listEntityOffsets.put(p.getSecond(), off);
consumer.accept(p);
});
}
use of cz.o2.proxima.direct.randomaccess.RandomAccessReader in project proxima-platform by O2-Czech-Republic.
the class DirectDataOperatorTest method testProxyScanWithOffset.
@Test
public void testProxyScanWithOffset() {
EntityDescriptor proxied = repo.getEntity("proxied");
AttributeDescriptor<?> source = proxied.getAttribute("event.*");
Set<DirectAttributeFamilyDescriptor> proxiedFamilies = direct.getFamiliesForAttribute(source);
direct.getWriter(source).get().write(StreamElement.upsert(proxied, source, UUID.randomUUID().toString(), "key", "event.abc", System.currentTimeMillis(), "test".getBytes(StandardCharsets.UTF_8)), (s, exc) -> {
assertTrue(s);
});
direct.getWriter(source).get().write(StreamElement.upsert(proxied, source, UUID.randomUUID().toString(), "key", "event.def", System.currentTimeMillis(), "test2".getBytes(StandardCharsets.UTF_8)), (s, exc) -> {
assertTrue(s);
});
List<KeyValue<?>> kvs = new ArrayList<>();
RandomAccessReader reader = proxiedFamilies.iterator().next().getRandomAccessReader().get();
reader.scanWildcard("key", source, reader.fetchOffset(RandomAccessReader.Listing.ATTRIBUTE, "event.abc"), 1, kvs::add);
assertEquals(1, kvs.size());
assertEquals("test2", new String((byte[]) kvs.get(0).getValue()));
assertEquals(source, kvs.get(0).getAttributeDescriptor());
assertEquals("event.def", kvs.get(0).getAttribute());
assertEquals("key", kvs.get(0).getKey());
}
use of cz.o2.proxima.direct.randomaccess.RandomAccessReader in project proxima-platform by O2-Czech-Republic.
the class DirectDataOperatorTest method testApplicationOfProxyTransformOnReplicatedDataWithTransform.
@Test(timeout = 10000)
public void testApplicationOfProxyTransformOnReplicatedDataWithTransform() throws InterruptedException {
repo.reloadConfig(true, ConfigFactory.load().withFallback(ConfigFactory.load("test-replication-proxy.conf")).resolve());
final EntityDescriptor dummy = repo.getEntity("dummy2");
final EntityDescriptor event = repo.getEntity("event");
final AttributeDescriptor<Object> data = event.getAttribute("data");
final AttributeDescriptor<Object> raw = dummy.getAttribute("_e.*", true);
TransformationRunner.runTransformations(repo, direct);
CountDownLatch latch = new CountDownLatch(2);
runAttributeReplicas(direct, tmp -> latch.countDown());
assertTrue(direct.getWriter(data).isPresent());
OnlineAttributeWriter writer = direct.getWriter(data).get();
long now = System.currentTimeMillis();
writer.write(StreamElement.upsert(dummy, data, "uuid", "gw", data.getName(), now, new byte[] { 1, 2 }), (succ, exc) -> {
assertTrue(succ);
latch.countDown();
});
latch.await();
Optional<RandomAccessReader> reader = direct.getFamiliesForAttribute(raw).stream().filter(af -> af.getDesc().getAccess().canRandomRead()).findAny().flatMap(DirectAttributeFamilyDescriptor::getRandomAccessReader);
assertTrue(reader.isPresent());
assertTrue(reader.get().get("gw", raw.toAttributePrefix() + (now + 1), raw).isPresent());
assertFalse(reader.get().get("gw", raw.toAttributePrefix() + now, raw).isPresent());
}
use of cz.o2.proxima.direct.randomaccess.RandomAccessReader in project proxima-platform by O2-Czech-Republic.
the class CassandraDBAccessorTest method testGetSuccess.
/**
* Test get of attribute.
*/
@Test
public void testGetSuccess() throws IOException {
entity = EntityDescriptor.newBuilder().setName("dummy").build();
byte[] payload = new byte[] { 1, 2 };
Row row = mock(Row.class);
when(row.getBytes(0)).thenReturn(ByteBuffer.wrap(payload));
List<Row> rows = Collections.singletonList(row);
ResultSet res = mock(ResultSet.class);
when(res.iterator()).thenReturn(rows.iterator());
TestDBAccessor accessor = new TestDBAccessor(entity, URI.create("cassandra://host:9042/table/?primary=data"), getCfg(TestCqlFactory.class));
try (RandomAccessReader db = accessor.newRandomReader()) {
accessor.setRes(res);
Optional<KeyValue<byte[]>> value = db.get("key", attr);
assertTrue(value.isPresent());
assertEquals("dummy", value.get().getAttribute());
assertEquals("key", value.get().getKey());
assertArrayEquals(payload, value.get().getValue());
}
assertTrue(CassandraDBAccessor.getCLUSTER_MAP().isEmpty());
}
use of cz.o2.proxima.direct.randomaccess.RandomAccessReader in project proxima-platform by O2-Czech-Republic.
the class DirectDataOperatorTest method testApplicationOfProxyTransformOnIncomingData.
@Test(timeout = 10000)
public void testApplicationOfProxyTransformOnIncomingData() throws InterruptedException {
repo.reloadConfig(true, ConfigFactory.load().withFallback(ConfigFactory.load("test-replication-proxy.conf")).resolve());
final EntityDescriptor dummy = repo.getEntity("dummy2");
final AttributeDescriptor<Object> event = dummy.getAttribute("event.*");
final AttributeDescriptor<Object> eventSource = dummy.getAttribute("_dummy2Replication_read$event.*", true);
final AttributeDescriptor<Object> raw = dummy.getAttribute("_e.*", true);
TransformationRunner.runTransformations(repo, direct);
CountDownLatch latch = new CountDownLatch(2);
runAttributeReplicas(direct, tmp -> latch.countDown());
assertTrue(direct.getWriter(eventSource).isPresent());
OnlineAttributeWriter writer = direct.getWriter(eventSource).get();
writer.write(StreamElement.upsert(dummy, eventSource, "uuid", "gw", event.toAttributePrefix() + "1", System.currentTimeMillis(), new byte[] { 1, 2 }), (succ, exc) -> {
assertTrue(succ);
latch.countDown();
});
latch.await();
Optional<RandomAccessReader> reader = direct.getFamiliesForAttribute(event).stream().filter(af -> af.getDesc().getAccess().canRandomRead()).findAny().flatMap(DirectAttributeFamilyDescriptor::getRandomAccessReader);
assertTrue(reader.isPresent());
assertTrue(reader.get().get("gw", event.toAttributePrefix() + "1", event).isPresent());
reader = direct.getFamiliesForAttribute(raw).stream().filter(af -> af.getDesc().getAccess().canRandomRead()).findAny().flatMap(DirectAttributeFamilyDescriptor::getRandomAccessReader);
assertTrue(reader.isPresent());
assertTrue(reader.get().get("gw", raw.toAttributePrefix() + "2", raw).isPresent());
}
Aggregations