Search in sources :

Example 1 with UnitOfWorkAbortEvent

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

the class MongoDBTransactionManagerIT method testAbort.

@Test
void testAbort() {
    String testName = "test_abort";
    MongoDatabase mongoDatabase = mongoClient.getDatabase(testName);
    MongoCollection<Document> mongoCollection = mongoDatabase.getCollection(testName);
    mongoCollection.insertOne(new Document().append(DOCUMENT_ID, "test0"));
    MongoDBTransactionManager transactionManager = new TestTransactionManager(mongoClient);
    String id1 = "test1";
    String value1 = "test1";
    transactionManager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
    mongoCollection.insertOne(transactionManager.getClientSession(), new Document().append(DOCUMENT_ID, id1).append(TEST_KEY, value1));
    Document result = mongoCollection.find(transactionManager.getClientSession(), Filters.eq(DOCUMENT_ID, id1)).first();
    assertEquals(new Document().append(DOCUMENT_ID, id1).append(TEST_KEY, value1), result);
    int size1 = (int) mongoCollection.countDocuments(transactionManager.getClientSession());
    assertEquals(2, size1);
    int size2 = (int) mongoCollection.countDocuments();
    assertEquals(1, size2);
    transactionManager.onAfterAbortEvent(new UnitOfWorkAbortEvent(null));
    int size3 = (int) mongoCollection.countDocuments();
    assertEquals(1, size3);
}
Also used : UnitOfWorkStartEvent(org.kie.kogito.uow.events.UnitOfWorkStartEvent) Document(org.bson.Document) UnitOfWorkAbortEvent(org.kie.kogito.uow.events.UnitOfWorkAbortEvent) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.jupiter.api.Test)

Example 2 with UnitOfWorkAbortEvent

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

the class MongoDBTransactionManagerTest method onAfterAbortEvent.

@Test
void onAfterAbortEvent() {
    manager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
    manager.onAfterAbortEvent(new UnitOfWorkAbortEvent(null));
    verify(clientSession, times(1)).abortTransaction();
    verify(clientSession, times(1)).close();
}
Also used : UnitOfWorkStartEvent(org.kie.kogito.uow.events.UnitOfWorkStartEvent) UnitOfWorkAbortEvent(org.kie.kogito.uow.events.UnitOfWorkAbortEvent) Test(org.junit.jupiter.api.Test)

Example 3 with UnitOfWorkAbortEvent

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

the class AbstractTransactionManagerIT method testAbort.

@Test
void testAbort() {
    String testName = "test_abort";
    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";
    transactionManager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
    mongoCollection.insertOne(transactionManager.getClientSession(), new Document().append(DOCUMENT_ID, id1).append(TEST_KEY, value1));
    Document result = mongoCollection.find(transactionManager.getClientSession(), Filters.eq(DOCUMENT_ID, id1)).first();
    assertEquals(new Document().append(DOCUMENT_ID, id1).append(TEST_KEY, value1), result);
    int size1 = (int) mongoCollection.countDocuments(transactionManager.getClientSession());
    assertEquals(2, size1);
    int size2 = (int) mongoCollection.countDocuments();
    assertEquals(1, size2);
    transactionManager.onAfterAbortEvent(new UnitOfWorkAbortEvent(null));
    int size3 = (int) mongoCollection.countDocuments();
    assertEquals(1, size3);
}
Also used : UnitOfWorkStartEvent(org.kie.kogito.uow.events.UnitOfWorkStartEvent) Document(org.bson.Document) UnitOfWorkAbortEvent(org.kie.kogito.uow.events.UnitOfWorkAbortEvent) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.jupiter.api.Test)

Example 4 with UnitOfWorkAbortEvent

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

the class MongoDBTransactionManagerTest method enabled.

@Test
void enabled() {
    MongoDBTransactionManager manager = new MongoDBTransactionManager(mongoClient) {

        @Override
        public boolean enabled() {
            return false;
        }
    };
    manager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
    manager.onAfterAbortEvent(new UnitOfWorkAbortEvent(null));
    verify(mongoClient, never()).startSession();
}
Also used : UnitOfWorkStartEvent(org.kie.kogito.uow.events.UnitOfWorkStartEvent) UnitOfWorkAbortEvent(org.kie.kogito.uow.events.UnitOfWorkAbortEvent) Test(org.junit.jupiter.api.Test)

Example 5 with UnitOfWorkAbortEvent

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

the class AbstractTransactionManagerTest method enabled.

@Test
void enabled() {
    AbstractTransactionManager manager = new AbstractTransactionManager(mongoClient, false) {
    };
    manager.onBeforeStartEvent(new UnitOfWorkStartEvent(null));
    manager.onAfterAbortEvent(new UnitOfWorkAbortEvent(null));
    verify(mongoClient, never()).startSession();
}
Also used : UnitOfWorkStartEvent(org.kie.kogito.uow.events.UnitOfWorkStartEvent) UnitOfWorkAbortEvent(org.kie.kogito.uow.events.UnitOfWorkAbortEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)6 UnitOfWorkAbortEvent (org.kie.kogito.uow.events.UnitOfWorkAbortEvent)6 UnitOfWorkStartEvent (org.kie.kogito.uow.events.UnitOfWorkStartEvent)6 MongoDatabase (com.mongodb.client.MongoDatabase)2 Document (org.bson.Document)2