Search in sources :

Example 1 with RandomAccessReader

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);
    });
}
Also used : RandomAccessReader(cz.o2.proxima.direct.randomaccess.RandomAccessReader) RandomOffset(cz.o2.proxima.direct.randomaccess.RandomOffset)

Example 2 with RandomAccessReader

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());
}
Also used : EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) KeyValue(cz.o2.proxima.direct.randomaccess.KeyValue) RandomAccessReader(cz.o2.proxima.direct.randomaccess.RandomAccessReader) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with RandomAccessReader

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());
}
Also used : EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) RandomAccessReader(cz.o2.proxima.direct.randomaccess.RandomAccessReader) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with RandomAccessReader

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());
}
Also used : KeyValue(cz.o2.proxima.direct.randomaccess.KeyValue) RandomAccessReader(cz.o2.proxima.direct.randomaccess.RandomAccessReader) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Example 5 with RandomAccessReader

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());
}
Also used : Arrays(java.util.Arrays) TestTracker(cz.o2.proxima.storage.watermark.GlobalWatermarkThroughputLimiterTest.TestTracker) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) StorageType(cz.o2.proxima.storage.StorageType) DummyFilter(cz.o2.proxima.util.DummyFilter) EventDataToDummy(cz.o2.proxima.transform.EventDataToDummy) CachedView(cz.o2.proxima.direct.view.CachedView) StreamElement(cz.o2.proxima.storage.StreamElement) TransformationRunner(cz.o2.proxima.util.TransformationRunner) Map(java.util.Map) AttributeFamilyProxyDescriptor(cz.o2.proxima.repository.AttributeFamilyProxyDescriptor) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) TransformationDescriptor(cz.o2.proxima.repository.TransformationDescriptor) Optionals(cz.o2.proxima.util.Optionals) TestUtils(cz.o2.proxima.util.TestUtils) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) GlobalWatermarkThroughputLimiter(cz.o2.proxima.storage.watermark.GlobalWatermarkThroughputLimiter) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ConfigRepository(cz.o2.proxima.repository.ConfigRepository) KeyValue(cz.o2.proxima.direct.randomaccess.KeyValue) Assert.assertFalse(org.junit.Assert.assertFalse) Accept(cz.o2.proxima.storage.internal.AbstractDataAccessorFactory.Accept) Optional(java.util.Optional) ElementWiseTransformation(cz.o2.proxima.transform.ElementWiseTransformation) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ThroughputLimiter(cz.o2.proxima.storage.ThroughputLimiter) AttributeProxyDescriptor(cz.o2.proxima.repository.AttributeProxyDescriptor) Iterables(com.google.common.collect.Iterables) LimitedCommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReaders.LimitedCommitLogReader) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ConfigFactory(com.typesafe.config.ConfigFactory) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) RandomAccessReader(cz.o2.proxima.direct.randomaccess.RandomAccessReader) PassthroughFilter(cz.o2.proxima.storage.PassthroughFilter) Config(com.typesafe.config.Config) Assert.assertNotNull(org.junit.Assert.assertNotNull) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) Assert.assertTrue(org.junit.Assert.assertTrue) CommitLogObserver(cz.o2.proxima.direct.commitlog.CommitLogObserver) IOException(java.io.IOException) Test(org.junit.Test) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) NotSerializableException(java.io.NotSerializableException) ReplicationRunner.runAttributeReplicas(cz.o2.proxima.util.ReplicationRunner.runAttributeReplicas) TimeUnit(java.util.concurrent.TimeUnit) GlobalWatermarkTracker(cz.o2.proxima.storage.watermark.GlobalWatermarkTracker) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) RandomAccessReader(cz.o2.proxima.direct.randomaccess.RandomAccessReader) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

RandomAccessReader (cz.o2.proxima.direct.randomaccess.RandomAccessReader)20 EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)18 KeyValue (cz.o2.proxima.direct.randomaccess.KeyValue)14 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)10 Map (java.util.Map)10 Objects (java.util.Objects)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 Slf4j (lombok.extern.slf4j.Slf4j)10 AttributeFamilyDescriptor (cz.o2.proxima.repository.AttributeFamilyDescriptor)9 Optionals (cz.o2.proxima.util.Optionals)9 List (java.util.List)9 Optional (java.util.Optional)9 Set (java.util.Set)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Collectors (java.util.stream.Collectors)9 Iterables (com.google.common.collect.Iterables)8 CommitLogObserver (cz.o2.proxima.direct.commitlog.CommitLogObserver)8 CommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReader)8