Search in sources :

Example 1 with Repository

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

the class KafkaLogReaderIT method initializeTestWithUri.

private void initializeTestWithUri(String uri, String access) {
    final Repository repository = Repository.ofTest(createConfig(uri, access));
    entity = repository.getEntity("entity");
    fooDescriptor = entity.getAttribute("foo");
    operator = repository.getOrCreateOperator(DirectDataOperator.class);
}
Also used : DirectDataOperator(cz.o2.proxima.direct.core.DirectDataOperator) Repository(cz.o2.proxima.repository.Repository)

Example 2 with Repository

use of cz.o2.proxima.repository.Repository 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 3 with Repository

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

the class DirectBatchUnboundedSourceTest method testReadError.

@Test(expected = IOException.class)
public void testReadError() throws Exception {
    PipelineOptions opts = PipelineOptionsFactory.create();
    Repository repo = Repository.ofTest(ConfigFactory.load("test-reference.conf").resolve());
    DirectBatchUnboundedSource source = DirectBatchUnboundedSource.of(repo.asFactory(), throwingReader(), Collections.singletonList(repo.getEntity("gateway").getAttribute("armed")), Long.MIN_VALUE, Long.MAX_VALUE, Collections.emptyMap());
    List<? extends UnboundedSource<StreamElement, Checkpoint>> split = source.split(1, opts);
    assertEquals(1, split.size());
    UnboundedReader<StreamElement> reader = split.get(0).createReader(opts, null);
    while (!reader.advance()) {
        TimeUnit.MILLISECONDS.sleep(10);
    }
}
Also used : Repository(cz.o2.proxima.repository.Repository) Checkpoint(cz.o2.proxima.beam.direct.io.DirectBatchUnboundedSource.Checkpoint) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) StreamElement(cz.o2.proxima.storage.StreamElement) Test(org.junit.Test)

Example 4 with Repository

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

the class DirectBatchUnboundedSourceTest method testOffsetWithNoAdvance.

@Test
public void testOffsetWithNoAdvance() throws Exception {
    PipelineOptions opts = PipelineOptionsFactory.create();
    Repository repo = Repository.ofTest(ConfigFactory.load("test-reference.conf").resolve());
    DirectBatchUnboundedSource source = DirectBatchUnboundedSource.of(repo.asFactory(), Optionals.get(direct.getBatchLogReader(armed)), Collections.singletonList(repo.getEntity("gateway").getAttribute("armed")), Long.MIN_VALUE, Long.MAX_VALUE, Collections.emptyMap());
    List<? extends UnboundedSource<StreamElement, Checkpoint>> split = source.split(1, opts);
    assertEquals(1, split.size());
    OnlineAttributeWriter writer = Optionals.get(direct.getWriter(armed));
    long now = System.currentTimeMillis();
    writer.write(StreamElement.upsert(gateway, armed, UUID.randomUUID().toString(), "key", armed.getName(), now, new byte[] {}), (succ, exc) -> {
    });
    UnboundedReader<StreamElement> reader = split.get(0).createReader(opts, null);
    while (!reader.advance()) {
        TimeUnit.MILLISECONDS.sleep(10);
    }
    Checkpoint checkpoint = (Checkpoint) reader.getCheckpointMark();
    assertNotNull(checkpoint);
    assertEquals(1, checkpoint.getSkipFromFirst());
    reader = split.get(0).createReader(opts, checkpoint);
    checkpoint = (Checkpoint) reader.getCheckpointMark();
    TestUtils.assertSerializable(source);
    TestUtils.assertHashCodeAndEquals(source, SerializableUtils.clone(source));
    assertEquals(checkpoint, reader.getCheckpointMark());
    TestUtils.assertSerializable(checkpoint);
    TestUtils.assertHashCodeAndEquals(checkpoint, SerializableUtils.clone(checkpoint));
}
Also used : Repository(cz.o2.proxima.repository.Repository) Checkpoint(cz.o2.proxima.beam.direct.io.DirectBatchUnboundedSource.Checkpoint) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) OnlineAttributeWriter(cz.o2.proxima.direct.core.OnlineAttributeWriter) StreamElement(cz.o2.proxima.storage.StreamElement) Test(org.junit.Test)

Example 5 with Repository

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

the class DirectBatchUnboundedSourceTest method testDirectBatchUnboundedSourceWithManyAndThrottling.

@Test(timeout = 30000)
public void testDirectBatchUnboundedSourceWithManyAndThrottling() {
    Config config = ConfigFactory.parseString("beam.unbounded-batch.limit.uri = \"inmem:///proxima_gateway\"\n" + "beam.unbounded-batch.limit.throughput = 10000").withFallback(ConfigFactory.load("test-reference.conf")).resolve();
    Repository repo = Repository.ofTest(config);
    AttributeFamilyDescriptor readFamily = Optionals.get(repo.getAllFamilies().filter(af -> af.getName().equals("gateway-storage-stream")).findFirst());
    assertEquals(URI.create("inmem:///proxima_gateway"), readFamily.getStorageUri());
    testBatchUnboundedSourceWithCountUsingRepository(repo, 100);
}
Also used : Repository(cz.o2.proxima.repository.Repository) Config(com.typesafe.config.Config) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) Test(org.junit.Test)

Aggregations

Repository (cz.o2.proxima.repository.Repository)24 StreamElement (cz.o2.proxima.storage.StreamElement)17 Test (org.junit.Test)12 DirectDataOperator (cz.o2.proxima.direct.core.DirectDataOperator)9 EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)9 ArrayList (java.util.ArrayList)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 OnlineAttributeWriter (cz.o2.proxima.direct.core.OnlineAttributeWriter)7 List (java.util.List)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 CheckedThread (org.apache.flink.core.testutils.CheckedThread)5 Config (com.typesafe.config.Config)4 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)4 Checkpoint (cz.o2.proxima.beam.direct.io.DirectBatchUnboundedSource.Checkpoint)3 BatchLogObserver (cz.o2.proxima.direct.batch.BatchLogObserver)3 BatchLogReader (cz.o2.proxima.direct.batch.BatchLogReader)3 KeyValue (cz.o2.proxima.direct.randomaccess.KeyValue)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Test (org.junit.jupiter.api.Test)3