use of cz.o2.proxima.transaction.Response in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testPostCommitOutOfOrder.
@Test(timeout = 10000)
public void testPostCommitOutOfOrder() throws InterruptedException {
createObserver();
State committed = State.open(2001L, now, Collections.emptyList()).committed(Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 2001L, "1")));
observer.transactionPostCommit(committed);
State committed2 = State.open(1001L, now - 1, Collections.emptyList()).committed(Collections.singletonList(KeyAttributes.ofStreamElement(userGateways.delete(1001L, "user", "1", now - 1))));
observer.transactionPostCommit(committed2);
BlockingQueue<Pair<String, Response>> responseQueue = new ArrayBlockingQueue<>(1);
try (ClientTransactionManager clientManager = direct.getClientTransactionManager()) {
String t = "t";
clientManager.begin(t, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), KeyAttributes.ofWildcardQueryElements(user, "user", userGateways, Collections.emptyList()));
Pair<String, Response> response = responseQueue.take();
assertEquals(Response.Flags.ABORTED, response.getSecond().getFlags());
}
}
use of cz.o2.proxima.transaction.Response in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testCreateTransactionCommitWithConflictInInputs.
@Test(timeout = 10000)
public void testCreateTransactionCommitWithConflictInInputs() throws InterruptedException {
createObserver();
ClientTransactionManager clientManager = direct.getClientTransactionManager();
String t1 = UUID.randomUUID().toString();
String t2 = UUID.randomUUID().toString();
List<KeyAttribute> inputs = Collections.singletonList(KeyAttributes.ofAttributeDescriptor(this.user, "user", userGateways, 1L, "1"));
BlockingQueue<Pair<String, Response>> responseQueue = new ArrayBlockingQueue<>(1);
clientManager.begin(t1, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), inputs);
responseQueue.take();
clientManager.commit(t1, Collections.singletonList(KeyAttributes.ofAttributeDescriptor(this.user, "user", userGateways, 2L, "1")));
Pair<String, Response> response = responseQueue.take();
assertEquals(Response.Flags.COMMITTED, response.getSecond().getFlags());
clientManager.begin(t2, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), inputs);
response = responseQueue.take();
assertEquals(Response.Flags.ABORTED, response.getSecond().getFlags());
}
use of cz.o2.proxima.transaction.Response in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testTransactionUpdate.
@Test(timeout = 10000)
public void testTransactionUpdate() throws InterruptedException {
createObserver();
ClientTransactionManager clientManager = direct.getClientTransactionManager();
String transactionId = UUID.randomUUID().toString();
BlockingQueue<Pair<String, Response>> responseQueue = new ArrayBlockingQueue<>(1);
clientManager.begin(transactionId, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 1L, "1")));
// discard this
responseQueue.take();
clientManager.updateTransaction(transactionId, Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user2", userGateways, 2L, "1")));
Pair<String, Response> response = responseQueue.take();
assertTrue(response.getFirst().startsWith("update."));
assertEquals(Response.Flags.UPDATED, response.getSecond().getFlags());
assertFalse(response.getSecond().hasStamp());
do {
State currentState = direct.getServerTransactionManager().getCurrentState(transactionId);
assertNotNull(currentState);
if (currentState.getInputAttributes().size() == 2) {
assertEquals("user", Iterables.get(currentState.getInputAttributes(), 0).getKey());
assertEquals("user2", Iterables.get(currentState.getInputAttributes(), 1).getKey());
break;
}
} while (true);
}
use of cz.o2.proxima.transaction.Response in project proxima-platform by O2-Czech-Republic.
the class RetrieveServiceTest method testGetValidWithTransaction.
@Test
public void testGetValidWithTransaction() {
EntityDescriptor entity = server.repo.getEntity("dummy");
AttributeDescriptor<?> attribute = entity.getAttribute("data");
String key = "my-fancy-entity-key";
Optionals.get(server.direct.getWriter(attribute)).write(StreamElement.upsert(entity, attribute, 1000L, key, attribute.getName(), System.currentTimeMillis(), new byte[] { 1, 2, 3 }), (s, err) -> {
});
String transactionId = UUID.randomUUID().toString();
Rpc.GetRequest request = Rpc.GetRequest.newBuilder().setEntity(entity.getName()).setAttribute(attribute.getName()).setKey(key).setTransactionId(transactionId).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());
assertArrayEquals(new byte[] { 1, 2, 3 }, response.getValue().toByteArray());
assertEquals(1, transactionUpdates.size());
assertTrue(transactionUpdates.containsKey(transactionId));
assertEquals(Collections.singletonList(KeyAttributes.ofAttributeDescriptor(entity, key, attribute, 1000L)), transactionUpdates.get(transactionId));
}
use of cz.o2.proxima.transaction.Response in project proxima-platform by O2-Czech-Republic.
the class RetrieveServiceTest method testListNotFound.
@Test
public void testListNotFound() {
EntityDescriptor entity = server.repo.getEntity("dummy");
AttributeDescriptor<?> attribute = entity.getAttribute("wildcard.*");
String key = "my-fancy-entity-key";
Rpc.ListRequest request = Rpc.ListRequest.newBuilder().setEntity(entity.getName()).setWildcardPrefix("wildcard").setKey(key).setLimit(1).build();
final List<Rpc.ListResponse> responses = new ArrayList<>();
final AtomicBoolean finished = new AtomicBoolean(false);
final StreamObserver<Rpc.ListResponse> responseObserver;
responseObserver = new StreamObserver<Rpc.ListResponse>() {
@Override
public void onNext(Rpc.ListResponse res) {
responses.add(res);
}
@Override
public void onError(Throwable thrwbl) {
throw new RuntimeException(thrwbl);
}
@Override
public void onCompleted() {
finished.set(true);
}
};
retrieve.listAttributes(request, responseObserver);
assertTrue(finished.get());
assertEquals(1, responses.size());
Rpc.ListResponse response = responses.get(0);
assertEquals(200, response.getStatus());
assertTrue(response.getValueList().isEmpty());
}
Aggregations