use of cz.o2.proxima.transaction.Response in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testCreateTransactionCommitWithSameTimestampInOutputs.
@Test(timeout = 10000)
public void testCreateTransactionCommitWithSameTimestampInOutputs() throws InterruptedException {
long stamp = System.currentTimeMillis();
WithFixedTime factory = new WithFixedTime(stamp);
createObserver(factory);
ClientTransactionManager clientManager = direct.getClientTransactionManager();
String t1 = UUID.randomUUID().toString();
String t2 = UUID.randomUUID().toString();
BlockingQueue<Pair<String, Response>> responseQueue = new ArrayBlockingQueue<>(1);
clientManager.begin(t1, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "u1", userGateways, 1L, "1")));
Pair<String, Response> t1OpenResponse = responseQueue.take();
assertEquals(stamp, t1OpenResponse.getSecond().getStamp());
List<KeyAttribute> t1Outputs = Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, t1OpenResponse.getSecond().getSeqId(), "1"));
clientManager.begin(t2, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), // not conflicting with the previous one
Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "u2", userGateways, 1L, "1")));
Pair<String, Response> t2OpenResponse = responseQueue.take();
assertEquals(stamp, t2OpenResponse.getSecond().getStamp());
List<KeyAttribute> t2Outputs = Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, t2OpenResponse.getSecond().getSeqId(), "1"));
clientManager.commit(t1, t1Outputs);
Pair<String, Response> response = responseQueue.take();
assertEquals("commit", response.getFirst());
assertEquals(Response.Flags.COMMITTED, response.getSecond().getFlags());
clientManager.commit(t2, t2Outputs);
response = responseQueue.take();
assertEquals("commit", response.getFirst());
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 testHousekeepingOfWildcardAttributes.
@Test(timeout = 10000)
public void testHousekeepingOfWildcardAttributes() throws InterruptedException {
now = System.currentTimeMillis();
AtomicLong stamp = new AtomicLong(now);
createObserver(new WithTransactionTimeout(100, stamp));
ServerTransactionManager serverManager = observer.getRawManager();
try (ClientTransactionManager clientManager = new TransactionResourceManager(direct, Collections.emptyMap())) {
serverManager.houseKeeping();
String transactionId = "t1";
BlockingQueue<Pair<String, Response>> queue = new ArrayBlockingQueue<>(10);
clientManager.begin(transactionId, (s, r) -> ExceptionUtils.unchecked(() -> queue.put(Pair.of(s, r))), KeyAttributes.ofWildcardQueryElements(this.user, "user", userGateways, Collections.emptyList()));
Pair<String, Response> response = queue.take();
assertEquals(Response.Flags.OPEN, response.getSecond().getFlags());
assertTrue("Expected empty queue, got " + queue, queue.isEmpty());
StreamElement wildcardUpsert = userGateways.upsert(response.getSecond().getSeqId(), "user", "1", now, new byte[] {});
clientManager.commit(transactionId, Collections.singletonList(KeyAttributes.ofStreamElement(wildcardUpsert)));
assertEquals(Response.Flags.COMMITTED, queue.take().getSecond().getFlags());
assertTrue(queue.isEmpty());
// wait till housekeeping time expires
stamp.addAndGet(200L);
transactionId = "t2";
clientManager.begin(transactionId, (s, r) -> ExceptionUtils.unchecked(() -> queue.put(Pair.of(s, r))), KeyAttributes.ofWildcardQueryElements(user, "user", userGateways, Collections.singletonList(wildcardUpsert)));
response = queue.take();
assertEquals(Response.Flags.OPEN, response.getSecond().getFlags());
assertTrue(queue.isEmpty());
wildcardUpsert = userGateways.upsert(response.getSecond().getSeqId(), "user", "1", now, new byte[] {});
clientManager.commit(transactionId, Collections.singletonList(KeyAttributes.ofStreamElement(wildcardUpsert)));
assertEquals(Response.Flags.COMMITTED, queue.take().getSecond().getFlags());
assertTrue(queue.isEmpty());
TimeUnit.MILLISECONDS.sleep(150);
transactionId = "t3";
clientManager.begin(transactionId, (s, r) -> ExceptionUtils.unchecked(() -> queue.put(Pair.of(s, r))), KeyAttributes.ofWildcardQueryElements(this.user, "user", userGateways, Collections.emptyList()));
assertEquals(Response.Flags.ABORTED, queue.take().getSecond().getFlags());
assertTrue(queue.isEmpty());
}
}
use of cz.o2.proxima.transaction.Response in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testCreateTransactionDuplicate.
@Test(timeout = 10000)
public void testCreateTransactionDuplicate() 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")));
Pair<String, Response> firstResponse = responseQueue.take();
clientManager.begin(transactionId, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 1L, "1")));
Pair<String, Response> response = responseQueue.take();
assertTrue(response.getFirst().startsWith("open."));
assertEquals(Response.Flags.DUPLICATE, response.getSecond().getFlags());
assertEquals(firstResponse.getSecond().getSeqId(), response.getSecond().getSeqId());
}
use of cz.o2.proxima.transaction.Response in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testCreateTransactionCommit.
@Test(timeout = 10000)
public void testCreateTransactionCommit() 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")));
responseQueue.take();
clientManager.commit(transactionId, Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 2L, "1")));
Pair<String, Response> response = responseQueue.take();
assertEquals("commit", response.getFirst());
assertEquals(Response.Flags.COMMITTED, response.getSecond().getFlags());
}
use of cz.o2.proxima.transaction.Response in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testTransactionRollback.
@Test(timeout = 10000)
public void testTransactionRollback() 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());
clientManager.rollback(transactionId);
response = responseQueue.take();
assertEquals("rollback", response.getFirst());
assertEquals(Response.Flags.ABORTED, response.getSecond().getFlags());
}
Aggregations