use of io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse in project zeebe by zeebe-io.
the class CompleteTaskTest method shouldRejectCompletionIfTaskNotFound.
@Test
public void shouldRejectCompletionIfTaskNotFound() {
// given
final int key = 123;
final Map<String, Object> event = new HashMap<>();
event.put("type", "foo");
// when
final ExecuteCommandResponse response = completeTask(key, event);
// then
assertThat(response.getEvent()).containsEntry("state", "COMPLETE_REJECTED");
}
use of io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse in project zeebe by zeebe-io.
the class CompleteTaskTest method shouldRejectCompletionIfTaskIsCompleted.
@Test
public void shouldRejectCompletionIfTaskIsCompleted() {
// given
createTask(TASK_TYPE);
apiRule.openTaskSubscription(TASK_TYPE).await();
final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
completeTask(subscribedEvent.key(), subscribedEvent.event());
// when
final ExecuteCommandResponse response = completeTask(subscribedEvent.key(), subscribedEvent.event());
// then
assertThat(response.getEvent()).containsEntry("state", "COMPLETE_REJECTED");
}
use of io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse in project zeebe by zeebe-io.
the class CompleteTaskTest method shouldRejectCompletionIfNotLockOwner.
@Test
public void shouldRejectCompletionIfNotLockOwner() {
// given
final String lockOwner = "kermit";
createTask(TASK_TYPE);
apiRule.createControlMessageRequest().partitionId(apiRule.getDefaultPartitionId()).messageType(ControlMessageType.ADD_TASK_SUBSCRIPTION).data().put("taskType", TASK_TYPE).put("lockDuration", Duration.ofSeconds(30).toMillis()).put("lockOwner", lockOwner).put("credits", 10).done().sendAndAwait();
final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
final Map<String, Object> event = subscribedEvent.event();
event.put("lockOwner", "ms piggy");
// when
final ExecuteCommandResponse response = completeTask(subscribedEvent.key(), event);
// then
assertThat(response.getEvent()).containsEntry("state", "COMPLETE_REJECTED");
}
use of io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldCloseSubscriptionOnTransportChannelClose.
@Test
public void shouldCloseSubscriptionOnTransportChannelClose() throws InterruptedException {
// given
apiRule.openTaskSubscription("foo").await();
// when the transport channel is closed
apiRule.interruptAllChannels();
// then the subscription has been closed, so we can create a new task and lock it for a new subscription
// closing subscriptions happens asynchronously
Thread.sleep(1000L);
final ExecuteCommandResponse response = testClient.createTask("foo");
final ControlMessageResponse subscriptionResponse = apiRule.openTaskSubscription("foo").await();
final int secondSubscriberKey = (int) subscriptionResponse.getData().get("subscriberKey");
final Optional<SubscribedEvent> taskEvent = apiRule.subscribedEvents().filter((s) -> s.subscriptionType() == SubscriptionType.TASK_SUBSCRIPTION && s.key() == response.key()).findFirst();
assertThat(taskEvent).isPresent();
assertThat(taskEvent.get().subscriberKey()).isEqualTo(secondSubscriberKey);
}
use of io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldAddTaskSubscription.
@Test
public void shouldAddTaskSubscription() throws InterruptedException {
// given
apiRule.createControlMessageRequest().messageType(ControlMessageType.ADD_TASK_SUBSCRIPTION).partitionId(apiRule.getDefaultPartitionId()).data().put("taskType", "foo").put("lockDuration", 10000L).put("lockOwner", "bar").put("credits", 5).done().send();
// when
final ExecuteCommandResponse response = testClient.createTask("foo");
// then
final SubscribedEvent taskEvent = testClient.receiveSingleEvent(taskEvents("LOCKED"));
assertThat(taskEvent.key()).isEqualTo(response.key());
assertThat(taskEvent.position()).isGreaterThan(response.position());
assertThat(taskEvent.event()).containsEntry("type", "foo").containsEntry("retries", 3).containsEntry("lockOwner", "bar");
final List<Object> taskStates = testClient.receiveEvents(taskEvents()).limit(4).map(e -> e.event().get("state")).collect(Collectors.toList());
assertThat(taskStates).containsExactly("CREATE", "CREATED", "LOCK", "LOCKED");
}
Aggregations