use of org.kie.kogito.uow.UnitOfWork in project kogito-runtimes by kiegroup.
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);
verify(listener).onBeforeStartEvent(any());
verify(listener, never()).onAfterEndEvent(any());
verify(listener).onAfterAbortEvent(any());
}
use of org.kie.kogito.uow.UnitOfWork in project kogito-runtimes by kiegroup.
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);
}
use of org.kie.kogito.uow.UnitOfWork in project kogito-runtimes by kiegroup.
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);
verify(listener).onBeforeStartEvent(any());
verify(listener).onAfterEndEvent(any());
verify(listener, never()).onAfterAbortEvent(any());
}
use of org.kie.kogito.uow.UnitOfWork in project kogito-runtimes by kiegroup.
the class DefaultUnitOfWorkManagerTest method testFallbackUnitOfWork.
@Test
public void testFallbackUnitOfWork() {
UnitOfWork unit = unitOfWorkManager.currentUnitOfWork();
assertThat(unit).isNotNull().isInstanceOf(PassThroughUnitOfWork.class);
}
use of org.kie.kogito.uow.UnitOfWork in project kogito-runtimes by kiegroup.
the class DefaultUnitOfWorkManagerTest method testUnitOfWorkAddWorkOnNotStarted.
@Test
public void testUnitOfWorkAddWorkOnNotStarted() {
UnitOfWork unit = unitOfWorkManager.newUnitOfWork();
assertThat(unit).isNotNull().isInstanceOf(ManagedUnitOfWork.class);
final AtomicInteger counter = new AtomicInteger(0);
assertThat(counter.get()).isEqualTo(0);
WorkUnit<AtomicInteger> dummyWork = WorkUnit.create(counter, (d) -> d.incrementAndGet());
assertThrows(IllegalStateException.class, () -> unit.intercept(dummyWork), "Cannot intercept on not started unit");
verify(listener, never()).onBeforeStartEvent(any());
verify(listener, never()).onAfterEndEvent(any());
verify(listener, never()).onAfterAbortEvent(any());
}
Aggregations