Search in sources :

Example 1 with StreamElement

use of cz.o2.proxima.storage.StreamElement in project proxima-platform by O2-Czech-Republic.

the class HBaseLogReaderTest method testObserveLast.

@Test(timeout = 30000)
public void testObserveLast() throws InterruptedException, IOException {
    long now = 1500000000000L;
    write("secon", "dummy", "secon", now);
    write("second", "dummy", "second", now);
    write("third", "dummy", "third", now);
    List<Partition> partitions = reader.getPartitions();
    List<String> keys = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(1);
    reader.observe(partitions.subList(2, 3), Lists.newArrayList(attr), new BatchLogObserver() {

        @Override
        public boolean onNext(StreamElement element) {
            assertEquals(now, element.getStamp());
            keys.add(element.getKey());
            return true;
        }

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    });
    latch.await();
    assertEquals(Lists.newArrayList("second", "third"), keys);
}
Also used : Partition(cz.o2.proxima.storage.Partition) ArrayList(java.util.ArrayList) StreamElement(cz.o2.proxima.storage.StreamElement) CountDownLatch(java.util.concurrent.CountDownLatch) BatchLogObserver(cz.o2.proxima.direct.batch.BatchLogObserver) Test(org.junit.Test)

Example 2 with StreamElement

use of cz.o2.proxima.storage.StreamElement in project proxima-platform by O2-Czech-Republic.

the class HBaseLogReaderTest method testObserve.

@Test(timeout = 30000)
public void testObserve() throws InterruptedException, IOException {
    long now = 1500000000000L;
    write("a", "dummy", "a", now);
    write("firs", "wildcard.1", "firs", now);
    write("fir", "dummy", "fir", now);
    write("first", "dummy", "first", now);
    List<Partition> partitions = reader.getPartitions();
    List<String> keys = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(1);
    reader.observe(partitions.subList(0, 1), Lists.newArrayList(attr), new BatchLogObserver() {

        @Override
        public boolean onNext(StreamElement element) {
            assertEquals(now, element.getStamp());
            keys.add(element.getKey());
            return true;
        }

        @Override
        public void onCompleted() {
            latch.countDown();
        }
    });
    latch.await();
    assertEquals(Arrays.asList("a", "fir"), keys);
}
Also used : Partition(cz.o2.proxima.storage.Partition) ArrayList(java.util.ArrayList) StreamElement(cz.o2.proxima.storage.StreamElement) CountDownLatch(java.util.concurrent.CountDownLatch) BatchLogObserver(cz.o2.proxima.direct.batch.BatchLogObserver) Test(org.junit.Test)

Example 3 with StreamElement

use of cz.o2.proxima.storage.StreamElement in project proxima-platform by O2-Czech-Republic.

the class HBaseLogReaderTest method testObserveMultiple.

@Test(timeout = 30000)
public void testObserveMultiple() throws IOException, InterruptedException {
    long now = 1500000000000L;
    write("a", "dummy", "a", now);
    write("firs", "wildcard.1", "firs", now);
    write("fir", "dummy", "fir", now);
    write("first", "dummy", "first", now);
    List<Partition> partitions = reader.getPartitions();
    List<String> keys = new ArrayList<>();
    CountDownLatch latch = new CountDownLatch(1);
    assertEquals(3, partitions.size());
    reader.observe(partitions.subList(0, 1), Lists.newArrayList(attr, wildcard), new BatchLogObserver() {

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

        @Override
        public boolean onNext(StreamElement element) {
            assertEquals(now, element.getStamp());
            keys.add(element.getKey());
            return true;
        }

        @Override
        public boolean onError(Throwable error) {
            throw new RuntimeException(error);
        }
    });
    latch.await();
    assertEquals(Lists.newArrayList("a", "fir", "firs"), keys);
}
Also used : Partition(cz.o2.proxima.storage.Partition) ArrayList(java.util.ArrayList) StreamElement(cz.o2.proxima.storage.StreamElement) CountDownLatch(java.util.concurrent.CountDownLatch) BatchLogObserver(cz.o2.proxima.direct.batch.BatchLogObserver) Test(org.junit.Test)

Example 4 with StreamElement

use of cz.o2.proxima.storage.StreamElement in project proxima-platform by O2-Czech-Republic.

the class HBaseWriterTest method testWriteGetObserve.

@Test
public void testWriteGetObserve() throws InterruptedException {
    URI uri = URI.create("hbase://localhost:2181/users?family=u");
    HBaseWriter writer = new HBaseWriter(uri, cluster.getConfiguration(), Collections.emptyMap());
    HBaseLogReader reader = new HBaseLogReader(uri, cluster.getConfiguration(), entity, Executors::newCachedThreadPool);
    RandomHBaseReader randomReader = new RandomHBaseReader(uri, cluster.getConfiguration(), Collections.emptyMap(), entity);
    StreamElement write = StreamElement.upsert(entity, wildcard, UUID.randomUUID().toString(), "key", wildcard.toAttributePrefix() + "1", System.currentTimeMillis(), new byte[] { 1, 2, 3 });
    CountDownLatch writeLatch = new CountDownLatch(1);
    writer.write(write, (succ, exc) -> writeLatch.countDown());
    writeLatch.await();
    List<StreamElement> el = new ArrayList<>();
    CountDownLatch observeLatch = new CountDownLatch(1);
    reader.observe(reader.getPartitions(), Collections.singletonList(wildcard), new BatchLogObserver() {

        @Override
        public boolean onNext(StreamElement element) {
            el.add(element);
            return true;
        }

        @Override
        public void onCompleted() {
            observeLatch.countDown();
        }
    });
    observeLatch.await();
    assertEquals(1, el.size());
    assertEquals(write.getKey(), el.get(0).getKey());
    assertEquals(write.getAttribute(), el.get(0).getAttribute());
    assertArrayEquals(write.getValue(), el.get(0).getValue());
    Optional<? extends KeyValue<?>> kv = randomReader.get("key", wildcard.toAttributePrefix() + "1", wildcard, Long.MAX_VALUE);
    assertTrue(kv.isPresent());
    assertEquals(write.getKey(), el.get(0).getKey());
    assertEquals(write.getAttribute(), el.get(0).getAttribute());
    assertArrayEquals(write.getValue(), el.get(0).getValue());
}
Also used : ArrayList(java.util.ArrayList) StreamElement(cz.o2.proxima.storage.StreamElement) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) BatchLogObserver(cz.o2.proxima.direct.batch.BatchLogObserver) URI(java.net.URI) Test(org.junit.Test)

