Search in sources :

Example 1 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class HBaseLogReader method observe.

@Override
public ObserveHandle observe(List<Partition> partitions, List<AttributeDescriptor<?>> attributes, BatchLogObserver observer) {
    TerminationContext terminationContext = new TerminationContext(observer);
    observeInternal(partitions, attributes, observer, terminationContext);
    return terminationContext.asObserveHandle();
}
Also used : TerminationContext(cz.o2.proxima.direct.batch.TerminationContext)

Example 2 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class HadoopBatchLogReader method observe.

@Override
public ObserveHandle observe(List<Partition> partitions, List<AttributeDescriptor<?>> attributes, BatchLogObserver observer) {
    TerminationContext terminationContext = new TerminationContext(observer);
    observeInternal(partitions, attributes, observer, terminationContext);
    return terminationContext.asObserveHandle();
}
Also used : TerminationContext(cz.o2.proxima.direct.batch.TerminationContext)

Example 3 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class BeamStreamTest method testInterruptible.

@Test(timeout = 10000)
public void testInterruptible() throws InterruptedException {
    Repository repo = Repository.ofTest(ConfigFactory.load("test-reference.conf"));
    BeamDataOperator op = repo.getOrCreateOperator(BeamDataOperator.class);
    EntityDescriptor gateway = repo.getEntity("gateway");
    AttributeDescriptor<?> armed = gateway.getAttribute("armed");
    SynchronousQueue<Boolean> interrupt = new SynchronousQueue<>();
    Stream<StreamElement> stream = BeamStream.stream(op, Position.OLDEST, false, true, interrupt::take, BeamStream::createPipelineDefault, armed);
    CountDownLatch latch = new CountDownLatch(1);
    new Thread(() -> {
        // collect endless stream
        stream.collect();
        latch.countDown();
    }).start();
    // terminate
    interrupt.put(true);
    // and wait until the pipeline terminates
    latch.await();
    // make sonar happy
    assertTrue(true);
}
Also used : StreamElement(cz.o2.proxima.storage.StreamElement) CountDownLatch(java.util.concurrent.CountDownLatch) BeamDataOperator(cz.o2.proxima.beam.core.BeamDataOperator) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) Repository(cz.o2.proxima.repository.Repository) SynchronousQueue(java.util.concurrent.SynchronousQueue) StreamTest(cz.o2.proxima.tools.groovy.StreamTest) Test(org.junit.Test)

Example 4 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class AttributeFamilyProxyDataDescriptorTest method testReadingFromProxy.

@Test
public void testReadingFromProxy() {
    EntityDescriptor proxied = repo.getEntity("proxied");
    AttributeDescriptor<byte[]> event = proxied.getAttribute("event.*");
    direct.getWriter(event).orElseThrow(() -> new IllegalArgumentException("Missing writer for " + event)).write(newEvent(proxied, event), (succ, exc) -> {
    });
    Pipeline p = Pipeline.create();
    PCollection<StreamElement> input = beam.getBatchSnapshot(p, event);
    PCollection<Long> result = input.apply(Count.globally());
    PAssert.that(result).containsInAnyOrder(1L);
    assertNotNull(p.run());
}
Also used : EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) StreamElement(cz.o2.proxima.storage.StreamElement) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 5 with AttributeDescriptor

use of cz.o2.proxima.repository.AttributeDescriptor in project proxima-platform by O2-Czech-Republic.

the class BeamDataOperatorTest method testStreamFromOldestWithKafkaTest.

@Test
public void testStreamFromOldestWithKafkaTest() {
    Config config = ConfigFactory.parseMap(Collections.singletonMap("attributeFamilies.event-storage-stream.storage", "kafka-test://dummy/events")).withFallback(ConfigFactory.load("test-reference.conf"));
    Repository repo = Repository.ofTest(config);
    EntityDescriptor event = repo.getEntity("event");
    AttributeDescriptor<?> data = event.getAttribute("data");
    int numElements = 10000;
    long now = System.currentTimeMillis();
    try (DirectDataOperator direct = repo.getOrCreateOperator(DirectDataOperator.class);
        BeamDataOperator operator = repo.getOrCreateOperator(BeamDataOperator.class)) {
        for (int i = 0; i < numElements; i++) {
            direct.getWriter(data).orElseThrow(() -> new IllegalStateException("Missing writer for data")).write(StreamElement.upsert(event, data, UUID.randomUUID().toString(), UUID.randomUUID().toString(), data.getName(), now + i, new byte[] {}), (succ, exc) -> {
            });
        }
        Pipeline p = Pipeline.create();
        PCollection<StreamElement> input = operator.getStream(p, Position.OLDEST, true, true, data);
        PCollection<Long> count = input.apply(Count.globally());
        PAssert.that(count).containsInAnyOrder(Collections.singletonList((long) numElements));
        assertNotNull(p.run());
    }
}
Also used : Config(com.typesafe.config.Config) StreamElement(cz.o2.proxima.storage.StreamElement) Pipeline(org.apache.beam.sdk.Pipeline) DirectDataOperator(cz.o2.proxima.direct.core.DirectDataOperator) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) Repository(cz.o2.proxima.repository.Repository) Test(org.junit.Test)

Aggregations

EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)71 Test (org.junit.Test)59 StreamElement (cz.o2.proxima.storage.StreamElement)51 ArrayList (java.util.ArrayList)46 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)33 CountDownLatch (java.util.concurrent.CountDownLatch)33 List (java.util.List)29 KeyValue (cz.o2.proxima.direct.randomaccess.KeyValue)24 Slf4j (lombok.extern.slf4j.Slf4j)24 CommitLogObserver (cz.o2.proxima.direct.commitlog.CommitLogObserver)22 Map (java.util.Map)22 Collectors (java.util.stream.Collectors)22 CommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReader)21 RandomAccessReader (cz.o2.proxima.direct.randomaccess.RandomAccessReader)21 AttributeFamilyDescriptor (cz.o2.proxima.repository.AttributeFamilyDescriptor)20 Arrays (java.util.Arrays)20 Collections (java.util.Collections)20 Optional (java.util.Optional)20 Set (java.util.Set)20 AtomicReference (java.util.concurrent.atomic.AtomicReference)20