use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class ZeebeClientTopologyTimeoutTest method shouldRetryTopologyRequestAfterTimeout.
@Test
public void shouldRetryTopologyRequestAfterTimeout() {
// given
final int topologyTimeoutSeconds = 1;
broker.onTopologyRequest().doNotRespond();
broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
final TaskEventImpl baseEvent = Events.exampleTask();
final ZeebeClient client = buildClient();
// wait for a hanging topology request
waitUntil(() -> broker.getReceivedControlMessageRequests().stream().filter(r -> r.messageType() == ControlMessageType.REQUEST_TOPOLOGY).count() == 1);
// make topology available
broker.stubTopologyRequest();
// let request time out
clientClock.addTime(Duration.ofSeconds(topologyTimeoutSeconds + 1));
// when making a new request
final TaskEvent response = client.tasks().complete(baseEvent).execute();
// then the topology has been refreshed and the request succeeded
assertThat(response.getState()).isEqualTo("COMPLETED");
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class ClientCommandManagerTest method testRefreshTopologyRequest.
@Test
public void testRefreshTopologyRequest() {
// given
// initial topology has been fetched
waitUntil(() -> broker.getReceivedControlMessageRequests().size() == 1);
stubCreateTaskResponse();
// extend topology
broker.addTopic("other-topic", 0);
// when
final TaskEvent taskEvent = createTaskCmd("other-topic").execute();
// then the client has refreshed its topology
assertThat(taskEvent).isNotNull();
assertTopologyRefreshRequests(2);
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class ClientCommandManagerTest method testRefreshTopologyWhenLeaderIsNotKnown.
@Test
public void testRefreshTopologyWhenLeaderIsNotKnown() {
// given
// initial topology has been fetched
waitUntil(() -> broker.getReceivedControlMessageRequests().size() == 1);
stubCompleteTaskResponse();
// extend topology
broker.addTopic("other-topic", 1);
final TaskEventImpl task = Events.exampleTask();
task.setTopicName("other-topic");
task.setPartitionId(1);
// when
final TaskEvent result = client.tasks().complete(task).execute();
// then the client has refreshed its topology
assertThat(result).isNotNull();
assertTopologyRefreshRequests(2);
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class CreateTaskTest method shouldCreateTaskWithDefaultValues.
@Test
public void shouldCreateTaskWithDefaultValues() {
// given
brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "CREATE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "CREATED").put("headers", new HashMap<>()).put("payload", MsgPackUtil.encodeMsgPack(w -> w.packNil()).byteArray()).done().register();
// when
final TaskEvent taskEvent = clientRule.tasks().create(clientRule.getDefaultTopicName(), "fooType").execute();
// then
assertThat(taskEvent.getMetadata().getKey()).isEqualTo(123L);
assertThat(taskEvent.getMetadata().getTopicName()).isEqualTo(StubBrokerRule.TEST_TOPIC_NAME);
assertThat(taskEvent.getMetadata().getPartitionId()).isEqualTo(StubBrokerRule.TEST_PARTITION_ID);
assertThat(taskEvent.getRetries()).isEqualTo(CreateTaskCommand.DEFAULT_RETRIES);
assertThat(taskEvent.getHeaders()).isEmpty();
assertThat(taskEvent.getPayload()).isEqualTo("null");
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class UpdateTaskRetriesTest method shouldUpdateRetries.
@Test
public void shouldUpdateRetries() {
// given
final TaskEventImpl baseEvent = Events.exampleTask();
brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "UPDATE_RETRIES").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "RETRIES_UPDATED").done().register();
// when
final TaskEvent taskEvent = clientRule.tasks().updateRetries(baseEvent).retries(4).execute();
// then
final ExecuteCommandRequest request = brokerRule.getReceivedCommandRequests().get(0);
assertThat(request.eventType()).isEqualTo(EventType.TASK_EVENT);
assertThat(request.partitionId()).isEqualTo(StubBrokerRule.TEST_PARTITION_ID);
assertThat(request.getCommand()).containsOnly(entry("state", "UPDATE_RETRIES"), entry("lockTime", baseEvent.getLockExpirationTime().toEpochMilli()), entry("lockOwner", baseEvent.getLockOwner()), entry("retries", 4), entry("type", baseEvent.getType()), entry("headers", baseEvent.getHeaders()), entry("customHeaders", baseEvent.getCustomHeaders()), entry("payload", baseEvent.getPayloadMsgPack()));
assertThat(taskEvent.getMetadata().getKey()).isEqualTo(123L);
assertThat(taskEvent.getMetadata().getTopicName()).isEqualTo(StubBrokerRule.TEST_TOPIC_NAME);
assertThat(taskEvent.getMetadata().getPartitionId()).isEqualTo(StubBrokerRule.TEST_PARTITION_ID);
assertThat(taskEvent.getState()).isEqualTo("RETRIES_UPDATED");
assertThat(taskEvent.getHeaders()).isEqualTo(baseEvent.getHeaders());
assertThat(taskEvent.getLockExpirationTime()).isEqualTo(baseEvent.getLockExpirationTime());
assertThat(taskEvent.getLockOwner()).isEqualTo(baseEvent.getLockOwner());
assertThat(taskEvent.getType()).isEqualTo(baseEvent.getType());
assertThat(taskEvent.getPayload()).isEqualTo(baseEvent.getPayload());
assertThat(taskEvent.getRetries()).isEqualTo(4);
}
Aggregations