Search in sources :

Example 16 with ExecuteCommandResponse

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

the class TaskUpdateRetriesTest method shouldRejectUpdateRetriesIfRetriesLessThanZero.

@Test
public void shouldRejectUpdateRetriesIfRetriesLessThanZero() {
    // 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", -1);
    // when
    final ExecuteCommandResponse response = client.updateTaskRetries(subscribedEvent.key(), event);
    // then
    assertThat(response.getEvent()).containsEntry("state", "UPDATE_RETRIES_REJECTED");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 17 with ExecuteCommandResponse

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

Example 18 with ExecuteCommandResponse

use of io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse 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");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) TestTopicClient(io.zeebe.test.broker.protocol.clientapi.TestTopicClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) HashMap(java.util.HashMap) Test(org.junit.Test) EmbeddedBrokerRule(io.zeebe.broker.test.EmbeddedBrokerRule) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) Collectors(java.util.stream.Collectors) SubscriptionType(io.zeebe.protocol.clientapi.SubscriptionType) RuleChain(org.junit.rules.RuleChain) List(java.util.List) Rule(org.junit.Rule) EventType(io.zeebe.protocol.clientapi.EventType) Map(java.util.Map) Before(org.junit.Before) ClientApiRule(io.zeebe.test.broker.protocol.clientapi.ClientApiRule) ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) HashMap(java.util.HashMap) SubscribedEvent(io.zeebe.test.broker.protocol.clientapi.SubscribedEvent) Test(org.junit.Test)

Example 19 with ExecuteCommandResponse

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

the class TaskUpdateRetriesTest method shouldRejectUpdateRetriesIfTaskNotFound.

@Test
public void shouldRejectUpdateRetriesIfTaskNotFound() {
    // given
    final Map<String, Object> event = new HashMap<>();
    event.put("retries", NEW_RETRIES);
    event.put("type", TASK_TYPE);
    // when
    final ExecuteCommandResponse response = client.updateTaskRetries(123, event);
    // then
    assertThat(response.getEvent()).containsEntry("state", "UPDATE_RETRIES_REJECTED");
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 20 with ExecuteCommandResponse

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

the class CreateTopicTest method shouldNotCreateTopicWithNegativePartitions.

@Test
public void shouldNotCreateTopicWithNegativePartitions() {
    // given
    final String topicName = "newTopic";
    final int numberOfPartitions = -100;
    // when
    final ExecuteCommandResponse response = apiRule.createTopic(topicName, numberOfPartitions);
    // then
    assertThat(response.getEvent()).containsExactly(entry("state", "CREATE_REJECTED"), entry("name", topicName), entry("partitions", numberOfPartitions));
}
Also used : ExecuteCommandResponse(io.zeebe.test.broker.protocol.clientapi.ExecuteCommandResponse) 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