use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.
the class CompleteTaskTest method shouldCompleteTask.
@Test
public void shouldCompleteTask() {
// given
final TaskEventImpl baseEvent = Events.exampleTask();
brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
final String updatedPayload = "{\"fruit\":\"cherry\"}";
// when
final TaskEvent taskEvent = clientRule.tasks().complete(baseEvent).payload(updatedPayload).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.position()).isEqualTo(baseEvent.getMetadata().getPosition());
assertThat(request.getCommand()).containsOnly(entry("state", "COMPLETE"), entry("lockTime", baseEvent.getLockExpirationTime().toEpochMilli()), entry("lockOwner", baseEvent.getLockOwner()), entry("retries", baseEvent.getRetries()), entry("type", baseEvent.getType()), entry("headers", baseEvent.getHeaders()), entry("customHeaders", baseEvent.getCustomHeaders()), entry("payload", converter.convertToMsgPack(updatedPayload)));
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("COMPLETED");
assertThat(taskEvent.getHeaders()).isEqualTo(baseEvent.getHeaders());
assertThat(taskEvent.getLockExpirationTime()).isEqualTo(baseEvent.getLockExpirationTime());
assertThat(taskEvent.getLockOwner()).isEqualTo(baseEvent.getLockOwner());
assertThat(taskEvent.getRetries()).isEqualTo(baseEvent.getRetries());
assertThat(taskEvent.getType()).isEqualTo(baseEvent.getType());
assertThat(taskEvent.getPayload()).isEqualTo(updatedPayload);
}
use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.
the class FailTaskTest method shouldFailTask.
@Test
public void shouldFailTask() {
// given
final TaskEventImpl baseEvent = Events.exampleTask();
brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "FAIL").respondWith().key(123).event().allOf((r) -> r.getCommand()).put("state", "FAILED").done().register();
// when
final TaskEvent taskEvent = clientRule.tasks().fail(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", "FAIL"), 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("FAILED");
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);
}
use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.
the class ZeebeClientTest method shouldThrottleTopologyRefreshRequestsWhenPartitionLeaderCannotBeDetermined.
@Test
public void shouldThrottleTopologyRefreshRequestsWhenPartitionLeaderCannotBeDetermined() {
// when
final int nonExistingPartition = 999;
final TaskEventImpl taskEvent = new TaskEventImpl("CREATED", new MsgPackConverter());
taskEvent.setPartitionId(nonExistingPartition);
assertThatThrownBy(() -> {
client.tasks().complete(taskEvent).execute();
});
// +2 (one for the extra request when client is started)
final long requestTimeout = Long.parseLong(client.getInitializationProperties().getProperty(ClientProperties.CLIENT_REQUEST_TIMEOUT_SEC));
final long requestTimeoutMs = TimeUnit.SECONDS.toMillis(requestTimeout);
final long expectedMaximumTopologyRequests = (requestTimeoutMs / ClientTopologyManager.MIN_REFRESH_INTERVAL_MILLIS.toMillis()) + 2;
final long actualTopologyRequests = broker.getReceivedControlMessageRequests().stream().filter(r -> r.messageType() == ControlMessageType.REQUEST_TOPOLOGY).count();
assertThat(actualTopologyRequests).isLessThanOrEqualTo(expectedMaximumTopologyRequests);
}
use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.
the class ZeebeClientTest method shouldIncludeCallingFrameInExceptionStacktraceOnAsyncRootCause.
@Test
public void shouldIncludeCallingFrameInExceptionStacktraceOnAsyncRootCause() throws Exception {
// given
final TaskEventImpl baseEvent = Events.exampleTask();
broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(r -> r.key()).event().allOf((r) -> r.getCommand()).put("state", "COMPLETE_REJECTED").done().register();
// when
try {
client.tasks().complete(baseEvent).executeAsync().get();
fail("should throw exception");
} catch (ExecutionException e) {
// then
assertThat(e.getStackTrace()).anySatisfy(frame -> {
assertThat(frame.getClassName()).isEqualTo(this.getClass().getName());
assertThat(frame.getMethodName()).isEqualTo(testContext.getMethodName());
});
}
}
use of io.zeebe.client.event.impl.TaskEventImpl 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");
}
Aggregations