use of cz.o2.proxima.transaction.Commit in project proxima-platform by O2-Czech-Republic.
the class KafkaAccessorTest method testIsAcceptableFailsForRegexp.
@Test
public void testIsAcceptableFailsForRegexp() {
EntityDescriptor entity = EntityDescriptor.newBuilder().setName("entity").build();
URI storageUri = URI.create("kafka://broker/?topicPattern=pattern");
kafkaAccessor = new KafkaAccessor(entity, storageUri, new HashMap<>());
AttributeFamilyDescriptor descriptor = AttributeFamilyDescriptor.newBuilder().setName("test-state-commit-log").setAccess(AccessType.from(ConfigConstants.STATE_COMMIT_LOG)).setType(StorageType.PRIMARY).setStorageUri(storageUri).setEntity(entity).build();
assertThrows(IllegalStateException.class, () -> kafkaAccessor.isAcceptable(descriptor));
}
use of cz.o2.proxima.transaction.Commit in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testCreateTransactionCommitAfterFailover.
@Test(timeout = 10000)
public void testCreateTransactionCommitAfterFailover() throws InterruptedException {
String transactionId = UUID.randomUUID().toString();
BlockingQueue<Pair<String, Response>> responseQueue = new ArrayBlockingQueue<>(1);
try (ClientTransactionManager clientManager = new TransactionResourceManager(direct, Collections.emptyMap())) {
createObserver();
clientManager.begin(transactionId, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 1L, "1")));
takeResponseFor(responseQueue, "open.1");
observer.getRawManager().close();
createObserver();
clientManager.commit(transactionId, Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 2L, "1")));
Pair<String, Response> response = takeResponseFor(responseQueue, "commit");
assertEquals(Response.Flags.COMMITTED, response.getSecond().getFlags());
}
}
use of cz.o2.proxima.transaction.Commit in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testCreateTransactionRollbackAfterFailover.
@Test(timeout = 10000)
public void testCreateTransactionRollbackAfterFailover() throws InterruptedException {
String t1 = "t1-" + UUID.randomUUID();
String t2 = "t2-" + UUID.randomUUID();
BlockingQueue<Pair<String, Response>> responseQueue = new ArrayBlockingQueue<>(1);
try (ClientTransactionManager clientManager = new TransactionResourceManager(direct, Collections.emptyMap())) {
createObserver();
clientManager.begin(t1, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 1L, "1")));
Pair<String, Response> t1openResponse = takeResponseFor(responseQueue, "open.1");
clientManager.begin(t2, ExceptionUtils.uncheckedBiConsumer((k, v) -> responseQueue.put(Pair.of(k, v))), Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 1L, "1")));
Pair<String, Response> t2openResponse = takeResponseFor(responseQueue, "open.1");
assertTrue(t2openResponse.getSecond().getSeqId() > t1openResponse.getSecond().getSeqId());
clientManager.commit(t2, Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 2L, "1")));
Pair<String, Response> t2commitResponse = takeResponseFor(responseQueue, "commit");
assertEquals("commit", t2commitResponse.getFirst());
observer.getRawManager().close();
createObserver();
clientManager.commit(t1, Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, 2L, "1")));
Pair<String, Response> response = takeResponseFor(responseQueue, "commit");
assertTrue("Expected exactly one committed transaction, got " + t2commitResponse.getSecond() + " and " + response.getSecond(), t2commitResponse.getSecond().getFlags() == Response.Flags.COMMITTED ^ response.getSecond().getFlags() == Response.Flags.COMMITTED);
tearDown();
}
}
use of cz.o2.proxima.transaction.Commit in project proxima-platform by O2-Czech-Republic.
the class TransactionLogObserverTest method testCreateTransactionCommitWithConflictInOutputs.
@Test(timeout = 10000)
public void testCreateTransactionCommitWithConflictInOutputs() throws InterruptedException {
createObserver();
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();
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();
List<KeyAttribute> t2Outputs = Collections.singletonList(KeyAttributes.ofAttributeDescriptor(user, "user", userGateways, t2OpenResponse.getSecond().getSeqId(), "1"));
clientManager.commit(t2, t2Outputs);
Pair<String, Response> response = responseQueue.take();
assertEquals("commit", response.getFirst());
assertEquals(Response.Flags.COMMITTED, response.getSecond().getFlags());
clientManager.commit(t1, t1Outputs);
response = responseQueue.take();
assertEquals("commit", response.getFirst());
assertEquals(Response.Flags.ABORTED, response.getSecond().getFlags());
}
use of cz.o2.proxima.transaction.Commit in project proxima-platform by O2-Czech-Republic.
the class LocalKafkaCommitLogDescriptorTest method testOnlineObserveWithRebalanceResetsOffsetCommitter.
@Test(timeout = 100000)
public void testOnlineObserveWithRebalanceResetsOffsetCommitter() throws InterruptedException {
int numWrites = 5;
Accessor accessor = kafka.createAccessor(direct, createTestFamily(entity, storageUri, cfg(Pair.of(LocalKafkaCommitLogDescriptor.CFG_NUM_PARTITIONS, 3), // poll single record to commit it in atomic way
Pair.of(KafkaAccessor.MAX_POLL_RECORDS, 1))));
final CountDownLatch latch = new CountDownLatch(numWrites);
AtomicInteger consumed = new AtomicInteger();
List<OnNextContext> unconfirmed = Collections.synchronizedList(new ArrayList<>());
CommitLogObserver observer = new CommitLogObserver() {
@Override
public boolean onNext(StreamElement ingest, OnNextContext context) {
switch(consumed.getAndIncrement()) {
case 0:
// we must confirm the first message to create a committed position
context.confirm();
break;
case 2:
throw new RuntimeException("Failing first consumer!");
default:
unconfirmed.add(context);
break;
}
if (consumed.get() == numWrites) {
unconfirmed.forEach(OnNextContext::confirm);
}
latch.countDown();
return true;
}
@Override
public void onCompleted() {
}
@Override
public boolean onError(Throwable error) {
return true;
}
};
testOnlineObserveWithRebalanceResetsOffsetCommitterWithObserver(observer, accessor, numWrites);
latch.await();
assertEquals("Invalid committed offests: " + accessor.committedOffsets, 3, accessor.committedOffsets.values().stream().mapToInt(AtomicInteger::get).sum());
}
Aggregations