Search in sources :

Example 1 with ExtendedMessage

use of cz.o2.proxima.server.test.Test.ExtendedMessage in project proxima-platform by O2-Czech-Republic.

the class IngestServiceTest method testIngestValidExtendedScheme.

@Test(timeout = 10000)
public void testIngestValidExtendedScheme() throws Exception {
    ExtendedMessage payload = ExtendedMessage.newBuilder().setFirst(1).setSecond(2).build();
    Rpc.Ingest request = Rpc.Ingest.newBuilder().setEntity("test").setAttribute("data").setUuid(UUID.randomUUID().toString()).setKey("my-dummy-entity").setValue(payload.toByteString()).build();
    flushToIngest(request);
    assertEquals(1, responses.size());
    Rpc.Status status = responses.poll();
    assertEquals(200, status.getStatus());
    InMemStorage storage = getInMemStorage();
    Map<String, StreamElement> data = storage.getData();
    assertEquals(2, data.size());
    byte[] value = data.get("/test_inmem/my-dummy-entity#data").getValue();
    assertNotNull(value);
    assertEquals(payload, ExtendedMessage.parseFrom(value));
    value = data.get("/test_inmem/random/my-dummy-entity#data").getValue();
    assertNotNull(value);
    assertEquals(payload, ExtendedMessage.parseFrom(value));
}
Also used : ExtendedMessage(cz.o2.proxima.server.test.Test.ExtendedMessage) Rpc(cz.o2.proxima.proto.service.Rpc) InMemStorage(cz.o2.proxima.direct.storage.InMemStorage) StreamElement(cz.o2.proxima.storage.StreamElement) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 2 with ExtendedMessage

use of cz.o2.proxima.server.test.Test.ExtendedMessage in project proxima-platform by O2-Czech-Republic.

the class RetrieveServiceTest method testGetValidExtendedScheme.

@Test
public void testGetValidExtendedScheme() throws InvalidProtocolBufferException {
    EntityDescriptor entity = server.repo.getEntity("test");
    AttributeDescriptor<?> attribute = entity.getAttribute("data");
    String key = "my-fancy-entity-key";
    ExtendedMessage payload = ExtendedMessage.newBuilder().setFirst(1).setSecond(2).build();
    Optionals.get(server.direct.getWriter(attribute)).write(StreamElement.upsert(entity, attribute, UUID.randomUUID().toString(), key, attribute.getName(), System.currentTimeMillis(), payload.toByteArray()), (s, err) -> {
    });
    Rpc.GetRequest request = Rpc.GetRequest.newBuilder().setEntity(entity.getName()).setAttribute(attribute.getName()).setKey(key).build();
    final List<Rpc.GetResponse> responses = new ArrayList<>();
    final AtomicBoolean finished = new AtomicBoolean(false);
    final StreamObserver<Rpc.GetResponse> responseObserver;
    responseObserver = new StreamObserver<Rpc.GetResponse>() {

        @Override
        public void onNext(Rpc.GetResponse res) {
            responses.add(res);
        }

        @Override
        public void onError(Throwable thrwbl) {
            throw new RuntimeException(thrwbl);
        }

        @Override
        public void onCompleted() {
            finished.set(true);
        }
    };
    retrieve.get(request, responseObserver);
    assertTrue(finished.get());
    assertEquals(1, responses.size());
    Rpc.GetResponse response = responses.get(0);
    assertEquals("Error: " + response.getStatus() + ": " + response.getStatusMessage(), 200, response.getStatus());
    assertEquals(payload, ExtendedMessage.parseFrom(response.getValue().toByteArray()));
}
Also used : Rpc(cz.o2.proxima.proto.service.Rpc) ArrayList(java.util.ArrayList) EntityDescriptor(cz.o2.proxima.repository.EntityDescriptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExtendedMessage(cz.o2.proxima.server.test.Test.ExtendedMessage) Test(org.junit.Test)

Aggregations

Rpc (cz.o2.proxima.proto.service.Rpc)2 ExtendedMessage (cz.o2.proxima.server.test.Test.ExtendedMessage)2 Test (org.junit.Test)2 ByteString (com.google.protobuf.ByteString)1 InMemStorage (cz.o2.proxima.direct.storage.InMemStorage)1 EntityDescriptor (cz.o2.proxima.repository.EntityDescriptor)1 StreamElement (cz.o2.proxima.storage.StreamElement)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1