use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.
the class VerificationTest method testProcessParallelSuccessful.
@Test
public void testProcessParallelSuccessful() throws InterruptedException {
String addPayload = "{}";
given().contentType(ContentType.JSON).accept(ContentType.JSON).body(addPayload).when().post("/parallel").then().statusCode(200).body("id", notNullValue());
long elapsed = 3000;
while (elapsed >= 0) {
elapsed -= 1000;
Thread.sleep(1000);
int size = given().accept(ContentType.JSON).when().get("/parallel").then().statusCode(200).extract().path("$.size()");
if (size == 0) {
break;
}
}
List<DataEvent<?>> received = publisher.events();
assertEquals(5, received.size());
ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) received.stream().filter(pi -> ((ProcessInstanceDataEvent) pi).getData().getState().equals(ProcessInstance.STATE_COMPLETED)).findFirst().get();
assertEquals("fallback name", piEvent.getData().getVariables().get("errorInfo"));
given().accept(ContentType.JSON).when().get("/parallel").then().statusCode(200).body("$.size()", is(0));
}
use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.
the class GraphQLProcessSubscriptionEventPublisher method process.
@Override
public void process(DataEvent<?> event) {
if (processId == null || mapper == null) {
return;
}
if (event instanceof ProcessInstanceDataEvent) {
ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) event;
ProcessInstance<?> instance = piEvent.getData().sourceInstance();
if (instance.process().id().equals(processId)) {
if (instance.status() == ProcessInstance.STATE_COMPLETED) {
completedProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
} else if (instance.status() == ProcessInstance.STATE_ABORTED) {
abortedProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
} else if (instance.status() == ProcessInstance.STATE_ERROR) {
inErrorProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
} else {
changedProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
}
}
}
}
use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.
the class PublishEventTest method assertProcessInstanceEvent.
/*
* Helper methods
*/
protected ProcessInstanceEventBody assertProcessInstanceEvent(DataEvent<?> event, String processId, String processName, Integer state) {
assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
ProcessInstanceEventBody body = ((ProcessInstanceDataEvent) event).getData();
assertThat(body).isNotNull();
assertThat(body.getId()).isNotNull();
assertThat(body.getStartDate()).isNotNull();
if (state == ProcessInstance.STATE_ACTIVE || state == ProcessInstance.STATE_ERROR) {
assertThat(body.getEndDate()).isNull();
} else {
assertThat(body.getEndDate()).isNotNull();
}
assertThat(body.getParentInstanceId()).isNull();
assertThat(body.getRootInstanceId()).isNull();
assertThat(body.getProcessId()).isEqualTo(processId);
assertThat(body.getProcessName()).isEqualTo(processName);
assertThat(body.getState()).isEqualTo(state);
assertThat(event.getSource()).isEqualTo("http://myhost/" + processId);
assertThat(event.getTime()).doesNotContain("[");
return body;
}
use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.
the class MockEventPublisher method waitForNodeEntered.
public boolean waitForNodeEntered(String nodeName, long elapsed) throws InterruptedException {
boolean found = false;
while (elapsed >= 0) {
elapsed -= 1000;
Thread.sleep(1000);
for (DataEvent<?> event : events) {
ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) event;
found = piEvent.getData().getNodeInstances().stream().anyMatch(ni -> ni.getNodeName().equals(nodeName) && ni.getLeaveTime() == null);
if (found) {
break;
}
}
if (found) {
break;
}
}
return found;
}
use of io.automatiko.engine.services.event.ProcessInstanceDataEvent in project automatiko-engine by automatiko-io.
the class MockEventPublisher method waitForNodeCompleted.
public boolean waitForNodeCompleted(String nodeName, long elapsed) throws InterruptedException {
boolean found = false;
while (elapsed >= 0) {
elapsed -= 1000;
Thread.sleep(1000);
for (DataEvent<?> event : events) {
ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) event;
found = piEvent.getData().getNodeInstances().stream().map(ni -> log(ni)).anyMatch(ni -> ni.getNodeName().equals(nodeName) && ni.getLeaveTime() != null);
if (found) {
break;
}
}
if (found) {
break;
}
}
return found;
}
Aggregations