Search in sources :

Example 6 with UnitOfWork

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());
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Example 7 with UnitOfWork

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);
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Example 8 with UnitOfWork

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());
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Example 9 with UnitOfWork

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);
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) Test(org.junit.jupiter.api.Test)

Example 10 with UnitOfWork

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());
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Aggregations

UnitOfWork (org.kie.kogito.uow.UnitOfWork)22 Test (org.junit.jupiter.api.Test)20 HashMap (java.util.HashMap)14 Application (org.kie.kogito.Application)14 Model (org.kie.kogito.Model)14 Processes (org.kie.kogito.process.Processes)14 ProcessInstanceDataEvent (org.kie.kogito.event.process.ProcessInstanceDataEvent)11 ProcessInstanceEventBody (org.kie.kogito.event.process.ProcessInstanceEventBody)10 DataEvent (org.kie.kogito.event.DataEvent)9 UserTaskInstanceDataEvent (org.kie.kogito.event.process.UserTaskInstanceDataEvent)9 VariableInstanceDataEvent (org.kie.kogito.event.process.VariableInstanceDataEvent)9 List (java.util.List)8 ArrayList (java.util.ArrayList)7 Person (org.kie.kogito.codegen.data.Person)6 WorkItem (org.kie.kogito.process.WorkItem)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)3 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)2 VariableInstanceEventBody (org.kie.kogito.event.process.VariableInstanceEventBody)2 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)2