Search in sources :

Example 11 with UnitOfWorkEndEvent

use of org.kie.kogito.uow.events.UnitOfWorkEndEvent in project kogito-runtimes by kiegroup.

the class AbstractTransactionManagerTest 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();
}
Also used : UnitOfWorkStartEvent(org.kie.kogito.uow.events.UnitOfWorkStartEvent) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) UnitOfWorkEndEvent(org.kie.kogito.uow.events.UnitOfWorkEndEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)11 UnitOfWorkEndEvent (org.kie.kogito.uow.events.UnitOfWorkEndEvent)11 UnitOfWorkStartEvent (org.kie.kogito.uow.events.UnitOfWorkStartEvent)11 ExecutorService (java.util.concurrent.ExecutorService)6 MongoDatabase (com.mongodb.client.MongoDatabase)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Future (java.util.concurrent.Future)4 Document (org.bson.Document)4 AbstractTransactionManager (org.kie.kogito.mongodb.transaction.AbstractTransactionManager)3 MongoClient (com.mongodb.client.MongoClient)2 MongoClients (com.mongodb.client.MongoClients)2 MongoCollection (com.mongodb.client.MongoCollection)2 MongoCursor (com.mongodb.client.MongoCursor)2 Filters (com.mongodb.client.model.Filters)2 List (java.util.List)2 Objects (java.util.Objects)2 ExecutionException (java.util.concurrent.ExecutionException)2 Executors (java.util.concurrent.Executors)2 TimeUnit (java.util.concurrent.TimeUnit)2