Example 5 with StreamElement

use of cz.o2.proxima.storage.StreamElement in project proxima-platform by O2-Czech-Republic.

the class HadoopStorageTest method testObserveCancel.

@Test(timeout = 5000L)
public void testObserveCancel() throws InterruptedException {
    Map<String, Object> cfg = cfg(HadoopDataAccessor.HADOOP_ROLL_INTERVAL, -1);
    HadoopDataAccessor accessor = new HadoopDataAccessor(TestUtils.createTestFamily(entity, uri, cfg));
    CountDownLatch latch = new CountDownLatch(1);
    writeOneElement(accessor, (success, error) -> {
        assertTrue(success);
        assertNull(error);
        latch.countDown();
    }).updateWatermark(Long.MAX_VALUE);
    latch.await();
    BatchLogReader reader = accessor.getBatchLogReader(direct.getContext()).orElse(null);
    assertNotNull(reader);
    List<Partition> partitions = reader.getPartitions();
    assertEquals(1, partitions.size());
    CountDownLatch cancelledLatch = new CountDownLatch(1);
    AtomicReference<ObserveHandle> handle = new AtomicReference<>();
    handle.set(reader.observe(partitions, Collections.singletonList(attribute), new BatchLogObserver() {

        @Override
        public boolean onNext(StreamElement element) {
            handle.get().close();
            return true;
        }

        @Override
        public void onCompleted() {
            fail("onCompleted should not have been called");
        }

        @Override
        public void onCancelled() {
            cancelledLatch.countDown();
        }

        @Override
        public boolean onError(Throwable error) {
            onCancelled();
            return true;
        }
    }));
    cancelledLatch.await();
}
Also used : Iterables(com.google.common.collect.Iterables) AttributeWriterBase(cz.o2.proxima.direct.core.AttributeWriterBase) BatchLogReader(cz.o2.proxima.direct.batch.BatchLogReader) Partition(cz.o2.proxima.storage.Partition) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) ExceptionUtils(cz.o2.proxima.util.ExceptionUtils) StreamElement(cz.o2.proxima.storage.StreamElement) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ConfigFactory(com.typesafe.config.ConfigFactory) URI(java.net.URI) ObserveHandle(cz.o2.proxima.direct.batch.ObserveHandle) Before(org.junit.Before) BulkAttributeWriter(cz.o2.proxima.direct.core.BulkAttributeWriter) Repository(cz.o2.proxima.repository.Repository) TestUtils(cz.o2.proxima.util.TestUtils) SynchronousQueue(java.util.concurrent.SynchronousQueue) AttributeDescriptor(cz.o2.proxima.repository.AttributeDescriptor) BatchLogObserver(cz.o2.proxima.direct.batch.BatchLogObserver) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test) AttributeFamilyDescriptor(cz.o2.proxima.repository.AttributeFamilyDescriptor) UUID(java.util.UUID) CommitCallback(cz.o2.proxima.direct.core.CommitCallback) File(java.io.File) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ConfigRepository(cz.o2.proxima.repository.ConfigRepository) Rule(org.junit.Rule) Accept(cz.o2.proxima.storage.internal.AbstractDataAccessorFactory.Accept) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) DirectDataOperator(cz.o2.proxima.direct.core.DirectDataOperator) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) Partition(cz.o2.proxima.storage.Partition) ObserveHandle(cz.o2.proxima.direct.batch.ObserveHandle) StreamElement(cz.o2.proxima.storage.StreamElement) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) BatchLogReader(cz.o2.proxima.direct.batch.BatchLogReader) BatchLogObserver(cz.o2.proxima.direct.batch.BatchLogObserver) Test(org.junit.Test)

Aggregations

StreamElement (cz.o2.proxima.storage.StreamElement)308 Test (org.junit.Test)243 CountDownLatch (java.util.concurrent.CountDownLatch)145 ArrayList (java.util.ArrayList)107 CommitLogObserver (cz.o2.proxima.direct.commitlog.CommitLogObserver)89 EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)85 List (java.util.List)82 CommitLogReader (cz.o2.proxima.direct.commitlog.CommitLogReader)77 AttributeDescriptor (cz.o2.proxima.repository.AttributeDescriptor)71 Repository (cz.o2.proxima.repository.Repository)70 DirectDataOperator (cz.o2.proxima.direct.core.DirectDataOperator)65 AtomicReference (java.util.concurrent.atomic.AtomicReference)63 ConfigFactory (com.typesafe.config.ConfigFactory)62 UUID (java.util.UUID)62 ObserveHandle (cz.o2.proxima.direct.commitlog.ObserveHandle)59 Collections (java.util.Collections)59 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)53 Assert (org.junit.Assert)51 URI (java.net.URI)48 HashMap (java.util.HashMap)48