use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class TaskUpdateRetriesTest method shouldRejectUpdateRetriesIfRetriesZero.
@Test
public void shouldRejectUpdateRetriesIfRetriesZero() {
// 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", 0);
// when
final ExecuteCommandResponse response = client.updateTaskRetries(subscribedEvent.key(), event);
// then
assertThat(response.getEvent()).containsEntry("state", "UPDATE_RETRIES_REJECTED");
}
use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class TaskUpdateRetriesTest method shouldUpdateRetries.
@Test
public void shouldUpdateRetries() {
// 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", NEW_RETRIES);
// when
final ExecuteCommandResponse response = client.updateTaskRetries(subscribedEvent.key(), event);
// then
final Map<String, Object> expectedEvent = new HashMap<>(event);
expectedEvent.put("state", "RETRIES_UPDATED");
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 = 10;
final List<SubscribedEvent> taskEvents = doRepeatedly(() -> apiRule.moveMessageStreamToHead().subscribedEvents().filter(e -> e.subscriptionType() == SubscriptionType.TOPIC_SUBSCRIPTION && e.eventType() == EventType.TASK_EVENT).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", "UPDATE_RETRIES", "RETRIES_UPDATED", "LOCK", "LOCKED");
}
use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class CreateDeploymentTest method shouldCreateWorkflowOnAllPartitions.
@Test
public void shouldCreateWorkflowOnAllPartitions() {
// given
final int partitions = 3;
apiRule.createTopic("test", partitions);
final List<Integer> partitionIds = apiRule.getPartitionIds("test");
// when
apiRule.topic().deploy("test", WORKFLOW);
// then
final List<Long> workflowKeys = new ArrayList<>();
partitionIds.forEach(partitionId -> {
final SubscribedEvent event = apiRule.topic(partitionId).receiveSingleEvent(workflowEvents("CREATED"));
workflowKeys.add(event.key());
});
assertThat(workflowKeys).hasSize(partitions).containsOnly(workflowKeys.get(0));
}
use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class CreateDeploymentTest method shouldAssignWorkflowVersionsPerTopic.
@Test
public void shouldAssignWorkflowVersionsPerTopic() {
// given
apiRule.createTopic("foo", 1);
apiRule.createTopic("bar", 1);
// when
apiRule.topic().deploy("foo", WORKFLOW);
apiRule.topic().deploy("bar", WORKFLOW);
// then
final SubscribedEvent eventFoo = apiRule.topic(apiRule.getSinglePartitionId("foo")).receiveSingleEvent(workflowEvents("CREATED"));
final SubscribedEvent eventBar = apiRule.topic(apiRule.getSinglePartitionId("bar")).receiveSingleEvent(workflowEvents("CREATED"));
assertThat(eventFoo.event().get("version")).isEqualTo(1);
assertThat(eventBar.event().get("version")).isEqualTo(1);
}
use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.
the class CreateDeploymentTest method shouldCreateDeploymentResourceWithMultipleWorkflows.
@Test
public void shouldCreateDeploymentResourceWithMultipleWorkflows() throws IOException {
// given
final InputStream resourceAsStream = getClass().getResourceAsStream("/workflows/collaboration.bpmn");
// when
final ExecuteCommandResponse resp = apiRule.topic().deployWithResponse(ClientApiRule.DEFAULT_TOPIC_NAME, StreamUtil.read(resourceAsStream), ResourceType.BPMN_XML.name(), "collaboration.bpmn");
// 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");
}
Aggregations