Search in sources :

Example 51 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class TaskSubscriptionTest method shouldNotPublishTaskWithoutRetries.

@Test
public void shouldNotPublishTaskWithoutRetries() throws InterruptedException {
    // given
    final String taskType = "foo";
    apiRule.openTaskSubscription(taskType).await();
    testClient.createTask(taskType);
    waitUntil(() -> apiRule.numSubscribedEventsAvailable() == 1);
    final SubscribedEvent task = apiRule.subscribedEvents().findFirst().get();
    // when
    final Map<String, Object> event = new HashMap<>(task.event());
    event.put("retries", 0);
    testClient.failTask(task.key(), event);
    // then
    Thread.sleep(500);
    assertThat(apiRule.numSubscribedEventsAvailable()).isEqualTo(0);
}
Also used : HashMap(java.util.HashMap) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 52 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class TaskLockExpirationTest method shouldNotExpireLockIfTaskFailed.

@Test
public void shouldNotExpireLockIfTaskFailed() {
    // given
    brokerRule.getClock().pinCurrentTime();
    final Duration lockTime = Duration.ofSeconds(60);
    final String taskType = "taskType";
    createTask(taskType);
    apiRule.openTaskSubscription(apiRule.getDefaultPartitionId(), taskType, lockTime.toMillis()).await();
    // => task is locked
    final SubscribedEvent lockedTask = apiRule.subscribedEvents().findFirst().get();
    final Map<String, Object> event = new HashMap<>(lockedTask.event());
    event.put("retries", 0);
    failTask(lockedTask.key(), event);
    // when
    brokerRule.getClock().addTime(lockTime.plus(Duration.ofSeconds(1)));
    // then
    assertNoMoreTaskReceived();
}
Also used : HashMap(java.util.HashMap) Duration(java.time.Duration) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 53 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class FailTaskTest method shouldRejectFailIfNotLockOwner.

@Test
public void shouldRejectFailIfNotLockOwner() {
    // given
    final String lockOwner = "peter";
    client.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", "jan");
    // when
    final ExecuteCommandResponse response = client.failTask(subscribedEvent.key(), event);
    // then
    assertThat(response.getEvent()).containsEntry("state", "FAIL_REJECTED");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 54 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent 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");
}
Also used : 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 55 with SubscribedEvent

use of io.zeebe.test.broker.protocol.clientapi.SubscribedEvent in project zeebe by zeebe-io.

the class FailTaskTest method shouldRejectFailIfTaskCompleted.

@Test
public void shouldRejectFailIfTaskCompleted() {
    // given
    client.createTask(TASK_TYPE);
    apiRule.openTaskSubscription(TASK_TYPE).await();
    final SubscribedEvent subscribedEvent = receiveSingleSubscribedEvent();
    client.completeTask(subscribedEvent.key(), subscribedEvent.event());
    // when
    final ExecuteCommandResponse response = client.failTask(subscribedEvent.key(), subscribedEvent.event());
    // then
    assertThat(response.getEvent()).containsEntry("state", "FAIL_REJECTED");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Aggregations

SubscribedEvent (io.zeebe.test.broker.protocol.clientapi.SubscribedEvent)57 Test (org.junit.Test)55 ExecuteCommandResponse (io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse)28 EmbeddedBrokerRule (io.zeebe.broker.test.EmbeddedBrokerRule)13 ClientApiRule (io.zeebe.test.broker.protocol.clientapi.ClientApiRule)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 RuleChain (org.junit.rules.RuleChain)13 IOException (java.io.IOException)11 EventType (io.zeebe.protocol.clientapi.EventType)10 TestTopicClient (io.zeebe.test.broker.protocol.clientapi.TestTopicClient)10 HashMap (java.util.HashMap)10 Before (org.junit.Before)10 Bpmn (io.zeebe.model.bpmn.Bpmn)9 WorkflowDefinition (io.zeebe.model.bpmn.instance.WorkflowDefinition)9 TestTopicClient.taskEvents (io.zeebe.test.broker.protocol.clientapi.TestTopicClient.taskEvents)8 List (java.util.List)7 Map (java.util.Map)7 ErrorType (io.zeebe.broker.incident.data.ErrorType)6 JSON_MAPPER (io.zeebe.broker.test.MsgPackUtil.JSON_MAPPER)6