use of org.kie.kogito.uow.events.UnitOfWorkEndEvent in project kogito-runtimes by kiegroup.
the class MongoDBTransactionManagerTest method onAfterEndEvent.
@Test
void onAfterEndEvent() {
manager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
manager.onAfterEndEvent(new UnitOfWorkEndEvent(null));
verify(clientSession, times(1)).commitTransaction();
verify(clientSession, times(1)).close();
}
use of org.kie.kogito.uow.events.UnitOfWorkEndEvent in project kogito-runtimes by kiegroup.
the class MongoDBTransactionManagerTest method test.
@Test
void test() throws InterruptedException, ExecutionException, TimeoutException {
ExecutorService service = Executors.newFixedThreadPool(TEST_THREADS);
List<Future<?>> results = new ArrayList<>();
for (int i = 0; i < TEST_THREADS; i++) {
results.add(service.submit(() -> {
manager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
manager.onAfterEndEvent(new UnitOfWorkEndEvent(null));
}));
}
for (Future<?> result : results) {
result.get(2L, TimeUnit.SECONDS);
}
verify(mongoClient, times(TEST_THREADS)).startSession();
verify(clientSession, times(TEST_THREADS)).startTransaction(any());
verify(clientSession, times(TEST_THREADS)).commitTransaction();
verify(clientSession, times(TEST_THREADS)).close();
}
use of org.kie.kogito.uow.events.UnitOfWorkEndEvent in project kogito-runtimes by kiegroup.
the class MongoDBProcessInstancesIT method testWithTransaction.
@Test
void testWithTransaction() {
AbstractTransactionManager transactionManager = new AbstractTransactionManager(mongoClient, true) {
};
transactionManager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
test(transactionManager);
transactionManager.onAfterEndEvent(new UnitOfWorkEndEvent(null));
}
use of org.kie.kogito.uow.events.UnitOfWorkEndEvent in project kogito-runtimes by kiegroup.
the class AbstractTransactionManagerIT method testInsertion.
@Test
void testInsertion() throws InterruptedException, ExecutionException, TimeoutException {
String testName = "test_insertion";
MongoDatabase mongoDatabase = mongoClient.getDatabase(testName);
MongoCollection<Document> mongoCollection = mongoDatabase.getCollection(testName);
mongoCollection.insertOne(new Document().append(DOCUMENT_ID, "test0"));
AbstractTransactionManager transactionManager = new TestTransactionManager(mongoClient);
String id1 = "test1";
String value1 = "test1";
String id2 = "test2";
String value2 = "test2";
ExecutorService service = Executors.newFixedThreadPool(TEST_THREADS);
CountDownLatch latch1 = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(1);
Future<?> execution1 = service.submit(() -> {
try {
transactionManager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
MongoCollection<Document> mongoCollection1 = mongoDatabase.getCollection(testName);
mongoCollection1.insertOne(transactionManager.getClientSession(), new Document().append(DOCUMENT_ID, id1).append(TEST_KEY, value1));
Document result1 = mongoCollection1.find(transactionManager.getClientSession(), Filters.eq(DOCUMENT_ID, id1)).first();
assertEquals(new Document().append(DOCUMENT_ID, id1).append(TEST_KEY, value1), result1);
int size1 = (int) mongoCollection1.countDocuments(transactionManager.getClientSession());
assertEquals(2, size1);
} finally {
latch1.countDown();
assertTrue(latch2.await(10, TimeUnit.SECONDS));
}
transactionManager.onAfterEndEvent(new UnitOfWorkEndEvent(null));
return null;
});
Future<?> execution2 = service.submit(() -> {
try {
transactionManager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
MongoCollection<Document> mongoCollection2 = mongoDatabase.getCollection(testName);
mongoCollection2.insertOne(transactionManager.getClientSession(), new Document().append(DOCUMENT_ID, id2).append(TEST_KEY, value2));
Document result2 = mongoCollection2.find(transactionManager.getClientSession(), Filters.eq(DOCUMENT_ID, id2)).first();
assertEquals(new Document().append(DOCUMENT_ID, id2).append(TEST_KEY, value2), result2);
int size2 = (int) mongoCollection2.countDocuments(transactionManager.getClientSession());
assertEquals(2, size2);
} finally {
latch2.countDown();
assertTrue(latch1.await(10, TimeUnit.SECONDS));
}
transactionManager.onAfterEndEvent(new UnitOfWorkEndEvent(null));
return null;
});
execution1.get(10, TimeUnit.SECONDS);
execution2.get(10, TimeUnit.SECONDS);
assertEquals(3, mongoCollection.countDocuments());
}
use of org.kie.kogito.uow.events.UnitOfWorkEndEvent in project kogito-runtimes by kiegroup.
the class AbstractTransactionManagerTest method onAfterEndEvent.
@Test
void onAfterEndEvent() {
manager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
manager.onAfterEndEvent(new UnitOfWorkEndEvent(null));
verify(clientSession, times(1)).commitTransaction();
verify(clientSession, times(1)).close();
}
Aggregations