use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class ZeebeClientTest method shouldDistributeNewEntitiesRoundRobin.
@Test
public void shouldDistributeNewEntitiesRoundRobin() {
// given
final String topic = "foo";
broker.clearTopology();
broker.addSystemTopic();
broker.addTopic(topic, 0);
broker.addTopic(topic, 1);
stubTaskResponse();
// when
final TaskEvent task1 = client.tasks().create(topic, "bar").execute();
final TaskEvent task2 = client.tasks().create(topic, "bar").execute();
final TaskEvent task3 = client.tasks().create(topic, "bar").execute();
final TaskEvent task4 = client.tasks().create(topic, "bar").execute();
// then
assertThat(Arrays.asList(task1, task2, task3, task4)).extracting("metadata.partitionId").containsExactlyInAnyOrder(0, 1, 0, 1);
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class CreateTaskTest method shouldCreateTask.
@Test
public void shouldCreateTask() {
// given
brokerRule.onExecuteCommandRequest(EventType.TASK_EVENT, "CREATE").respondWith().key(123).position(456).event().allOf((r) -> r.getCommand()).put("state", "CREATED").put("lockTime", Protocol.INSTANT_NULL_VALUE).put("lockOwner", "").done().register();
final String payload = "{\"foo\":\"bar\"}";
// when
final TaskEvent taskEvent = clientRule.tasks().create(clientRule.getDefaultTopicName(), "fooType").retries(3).addCustomHeader("beverage", "apple juice").payload(payload).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(ExecuteCommandRequestEncoder.positionNullValue());
assertThat(request.getCommand()).containsOnly(entry("state", "CREATE"), entry("retries", 3), entry("type", "fooType"), entry("headers", new HashMap<>()), entry("customHeaders", Maps.newHashMap("beverage", "apple juice")), entry("lockTime", Protocol.INSTANT_NULL_VALUE), entry("payload", converter.convertToMsgPack(payload)));
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.getMetadata().getPosition()).isEqualTo(456);
assertThat(taskEvent.getState()).isEqualTo("CREATED");
assertThat(taskEvent.getHeaders()).isEmpty();
assertThat(taskEvent.getCustomHeaders()).containsOnly(entry("beverage", "apple juice"));
assertThat(taskEvent.getLockExpirationTime()).isNull();
assertThat(taskEvent.getLockOwner()).isEmpty();
assertThat(taskEvent.getRetries()).isEqualTo(3);
assertThat(taskEvent.getType()).isEqualTo("fooType");
assertThat(taskEvent.getPayload()).isEqualTo(payload);
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class CreateTopicClusteredTest method shouldChooseNewLeaderForCreatedTopicAfterLeaderDies.
@Test
public void shouldChooseNewLeaderForCreatedTopicAfterLeaderDies() {
// given
final int partitionsCount = 1;
clusteringRule.createTopic("foo", partitionsCount);
final TaskEvent taskEvent = client.tasks().create("foo", "bar").execute();
final int partitionId = taskEvent.getMetadata().getPartitionId();
final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(partitionId);
final SocketAddress currentLeaderAddress = leaderForPartition.getSocketAddress();
// when
clusteringRule.stopBroker(currentLeaderAddress);
// then
final TopologyBroker newLeader = clusteringRule.getLeaderForPartition(partitionId);
assertThat(newLeader.getSocketAddress()).isNotEqualTo(leaderForPartition.getSocketAddress());
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class BrokerRecoveryTest method shouldCompleteStandaloneTaskAfterRestart.
@Test
public void shouldCompleteStandaloneTaskAfterRestart() {
// given
clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockOwner("test").lockTime(Duration.ofSeconds(5)).handler(recordingTaskHandler).open();
waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
// when
restartBroker();
final TaskEvent task = recordingTaskHandler.getHandledTasks().get(0);
clientRule.tasks().complete(task).execute();
// then
waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
}
use of io.zeebe.client.event.TaskEvent in project zeebe by zeebe-io.
the class BrokerRecoveryTest method shouldReceiveLockExpiredTasksAfterRestart.
@Test
public void shouldReceiveLockExpiredTasksAfterRestart() {
// given
clientRule.tasks().create(clientRule.getDefaultTopic(), "foo").execute();
final RecordingTaskHandler recordingTaskHandler = new RecordingTaskHandler();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofSeconds(5)).lockOwner("test").handler(recordingTaskHandler).open();
waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
// when
restartBroker();
// wait until stream processor and scheduler process the lock task event which is not re-processed on recovery
doRepeatedly(() -> {
// retriggers lock expiration check in broker
brokerRule.getClock().addTime(Duration.ofSeconds(60));
return null;
}).until(t -> eventRecorder.hasTaskEvent(taskEvent("LOCK_EXPIRED")));
recordingTaskHandler.clear();
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopic()).taskType("foo").lockTime(Duration.ofMinutes(10L)).lockOwner("test").handler(recordingTaskHandler).open();
// then
waitUntil(() -> !recordingTaskHandler.getHandledTasks().isEmpty());
final TaskEvent task = recordingTaskHandler.getHandledTasks().get(0);
clientRule.tasks().complete(task).execute();
waitUntil(() -> eventRecorder.hasTaskEvent(taskEvent("COMPLETED")));
}
Aggregations