Search in sources :

Example 31 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class IncidentTest method shouldDeleteStandaloneIncidentIfTaskRetriesIncreased.

@Test
public void shouldDeleteStandaloneIncidentIfTaskRetriesIncreased() {
    // given
    createStandaloneTask();
    failTaskWithNoRetriesLeft();
    // when
    updateTaskRetries();
    // then
    final SubscribedEvent taskEvent = testClient.receiveSingleEvent(taskEvents("FAILED"));
    final SubscribedEvent incidentEvent = testClient.receiveSingleEvent(incidentEvents("DELETED"));
    assertThat(incidentEvent.key()).isGreaterThan(0);
    assertThat(incidentEvent.event()).containsEntry("errorType", ErrorType.TASK_NO_RETRIES.name()).containsEntry("errorMessage", "No more retries left.").containsEntry("bpmnProcessId", "").containsEntry("workflowInstanceKey", -1).containsEntry("activityId", "").containsEntry("activityInstanceKey", -1).containsEntry("taskKey", taskEvent.key());
}
Also used : SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 32 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class IncidentTest method shouldCreateIncidentIfTaskHasNoRetriesLeft.

@Test
public void shouldCreateIncidentIfTaskHasNoRetriesLeft() {
    // given
    testClient.deploy(WORKFLOW_INPUT_MAPPING);
    final long workflowInstanceKey = testClient.createWorkflowInstance("process", PAYLOAD);
    // when
    failTaskWithNoRetriesLeft();
    // then
    final SubscribedEvent activityEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_ACTIVATED"));
    final SubscribedEvent failedEvent = testClient.receiveSingleEvent(taskEvents("FAILED"));
    final SubscribedEvent incidentEvent = testClient.receiveSingleEvent(incidentEvents("CREATED"));
    assertThat(incidentEvent.key()).isGreaterThan(0);
    assertThat(incidentEvent.event()).containsEntry("errorType", ErrorType.TASK_NO_RETRIES.name()).containsEntry("errorMessage", "No more retries left.").containsEntry("failureEventPosition", failedEvent.position()).containsEntry("bpmnProcessId", "process").containsEntry("workflowInstanceKey", workflowInstanceKey).containsEntry("activityId", "failingTask").containsEntry("activityInstanceKey", activityEvent.key()).containsEntry("taskKey", failedEvent.key());
}
Also used : SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 33 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class IncidentTest method updateTaskRetries.

private void updateTaskRetries() {
    final SubscribedEvent taskEvent = testClient.receiveSingleEvent(taskEvents("FAILED"));
    final ExecuteCommandResponse response = apiRule.createCmdRequest().key(taskEvent.key()).eventTypeTask().command().put("state", "UPDATE_RETRIES").put("retries", 1).put("type", "test").put("lockOwner", taskEvent.event().get("lockOwner")).put("headers", taskEvent.event().get("headers")).done().sendAndAwait();
    assertThat(response.getEvent()).containsEntry("state", "RETRIES_UPDATED");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent)

Example 34 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class IncidentTest method shouldResolveIncidentForInvalidResultOnOutputMapping.

