Search in sources :

Example 1 with ProcessInstanceWorkUnit

use of io.automatiko.engine.services.uow.ProcessInstanceWorkUnit in project automatiko-engine by automatiko-io.

the class DefaultUnitOfWorkManagerTest method testUnitOfWorkStartEndOrdered.

@Test
public void testUnitOfWorkStartEndOrdered() {
    UnitOfWork unit = unitOfWorkManager.newUnitOfWork();
    assertThat(unit).isNotNull().isInstanceOf(ManagedUnitOfWork.class);
    assertThat(((ManagedUnitOfWork) unit).delegate()).isInstanceOf(CollectingUnitOfWork.class);
    final AtomicInteger counter = new AtomicInteger(0);
    assertThat(counter.get()).isEqualTo(0);
    final AtomicInteger picounter = new AtomicInteger(0);
    BaseWorkUnit dummyWork = new BaseWorkUnit(counter, (d) -> ((AtomicInteger) d).incrementAndGet());
    ProcessInstanceWorkUnit<?> piWork = new ProcessInstanceWorkUnit<>(null, (d) -> picounter.set(counter.get()));
    unit.start();
    // make sure that dummyWork is first added and then piWork
    unit.intercept(dummyWork);
    unit.intercept(piWork);
    unit.end();
    // after execution the pi should be 0 as this is the initial value of counter
    // which will indicate
    // it was invoked before dummyWork that increments it
    assertThat(counter.get()).isEqualTo(1);
    assertThat(picounter.get()).isEqualTo(0);
}
Also used : ManagedUnitOfWork(io.automatiko.engine.services.uow.ManagedUnitOfWork) PassThroughUnitOfWork(io.automatiko.engine.services.uow.PassThroughUnitOfWork) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) CollectingUnitOfWork(io.automatiko.engine.services.uow.CollectingUnitOfWork) ManagedUnitOfWork(io.automatiko.engine.services.uow.ManagedUnitOfWork) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BaseWorkUnit(io.automatiko.engine.services.uow.BaseWorkUnit) ProcessInstanceWorkUnit(io.automatiko.engine.services.uow.ProcessInstanceWorkUnit) Test(org.junit.jupiter.api.Test)

Aggregations

UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)1 BaseWorkUnit (io.automatiko.engine.services.uow.BaseWorkUnit)1 CollectingUnitOfWork (io.automatiko.engine.services.uow.CollectingUnitOfWork)1 ManagedUnitOfWork (io.automatiko.engine.services.uow.ManagedUnitOfWork)1 PassThroughUnitOfWork (io.automatiko.engine.services.uow.PassThroughUnitOfWork)1 ProcessInstanceWorkUnit (io.automatiko.engine.services.uow.ProcessInstanceWorkUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.jupiter.api.Test)1