Search in sources :

Example 16 with CommitLogReader

use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.

the class KafkaLogReaderIT method testReadAndWriteSequentialId.

@Test(timeout = 30_000L)
public void testReadAndWriteSequentialId() throws InterruptedException {
    initializeTestWithUri("kafka://\"${broker}\"/topic", "[commit-log]");
    final EmbeddedKafkaBroker embeddedKafka = rule.getEmbeddedKafka();
    final int numPartitions = 3;
    embeddedKafka.addTopics(new NewTopic("topic", numPartitions, (short) 1));
    final CommitLogReader commitLogReader = Optionals.get(operator.getCommitLogReader(fooDescriptor));
    final TestLogObserver observer = new TestLogObserver();
    final ObserveHandle handle = commitLogReader.observe("test-reader", Position.OLDEST, observer);
    handle.waitUntilReady();
    final int numElements = 100;
    writeElements(numElements, true);
    while (observer.getNumReceivedElements() < numElements) {
        TimeUnit.MILLISECONDS.sleep(100);
    }
    observer.getReceivedElements().forEach(e -> assertTrue(e.hasSequentialId()));
    handle.close();
    Assert.assertEquals(numElements, observer.getNumReceivedElements());
    Assert.assertEquals(numElements, numCommittedElements(handle));
}
Also used : ObserveHandle(cz.o2.proxima.direct.commitlog.ObserveHandle) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) NewTopic(org.apache.kafka.clients.admin.NewTopic) EmbeddedKafkaBroker(org.springframework.kafka.test.EmbeddedKafkaBroker) Test(org.junit.Test)

Example 17 with CommitLogReader

use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.

the class ModelTest method testReadWrite.

@Test
public void testReadWrite() throws InterruptedException {
    Regular<BaseEvent> desc = model.getEvent().getDataDescriptor();
    Optional<OnlineAttributeWriter> writer = model.directOperator().getWriter(desc);
    writer.get().write(desc.upsert(UUID.randomUUID().toString(), System.currentTimeMillis(), BaseEvent.newBuilder().setUserName("user").build()), (succ, exc) -> {
    });
    Optional<CommitLogReader> reader = model.directOperator().getCommitLogReader(desc);
    List<String> users = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(1);
    reader.get().observeBulk("consumer", Position.OLDEST, true, new CommitLogObserver() {

        @Override
        public boolean onError(Throwable error) {
            return false;
        }

        @Override
        public void onCompleted() {
            latch.countDown();
        }

        @Override
        public boolean onNext(StreamElement ingest, OnNextContext context) {
            Optional<BaseEvent> baseEvent = desc.valueOf(ingest);
            users.add(baseEvent.get().getUserName());
            return true;
        }
    });
    latch.await();
    assertEquals("user", users.get(0));
}
Also used : Optional(java.util.Optional) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) ArrayList(java.util.ArrayList) BaseEvent(cz.o2.proxima.example.event.Event.BaseEvent) StreamElement(cz.o2.proxima.storage.StreamElement) CountDownLatch(java.util.concurrent.CountDownLatch) CommitLogObserver(cz.o2.proxima.direct.commitlog.CommitLogObserver) OnlineAttributeWriter(cz.o2.proxima.direct.core.OnlineAttributeWriter) Test(org.junit.Test)

Example 18 with CommitLogReader

use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.

the class CommitLogReadTest method testWithMultiplePartitions.

@Test(timeout = 60000)
public void testWithMultiplePartitions() throws InterruptedException {
    int numPartitions = 3;
    int numElements = 10;
    // this test has undebuggable issues on Flink, skip it for now
    if (runner.getSimpleName().equals("DirectRunner")) {
        LocalKafkaCommitLogDescriptor kafka = new LocalKafkaCommitLogDescriptor();
        KafkaAccessor accessor = kafka.createAccessor(direct, createTestFamily(event, URI.create("kafka-test://brokers/topic-" + UUID.randomUUID().toString()), ImmutableMap.of(LocalKafkaCommitLogDescriptor.CFG_NUM_PARTITIONS, numPartitions, WatermarkConfiguration.prefixedKey(WatermarkConfiguration.CFG_ESTIMATOR_FACTORY), FiniteElementsWatermarkEstimatorFactory.class.getName(), WatermarkConfiguration.prefixedKey("numElements"), numElements, WatermarkConfiguration.prefixedKey("name"), UUID.randomUUID().toString())));
        writeElementsToKafka(numElements, accessor);
        CommitLogReader reader = Optionals.get(accessor.getCommitLogReader(direct.getContext()));
        testReadingFromCommitLogMany(numElements, CommitLogRead.of("name", Position.OLDEST, Long.MAX_VALUE, repo, reader));
    }
}
Also used : KafkaAccessor(cz.o2.proxima.direct.kafka.KafkaAccessor) LocalKafkaCommitLogDescriptor(cz.o2.proxima.direct.kafka.LocalKafkaCommitLogDescriptor) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) Test(org.junit.Test)

