use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class CreateDeploymentTest method shouldCreateDeploymentWithMultipleResourcesAndWorkflows.
@Test
public void shouldCreateDeploymentWithMultipleResourcesAndWorkflows() throws IOException {
// given
final WorkflowDefinition singleWorkflow = Bpmn.createExecutableWorkflow("singleProcess").startEvent().done();
final InputStream multipleWorkflowsResource = getClass().getResourceAsStream("/workflows/collaboration.bpmn");
final List<Map<String, Object>> resources = Arrays.asList(deploymentResource(bpmnXml(singleWorkflow), "process1.bpmn"), deploymentResource(StreamUtil.read(multipleWorkflowsResource), "collaboration.bpmn"));
// when
final ExecuteCommandResponse resp = apiRule.createCmdRequest().partitionId(Protocol.SYSTEM_PARTITION).eventType(EventType.DEPLOYMENT_EVENT).command().put(PROP_STATE, "CREATE").put("topicName", ClientApiRule.DEFAULT_TOPIC_NAME).put("resources", resources).done().sendAndAwait();
// then
assertThat(resp.getEvent()).containsEntry(PROP_STATE, "CREATED");
final List<SubscribedEvent> workflowEvents = apiRule.topic().receiveEvents(workflowEvents("CREATED")).limit(3).collect(toList());
assertThat(workflowEvents).extracting(s -> s.event().get(PROP_WORKFLOW_BPMN_PROCESS_ID)).contains("singleProcess", "process1", "process2");
}
use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class CreateDeploymentTest method shouldCreateDeploymentWithMultipleResources.
@Test
public void shouldCreateDeploymentWithMultipleResources() {
// given
final WorkflowDefinition definition1 = Bpmn.createExecutableWorkflow("process1").startEvent().done();
final WorkflowDefinition definition2 = Bpmn.createExecutableWorkflow("process2").startEvent().done();
final List<Map<String, Object>> resources = Arrays.asList(deploymentResource(bpmnXml(definition1), "process1.bpmn"), deploymentResource(bpmnXml(definition2), "process2.bpmn"));
// when
final ExecuteCommandResponse resp = apiRule.createCmdRequest().partitionId(Protocol.SYSTEM_PARTITION).eventType(EventType.DEPLOYMENT_EVENT).command().put(PROP_STATE, "CREATE").put("topicName", ClientApiRule.DEFAULT_TOPIC_NAME).put("resources", resources).done().sendAndAwait();
// then
assertThat(resp.getEvent()).containsEntry(PROP_STATE, "CREATED");
final List<SubscribedEvent> workflowEvents = apiRule.topic().receiveEvents(workflowEvents("CREATED")).limit(2).collect(toList());
assertThat(workflowEvents).extracting(s -> s.event().get(PROP_WORKFLOW_BPMN_PROCESS_ID)).contains("process1", "process2");
}
use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class TopicSubscriptionAcknowledgementTest method shouldResumeAtTailOnLongMaxAckPosition.
@Test
public void shouldResumeAtTailOnLongMaxAckPosition() {
// given
apiRule.createCmdRequest().eventTypeSubscription().command().put("name", SUBSCRIPTION_NAME).put("state", "ACKNOWLEDGE").put("ackPosition", Long.MAX_VALUE).done().sendAndAwait();
closeSubscription();
apiRule.moveMessageStreamToTail();
// when
openSubscription();
// and
final ExecuteCommandResponse response = apiRule.createCmdRequest().eventTypeTask().command().put("state", "CREATE").put("type", "theTaskType").done().sendAndAwait();
final long taskKey = response.key();
// then
final Optional<SubscribedEvent> firstEvent = apiRule.subscribedEvents().findFirst();
assertThat(firstEvent).isPresent();
assertThat(firstEvent.get().key()).isEqualTo(taskKey);
}
use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class FailTaskTest method shouldFailTask.
@Test
public void shouldFailTask() {
// given
client.createTask(TASK_TYPE);
apiRule.openTaskSubscription(TASK_TYPE).await();
final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
// when
final ExecuteCommandResponse response = client.failTask(subscribedEvent.key(), subscribedEvent.event());
// then
final Map<String, Object> expectedEvent = new HashMap<>(subscribedEvent.event());
expectedEvent.put("state", "FAILED");
assertThat(response.getEvent()).containsAllEntriesOf(expectedEvent);
// and the task is published again
final SubscribedEvent republishedEvent = receiveSingleSubscribedEvent();
assertThat(republishedEvent.key()).isEqualTo(subscribedEvent.key());
assertThat(republishedEvent.position()).isNotEqualTo(subscribedEvent.position());
// and the task lifecycle is correct
apiRule.openTopicSubscription("foo", 0).await();
final int expectedTopicEvents = 8;
final List<SubscribedEvent> taskEvents = doRepeatedly(() -> apiRule.moveMessageStreamToHead().subscribedEvents().filter(e -> e.subscriptionType() == SubscriptionType.TOPIC_SUBSCRIPTION).limit(expectedTopicEvents).collect(Collectors.toList())).until(e -> e.size() == expectedTopicEvents);
assertThat(taskEvents).extracting(e -> e.event().get("state")).containsExactly("CREATE", "CREATED", "LOCK", "LOCKED", "FAIL", "FAILED", "LOCK", "LOCKED");
}
use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class TaskUpdateRetriesTest method shouldRejectUpdateRetriesIfRetriesLessThanZero.
@Test
public void shouldRejectUpdateRetriesIfRetriesLessThanZero() {
// given
client.createTask(TASK_TYPE);
apiRule.openTaskSubscription(TASK_TYPE).await();
final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
Map<String, Object> event = subscribedEvent.event();
event.put("retries", 0);
final ExecuteCommandResponse failResponse = client.failTask(subscribedEvent.key(), event);
event = failResponse.getEvent();
event.put("retries", -1);
// when
final ExecuteCommandResponse response = client.updateTaskRetries(subscribedEvent.key(), event);
// then
assertThat(response.getEvent()).containsEntry("state", "UPDATE_RETRIES_REJECTED");
}
Aggregations