@Test
public void shouldResolveIncidentForInvalidResultOnOutputMapping() throws Throwable {
    // given
    testClient.deploy(Bpmn.createExecutableWorkflow("process").startEvent().serviceTask("service", t -> t.taskType("external").input("$.jsonObject", "$").output("$.testAttr", "$")).done());
    final long workflowInstanceKey = testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD);
    // when
    testClient.completeTaskOfType("external", MSGPACK_MAPPER.writeValueAsBytes(JSON_MAPPER.readTree("{'testAttr':'test'}")));
    testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_ACTIVATED"));
    // then incident is created
    final SubscribedEvent failureEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_COMPLETING"));
    final SubscribedEvent incidentEvent = testClient.receiveSingleEvent(incidentEvents("CREATED"));
    // when
    updatePayload(workflowInstanceKey, failureEvent, "{'testAttr':{'obj':'test'}}");
    // then
    final SubscribedEvent followUpEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_COMPLETED"));
    final byte[] result = (byte[]) followUpEvent.event().get(PROP_PAYLOAD);
    assertThat(MSGPACK_MAPPER.readTree(result)).isEqualTo(JSON_MAPPER.readTree("{'obj':'test'}"));
    final SubscribedEvent incidentResolvedEvent = testClient.receiveSingleEvent(incidentEvents("RESOLVED"));
    assertThat(incidentResolvedEvent.key()).isEqualTo(incidentEvent.key());
    assertThat(incidentResolvedEvent.event()).containsEntry("errorType", ErrorType.IO_MAPPING_ERROR.name()).containsEntry("errorMessage", "Processing failed, since mapping will result in a non map object (json object).").containsEntry("bpmnProcessId", "process").containsEntry("workflowInstanceKey", workflowInstanceKey).containsEntry("activityId", "service").containsEntry("activityInstanceKey", followUpEvent.key()).containsEntry("taskKey", -1);
}
Also used : SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 35 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class IncidentTest method shouldResolveIncidentForInAndOutputMappingAndNoTaskCompletePayload.

@Test
public void shouldResolveIncidentForInAndOutputMappingAndNoTaskCompletePayload() throws Throwable {
    // given
    testClient.deploy(Bpmn.createExecutableWorkflow("process").startEvent().serviceTask("service", t -> t.taskType("external").input("$.jsonObject", "$").output("$.testAttr", "$")).done());
    final long workflowInstanceKey = testClient.createWorkflowInstance("process", MSGPACK_PAYLOAD);
    // when
    testClient.completeTaskOfType("external");
    // then incident is created
    final SubscribedEvent failureEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_COMPLETING"));
    final SubscribedEvent incidentEvent = testClient.receiveSingleEvent(incidentEvents("CREATED"));
    // when
    updatePayload(workflowInstanceKey, failureEvent, "{'testAttr':{'obj':'test'}}");
    // then
    final SubscribedEvent followUpEvent = testClient.receiveSingleEvent(workflowInstanceEvents("ACTIVITY_COMPLETED"));
    final byte[] result = (byte[]) followUpEvent.event().get(PROP_PAYLOAD);
    assertThat(MSGPACK_MAPPER.readTree(result)).isEqualTo(JSON_MAPPER.readTree("{'obj':'test'}"));
    final SubscribedEvent incidentResolvedEvent = testClient.receiveSingleEvent(incidentEvents("RESOLVED"));
    assertThat(incidentResolvedEvent.key()).isEqualTo(incidentEvent.key());
    assertThat(incidentResolvedEvent.event()).containsEntry("errorType", ErrorType.IO_MAPPING_ERROR.name()).containsEntry("errorMessage", "Task was completed without an payload - processing of output mapping failed!").containsEntry("bpmnProcessId", "process").containsEntry("workflowInstanceKey", workflowInstanceKey).containsEntry("activityId", "service").containsEntry("activityInstanceKey", followUpEvent.key()).containsEntry("taskKey", -1);
}
Also used : SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Aggregations

SubscribedEvent (io.zeebe.test.broker.protocol.clientapi.SubscribedEvent)57 Test (org.junit.Test)55 ExecuteCommandResponse (io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse)28 EmbeddedBrokerRule (io.zeebe.broker.test.EmbeddedBrokerRule)13 ClientApiRule (io.zeebe.test.broker.protocol.clientapi.ClientApiRule)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 RuleChain (org.junit.rules.RuleChain)13 IOException (java.io.IOException)11 EventType (io.zeebe.protocol.clientapi.EventType)10 TestTopicClient (io.zeebe.test.broker.protocol.clientapi.TestTopicClient)10 HashMap (java.util.HashMap)10 Before (org.junit.Before)10 Bpmn (io.zeebe.model.bpmn.Bpmn)9 WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)9 TestTopicClient.taskEvents (io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents)8 List (java.util.List)7 Map (java.util.Map)7 ErrorType (io.zeebe.broker.incident.data.ErrorType)6 JSON_MAPPER (io.zeebe.broker.test.MsgPackUtil.JSON_MAPPER)6