use of io.zeebe.client.event.impl.TaskEventImpl 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.impl.TaskEventImpl in project zeebe by zeebe-io.
the class UpdateTaskRetriesTest method shouldThrowExceptionOnRejection.
@Test
public void shouldThrowExceptionOnRejection() {
// given
final TaskEventImpl baseEvent = Events.exampleTask();
brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "UPDATE_RETRIES").respondWith().key(r -> r.key()).event().allOf((r) -> r.getCommand()).put("state", "UPDATE_RETRIES_REJECTED").done().register();
// then
exception.expect(ClientCommandRejectedException.class);
exception.expectMessage("Command for event with key 79 was rejected by broker (UPDATE_RETRIES_REJECTED)");
// when
clientRule.tasks().updateRetries(baseEvent).retries(5).execute();
}
use of io.zeebe.client.event.impl.TaskEventImpl 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);
}
use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.
the class Events method exampleTask.
public static TaskEventImpl exampleTask() {
final TaskEventImpl baseEvent = new TaskEventImpl("CREATED", new MsgPackConverter());
baseEvent.setHeaders(Maps.newHashMap("defaultHeaderKey", "defaultHeaderVal"));
baseEvent.setCustomHeaders(Maps.newHashMap("customHeaderKey", "customHeaderVal"));
baseEvent.setKey(79);
baseEvent.setLockOwner("foo");
baseEvent.setLockTime(System.currentTimeMillis());
baseEvent.setPartitionId(StubBrokerRule.TEST_PARTITION_ID);
baseEvent.setPayload("{\"key\":\"val\"}");
baseEvent.setRetries(123);
baseEvent.setTopicName(ClientApiRule.DEFAULT_TOPIC_NAME);
baseEvent.setType("taskTypeFoo");
baseEvent.setEventPosition(456);
return baseEvent;
}
use of io.zeebe.client.event.impl.TaskEventImpl in project zeebe by zeebe-io.
the class TaskSubscriber method pollEvents.
public int pollEvents(TaskHandler taskHandler) {
int polledEvents = pollEvents((e) -> {
final TaskEventImpl taskEvent = msgPackMapper.convert(e.getAsMsgPack(), TaskEventImpl.class);
taskEvent.updateMetadata(e.getMetadata());
try {
taskHandler.handle(taskClient, taskEvent);
} catch (Exception handlingException) {
LOGGER.info("An error occurred when handling task " + taskEvent.getMetadata().getKey() + ". Reporting failure to broker.", handlingException);
try {
taskClient.fail(taskEvent).retries(taskEvent.getRetries() - 1).execute();
} catch (Exception failureException) {
LOGGER.info("Could not report failure of task " + taskEvent.getMetadata().getKey() + " to broker. Continuing with next task", failureException);
}
}
});
return polledEvents;
}
Aggregations