Example 19 with CommitLogReader

use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.

the class CommitLogReadTest method testWithMultiplePartitionsMany.

@Test(timeout = 120000)
public void testWithMultiplePartitionsMany() throws InterruptedException {
    int numPartitions = 3;
    int numElements = 1000;
    LocalKafkaCommitLogDescriptor kafka = new LocalKafkaCommitLogDescriptor();
    KafkaAccessor accessor = kafka.createAccessor(direct, createTestFamily(event, URI.create("kafka-test://brokers/topic-" + UUID.randomUUID()), ImmutableMap.of(LocalKafkaCommitLogDescriptor.CFG_NUM_PARTITIONS, numPartitions, WatermarkConfiguration.prefixedKey(WatermarkConfiguration.CFG_ESTIMATOR_FACTORY), FiniteElementsWatermarkEstimatorFactory.class.getName(), WatermarkConfiguration.prefixedKey("numElements"), numElements, WatermarkConfiguration.prefixedKey("name"), UUID.randomUUID().toString())));
    writeElementsToKafka(numElements, accessor);
    CommitLogReader reader = Optionals.get(accessor.getCommitLogReader(direct.getContext()));
    testReadingFromCommitLogMany(numElements, CommitLogRead.of("name", Position.OLDEST, Long.MAX_VALUE, repo, reader));
}
Also used : KafkaAccessor(cz.o2.proxima.direct.kafka.KafkaAccessor) LocalKafkaCommitLogDescriptor(cz.o2.proxima.direct.kafka.LocalKafkaCommitLogDescriptor) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) Test(org.junit.Test)

Example 20 with CommitLogReader

use of cz.o2.proxima.direct.commitlog.CommitLogReader in project proxima-platform by O2-Czech-Republic.

the class DirectUnboundedSourceTest method testCheckpointWithNoAdvance.

@Test
public void testCheckpointWithNoAdvance() throws Exception {
    OnlineAttributeWriter writer = Optionals.get(direct.getWriter(armed));
    CommitLogReader commitLogReader = Optionals.get(direct.getCommitLogReader(armed));
    DirectUnboundedSource source = DirectUnboundedSource.of(repo.asFactory(), "name", commitLogReader, Position.OLDEST, true, Long.MAX_VALUE);
    long now = System.currentTimeMillis();
    writer.write(StreamElement.upsert(gateway, armed, UUID.randomUUID().toString(), "key", armed.getName(), now, new byte[] {}), (succ, exc) -> {
    });
    PipelineOptions opts = PipelineOptionsFactory.create();
    UnboundedSource<StreamElement, Checkpoint> split = source.split(1, opts).get(0);
    UnboundedReader<StreamElement> reader = split.createReader(opts, null);
    boolean start = reader.start();
    while (!start && !reader.advance()) {
        TimeUnit.MILLISECONDS.sleep(10);
    }
    Checkpoint mark = (Checkpoint) reader.getCheckpointMark();
    assertNotNull(mark);
    reader = split.createReader(opts, mark);
    TestUtils.assertSerializable(source);
    TestUtils.assertHashCodeAndEquals(source, SerializableUtils.clone(source));
    assertEquals(mark, reader.getCheckpointMark());
    TestUtils.assertSerializable(mark);
    TestUtils.assertHashCodeAndEquals(mark, SerializableUtils.clone(mark));
}
Also used : Checkpoint(cz.o2.proxima.beam.direct.io.DirectUnboundedSource.Checkpoint) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) OnlineAttributeWriter(cz.o2.proxima.direct.core.OnlineAttributeWriter) CommitLogReader(cz.o2.proxima.direct.commitlog.CommitLogReader) StreamElement(cz.o2.proxima.storage.StreamElement) Test(org.junit.Test)

Aggregations

CommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReader)80 Test (org.junit.Test)70 StreamElement (cz.o2.proxima.storage.StreamElement)67 CommitLogObserver (cz.o2.proxima.direct.commitlog.CommitLogObserver)63 CountDownLatch (java.util.concurrent.CountDownLatch)58 ObserveHandle (cz.o2.proxima.direct.commitlog.ObserveHandle)45 ArrayList (java.util.ArrayList)41 EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)34 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)33 List (java.util.List)31 UUID (java.util.UUID)29 ConfigFactory (com.typesafe.config.ConfigFactory)28 DirectDataOperator (cz.o2.proxima.direct.core.DirectDataOperator)28 Offset (cz.o2.proxima.direct.commitlog.Offset)27 Collections (java.util.Collections)27 Collectors (java.util.stream.Collectors)27 OnNextContext (cz.o2.proxima.direct.commitlog.CommitLogObserver.OnNextContext)26 AtomicReference (java.util.concurrent.atomic.AtomicReference)26 Repository (cz.o2.proxima.repository.Repository)25 Accessor (cz.o2.proxima.direct.kafka.LocalKafkaCommitLogDescriptor.Accessor)24