use of io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldNoLongerLockTasksAfterRemoval.
@Test
public void shouldNoLongerLockTasksAfterRemoval() throws InterruptedException {
// given
final String taskType = "foo";
final ControlMessageResponse openResponse = apiRule.openTaskSubscription(taskType).await();
final int subscriberKey = (int) openResponse.getData().get("subscriberKey");
apiRule.closeTaskSubscription(subscriberKey).await();
// when
testClient.createTask(taskType);
// then
apiRule.openTopicSubscription("test", 0).await();
Thread.sleep(500L);
final int eventsAvailable = apiRule.numSubscribedEventsAvailable();
final List<SubscribedEvent> receivedEvents = apiRule.subscribedEvents().limit(eventsAvailable).collect(Collectors.toList());
assertThat(receivedEvents).hasSize(2);
assertThat(receivedEvents).allMatch(e -> e.subscriptionType() == SubscriptionType.TOPIC_SUBSCRIPTION);
assertThat(receivedEvents).extracting("event").extracting("state").containsExactly("CREATE", // no more LOCK etc.
"CREATED");
}
use of io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse 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.ControlMessageResponse in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldIncreaseSubscriptionCredits.
@Test
public void shouldIncreaseSubscriptionCredits() throws InterruptedException {
// given
final ControlMessageResponse response = apiRule.createControlMessageRequest().messageType(ControlMessageType.ADD_TASK_SUBSCRIPTION).partitionId(apiRule.getDefaultPartitionId()).data().put("taskType", "foo").put("lockDuration", 1000L).put("lockOwner", "bar").put("credits", 2).done().sendAndAwait();
assertThat(response.getData().get("subscriberKey")).isEqualTo(0);
testClient.createTask("foo");
testClient.createTask("foo");
waitUntil(() -> apiRule.numSubscribedEventsAvailable() == 2);
testClient.createTask("foo");
testClient.createTask("foo");
// when
apiRule.createControlMessageRequest().messageType(ControlMessageType.INCREASE_TASK_SUBSCRIPTION_CREDITS).partitionId(apiRule.getDefaultPartitionId()).data().put("subscriberKey", 0).put("credits", 2).put("partitionId", apiRule.getDefaultPartitionId()).done().send();
// then
waitUntil(() -> apiRule.numSubscribedEventsAvailable() == 4);
}
use of io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldRemoveTaskSubscription.
@Test
public void shouldRemoveTaskSubscription() {
// given
final ControlMessageResponse openResponse = apiRule.openTaskSubscription("foo").await();
final int subscriberKey = (int) openResponse.getData().get("subscriberKey");
// when
final ControlMessageResponse closeResponse = apiRule.createControlMessageRequest().messageType(ControlMessageType.REMOVE_TASK_SUBSCRIPTION).partitionId(apiRule.getDefaultPartitionId()).data().put("subscriberKey", subscriberKey).done().send().await();
assertThat(closeResponse.getData()).containsEntry("subscriberKey", subscriberKey);
}
use of io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse in project zeebe by zeebe-io.
the class FailTaskTest method shouldRejectFailIfTaskAlreadyFailed.
@Test
public void shouldRejectFailIfTaskAlreadyFailed() {
// given
client.createTask(TASK_TYPE);
final ControlMessageResponse subscriptionResponse = apiRule.openTaskSubscription(TASK_TYPE).await();
final int subscriberKey = (int) subscriptionResponse.getData().get("subscriberKey");
final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
apiRule.closeTaskSubscription(subscriberKey).await();
client.failTask(subscribedEvent.key(), subscribedEvent.event());
// when
final ExecuteCommandResponse response = client.failTask(subscribedEvent.key(), subscribedEvent.event());
// then
assertThat(response.getEvent()).containsEntry("state", "FAIL_REJECTED");
}
Aggregations