use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class IdentityProviderAwareProcessListenerTest method testSetUser.
@Test
public void testSetUser() {
final IdentityProvider identityProvider = mock(IdentityProvider.class);
final String userId = "userId";
when(identityProvider.getName()).thenReturn(userId);
when(environment.get("IdentityProvider")).thenReturn(identityProvider);
final WorkflowProcessInstance processInstance = mock(WorkflowProcessInstance.class);
final HashMap<String, Object> metaData = new HashMap<>();
when(processInstance.getMetaData()).thenReturn(metaData);
final ProcessStartedEvent event = new ProcessStartedEventImpl(processInstance, mock(KieRuntime.class));
listener.beforeProcessStarted(event);
assertEquals(userId, metaData.get("OwnerId"));
verify(processInstance).setVariable("initiator", userId);
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testContinueTimerWithMisfire.
@Test(timeout = 25000)
public void testContinueTimerWithMisfire() throws Exception {
// RHBPMS-4729
System.setProperty("org.quartz.properties", "quartz-db-short-misfire.properties");
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 2);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
timerExporations.add(event.getProcessInstance().getId());
}
};
// No special configuration for TimerService in order to test RuntimeManager default
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/TimerStart2.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
countDownListener.waitTillCompleted();
manager.disposeRuntimeEngine(runtime);
manager.close();
System.out.println("==== manager.close() ====");
countDownListener.reset(3);
// Simulate interval between shutdown and start so the Trigger is older than (now - misfireThreshold)
Thread.sleep(5000);
// ---- restart ----
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/TimerStart2.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, true);
countDownListener.waitTillCompleted(4000);
assertEquals(5, timerExporations.size());
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class TimerUpdateTest method updateTimerLongerDelayTest.
@Test(timeout = 30000)
public void updateTimerLongerDelayTest() {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_NAME, 1);
// delay is set for 5s
setProcessScenario(TIMER_FILE);
kieSession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
kieSession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
Assertions.assertThat(list).isEmpty();
long id = kieSession.startProcess(PROCESS_NAME).getId();
long startTime = System.currentTimeMillis();
Assertions.assertThat(list).isNotEmpty();
// set delay to 8s
kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, 8));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime - 8000);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(500);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class TimerUpdateTest method updateTimerSubprocessLongerDelayTest.
@Test(timeout = 30000)
public void updateTimerSubprocessLongerDelayTest() {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_SUBPROCESS_NAME, 1);
// delay is set for 5s
setProcessScenario(TIMER_SUBPROCESS_FILE);
kieSession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
kieSession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (TIMER_SUBPROCESS_NAME.equals(event.getNodeInstance().getNodeName())) {
System.setProperty(TIMER_FIRED_TEXT, "");
System.setProperty(TIMER_FIRED_TIME_PROP, String.valueOf(System.currentTimeMillis()));
}
}
});
Assertions.assertThat(list).isEmpty();
long id = kieSession.startProcess(PROCESS_SUBPROCESS_NAME).getId();
long startTime = System.currentTimeMillis();
Assertions.assertThat(list).isNotEmpty();
// set delay to 8s
kieSession.execute(new UpdateTimerCommand(id, TIMER_SUBPROCESS_NAME, 8));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime - 8000);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(500);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class TimerUpdateTest method updateTimerBeforeDelayTest.
@Test(timeout = 30000)
public void updateTimerBeforeDelayTest() {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_NAME, 1);
// delay is set for 5s
setProcessScenario(TIMER_FILE);
kieSession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
kieSession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
Assertions.assertThat(list).isEmpty();
long id = kieSession.startProcess(PROCESS_NAME).getId();
long startTime = System.currentTimeMillis();
Assertions.assertThat(list).isNotEmpty();
// set delay on time that passed -> expected that timer fired immediately
kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, -5));
countDownListener.waitTillCompleted();
Assertions.assertThat(timerHasFired()).isTrue();
long firedTime = timerFiredTime();
long timeDifference = Math.abs(firedTime - startTime);
logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
Assertions.assertThat(timeDifference).isLessThan(500);
Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
Aggregations