Search in sources :

Example 1 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class ExclusiveGatewayTest method shouldEvaluateConditionOnFlow.

@Test
public void shouldEvaluateConditionOnFlow() {
    final WorkflowDefinition workflowDefinition = Bpmn.createExecutableWorkflow("workflow").startEvent().exclusiveGateway().sequenceFlow(s -> s.condition("$.foo < 5")).endEvent("a").sequenceFlow(s -> s.defaultFlow()).endEvent("b").done();
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(workflowDefinition, "workflow.bpmn").execute();
    // when
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("workflow").payload("{\"foo\":3}").execute();
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_COMPLETED")));
    final WorkflowInstanceEvent endEvent = eventRecorder.getSingleWorkflowInstanceEvent(wfInstanceEvent("END_EVENT_OCCURRED"));
    assertThat(endEvent.getActivityId()).isEqualTo("a");
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition)

Example 2 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class ExclusiveGatewayTest method shouldExecuteWorkflowWithLoop.

@Test
public void shouldExecuteWorkflowWithLoop() {
    // given
    final WorkflowDefinition workflowDefinition = Bpmn.createExecutableWorkflow("workflow").startEvent().serviceTask("inc", t -> t.taskType("inc")).exclusiveGateway().sequenceFlow(s -> s.condition("$.count > 5")).endEvent().sequenceFlow("back", s -> s.defaultFlow()).joinWith("inc").done();
    workflowClient.deploy(clientRule.getDefaultTopic()).addWorkflowModel(workflowDefinition, "workflow.bpmn").execute();
    // when
    workflowClient.create(clientRule.getDefaultTopic()).bpmnProcessId("workflow").payload("{\"count\":0}").execute();
    taskClient.newTaskSubscription(clientRule.getDefaultTopic()).lockTime(Duration.ofSeconds(5)).lockOwner("test").taskType("inc").handler((c, task) -> {
        final String payload = task.getPayload();
        final int i = payload.indexOf(":");
        final int count = Integer.valueOf(payload.substring(i + 1, i + 2));
        c.complete(task).payload("{\"count\":" + (count + 1) + "}").execute();
    }).open();
    // then
    waitUntil(() -> eventRecorder.hasWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_COMPLETED")));
    final WorkflowInstanceEvent event = eventRecorder.getSingleWorkflowInstanceEvent(wfInstanceEvent("WORKFLOW_INSTANCE_COMPLETED"));
    assertThat(event.getPayload()).isEqualTo("{\"count\":6}");
}
Also used : TasksClient(io.zeebe.client.TasksClient) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) WorkflowsClient(io.zeebe.client.WorkflowsClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.zeebe.model.bpmn.Bpmn) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) TopicEventRecorder(io.zeebe.broker.it.util.TopicEventRecorder) RuleChain(org.junit.rules.RuleChain) ClientRule(io.zeebe.broker.it.ClientRule) TopicEventRecorder.wfInstanceEvent(io.zeebe.broker.it.util.TopicEventRecorder.wfInstanceEvent) Duration(java.time.Duration) EmbeddedBrokerRule(io.zeebe.broker.it.EmbeddedBrokerRule) org.junit(org.junit) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition) WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) WorkflowDefinition(io.zeebe.model.bpmn.instance.WorkflowDefinition)

Example 3 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class BrokerRestartTest method shouldResolveFailedIncidentAfterRestart.

@Test
public void shouldResolveFailedIncidentAfterRestart() {
    // given
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(WORKFLOW_INCIDENT, "incident.bpmn").execute();
    clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("CREATED")));
    final WorkflowInstanceEvent activityInstance = eventRecorder.getSingleWorkflowInstanceEvent(TopicEventRecorder.wfInstanceEvent("ACTIVITY_READY"));
    clientRule.workflows().updatePayload(activityInstance).payload("{\"x\":\"y\"}").execute();
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("RESOLVE_FAILED")));
    // when
    restartBroker();
    clientRule.workflows().updatePayload(activityInstance).payload("{\"foo\":\"bar\"}").execute();
    // then
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("RESOLVED")));
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("CREATED")));
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) Test(org.junit.Test)

Example 4 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class BrokerRestartTest method shouldResolveIncidentAfterRestart.

@Test
public void shouldResolveIncidentAfterRestart() {
    // given
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(WORKFLOW_INCIDENT, "incident.bpmn").execute();
    clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").execute();
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("CREATED")));
    final WorkflowInstanceEvent activityInstance = eventRecorder.getSingleWorkflowInstanceEvent(TopicEventRecorder.wfInstanceEvent("ACTIVITY_READY"));
    // when
    restartBroker();
    clientRule.workflows().updatePayload(activityInstance).payload("{\"foo\":\"bar\"}").execute();
    // then
    waitUntil(() -> eventRecorder.hasIncidentEvent(incidentEvent("RESOLVED")));
    waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("CREATED")));
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) Test(org.junit.Test)

Example 5 with WorkflowInstanceEvent

use of io.zeebe.client.event.WorkflowInstanceEvent in project zeebe by zeebe-io.

the class BrokerRestartTest method shouldDeployNewWorkflowVersionAfterRestart.

@Test
// FIXME: https://github.com/zeebe-io/zeebe/issues/567
@Category(io.zeebe.UnstableTest.class)
public void shouldDeployNewWorkflowVersionAfterRestart() {
    // given
    clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(WORKFLOW, "workflow.bpmn").execute();
    // when
    restartBroker();
    final DeploymentEvent deploymentResult = clientRule.workflows().deploy(clientRule.getDefaultTopic()).addWorkflowModel(WORKFLOW, "workflow.bpmn").execute();
    // then
    assertThat(deploymentResult.getDeployedWorkflows().get(0).getVersion()).isEqualTo(2);
    final WorkflowInstanceEvent workflowInstanceV1 = clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").version(1).execute();
    final WorkflowInstanceEvent workflowInstanceV2 = clientRule.workflows().create(clientRule.getDefaultTopic()).bpmnProcessId("process").latestVersion().execute();
    // then
    assertThat(workflowInstanceV1.getVersion()).isEqualTo(1);
    assertThat(workflowInstanceV2.getVersion()).isEqualTo(2);
}
Also used : WorkflowInstanceEvent(io.zeebe.client.event.WorkflowInstanceEvent) DeploymentEvent(io.zeebe.client.event.DeploymentEvent) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

WorkflowInstanceEvent (io.zeebe.client.event.WorkflowInstanceEvent)31 Test (org.junit.Test)14 ClientRule (io.zeebe.broker.it.ClientRule)7 EmbeddedBrokerRule (io.zeebe.broker.it.EmbeddedBrokerRule)7 TopicEventRecorder (io.zeebe.broker.it.util.TopicEventRecorder)7 Bpmn (io.zeebe.model.bpmn.Bpmn)7 WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)7 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)7 Duration (java.time.Duration)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 RuleChain (org.junit.rules.RuleChain)7 RecordingTaskHandler (io.zeebe.broker.it.util.RecordingTaskHandler)6 WorkflowsClient (io.zeebe.client.WorkflowsClient)6 TaskEvent (io.zeebe.client.event.TaskEvent)6 ExpectedException (org.junit.rules.ExpectedException)6 TopicEventRecorder.wfInstanceEvent (io.zeebe.broker.it.util.TopicEventRecorder.wfInstanceEvent)5 org.junit (org.junit)5 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)4 DeploymentEvent (io.zeebe.client.event.DeploymentEvent)4 TasksClient (io.zeebe.client.TasksClient)3