Search in sources :

Example 36 with ExecuteCommandResponse

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");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 37 with ExecuteCommandResponse

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");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 38 with ExecuteCommandResponse

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");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 39 with ExecuteCommandResponse

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);
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) TaskSubscription(io.zeebe.broker.task.processor.TaskSubscription) TestTopicClient(io.zeebe.test.broker.protocol.clientapi.TestTopicClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) HashMap(java.util.HashMap) EmbeddedBrokerRule(io.zeebe.broker.test.EmbeddedBrokerRule) ControlMessageRequestBuilder(io.zeebe.test.broker.protocol.clientapi.ControlMessageRequestBuilder) TestTopicClient.taskEvents(io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents) ErrorCode(io.zeebe.protocol.clientapi.ErrorCode) SocketAddress(io.zeebe.transport.SocketAddress) SocketChannel(java.nio.channels.SocketChannel) Map(java.util.Map) Before(org.junit.Before) StandardSocketOptions(java.net.StandardSocketOptions) ControlMessageResponse(io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SubscriptionType(io.zeebe.protocol.clientapi.SubscriptionType) ErrorResponse(io.zeebe.test.broker.protocol.clientapi.ErrorResponse) RuleChain(org.junit.rules.RuleChain) List(java.util.List) StringUtil(io.zeebe.util.StringUtil) Rule(org.junit.Rule) Optional(java.util.Optional) ClientApiRule(io.zeebe.test.broker.protocol.clientapi.ClientApiRule) ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) ControlMessageResponse(io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 40 with ExecuteCommandResponse

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");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) TaskSubscription(io.zeebe.broker.task.processor.TaskSubscription) TestTopicClient(io.zeebe.test.broker.protocol.clientapi.TestTopicClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) HashMap(java.util.HashMap) EmbeddedBrokerRule(io.zeebe.broker.test.EmbeddedBrokerRule) ControlMessageRequestBuilder(io.zeebe.test.broker.protocol.clientapi.ControlMessageRequestBuilder) TestTopicClient.taskEvents(io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents) ErrorCode(io.zeebe.protocol.clientapi.ErrorCode) SocketAddress(io.zeebe.transport.SocketAddress) SocketChannel(java.nio.channels.SocketChannel) Map(java.util.Map) Before(org.junit.Before) StandardSocketOptions(java.net.StandardSocketOptions) ControlMessageResponse(io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SubscriptionType(io.zeebe.protocol.clientapi.SubscriptionType) ErrorResponse(io.zeebe.test.broker.protocol.clientapi.ErrorResponse) RuleChain(org.junit.rules.RuleChain) List(java.util.List) StringUtil(io.zeebe.util.StringUtil) Rule(org.junit.Rule) Optional(java.util.Optional) ClientApiRule(io.zeebe.test.broker.protocol.clientapi.ClientApiRule) ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Aggregations

ExecuteCommandResponse (io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse)47 Test (org.junit.Test)41 SubscribedEvent (io.zeebe.test.broker.protocol.clientapi.SubscribedEvent)22 HashMap (java.util.HashMap)13 Map (java.util.Map)9 List (java.util.List)8 EmbeddedBrokerRule (io.zeebe.broker.test.EmbeddedBrokerRule)7 ClientApiRule (io.zeebe.test.broker.protocol.clientapi.ClientApiRule)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 Rule (org.junit.Rule)7 RuleChain (org.junit.rules.RuleChain)7 WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)6 IOException (java.io.IOException)5 EventType (io.zeebe.protocol.clientapi.EventType)4 SubscriptionType (io.zeebe.protocol.clientapi.SubscriptionType)4 ControlMessageResponse (io.zeebe.test.broker.protocol.clientapi.ControlMessageResponse)4 TestTopicClient (io.zeebe.test.broker.protocol.clientapi.TestTopicClient)4 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)4 File (java.io.File)4 Collectors (java.util.stream.Collectors)4