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));
}
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()));
}
Aggregations