Search in sources :

Example 1 with BaseWorkUnit

use of io.automatiko.engine.services.uow.BaseWorkUnit 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)

Example 2 with BaseWorkUnit

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

the class DefaultUnitOfWorkManagerTest method testUnitOfWorkStartEnd.

@Test
public void testUnitOfWorkStartEnd() {
    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);
    BaseWorkUnit dummyWork = new BaseWorkUnit(counter, (d) -> ((AtomicInteger) d).incrementAndGet());
    unit.start();
    unit.intercept(dummyWork);
    unit.end();
    assertThat(counter.get()).isEqualTo(1);
}
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) Test(org.junit.jupiter.api.Test)

Example 3 with BaseWorkUnit

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

the class DefaultUnitOfWorkManagerTest method testUnitOfWorkStartAbort.

@Test
public void testUnitOfWorkStartAbort() {
    UnitOfWork unit = unitOfWorkManager.newUnitOfWork();
    assertThat(unit).isNotNull().isInstanceOf(ManagedUnitOfWork.class);
    final AtomicInteger counter = new AtomicInteger(0);
    assertThat(counter.get()).isEqualTo(0);
    BaseWorkUnit dummyWork = new BaseWorkUnit(counter, (d) -> ((AtomicInteger) d).incrementAndGet());
    unit.start();
    unit.intercept(dummyWork);
    unit.abort();
    assertThat(counter.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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BaseWorkUnit(io.automatiko.engine.services.uow.BaseWorkUnit) Test(org.junit.jupiter.api.Test)

Aggregations

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