use of io.zeebe.client.topic.Topic in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldReceiveTasksFromMultiplePartitions.
@Test
public void shouldReceiveTasksFromMultiplePartitions() {
// given
final String topicName = "gyros";
final int numPartitions = 2;
final ZeebeClient client = clientRule.getClient();
client.topics().create(topicName, numPartitions).execute();
final Topics topics = client.topics().getTopics().execute();
final Topic topic = topics.getTopics().stream().filter(t -> t.getName().equals(topicName)).findFirst().get();
final Integer[] partitionIds = topic.getPartitions().stream().mapToInt(p -> p.getId()).boxed().toArray(Integer[]::new);
final String taskType = "foooo";
final RecordingTaskHandler handler = new RecordingTaskHandler();
createTaskOnPartition(client, topicName, partitionIds[0], taskType);
createTaskOnPartition(client, topicName, partitionIds[1], taskType);
// when
client.tasks().newTaskSubscription(topicName).handler(handler).lockOwner("foo").lockTime(Duration.ofSeconds(30)).taskType(taskType).open();
// then
waitUntil(() -> handler.getHandledTasks().size() == 2);
final Integer[] receivedPartitionIds = handler.getHandledTasks().stream().map(t -> t.getMetadata().getPartitionId()).toArray(Integer[]::new);
assertThat(receivedPartitionIds).containsExactlyInAnyOrder(partitionIds);
}
use of io.zeebe.client.topic.Topic in project zeebe by zeebe-io.
the class SubscriptionClusteredTest method shouldOpenSubscriptionGroupForDistributedTopic.
@Test
public void shouldOpenSubscriptionGroupForDistributedTopic() {
// given
final String topicName = "pasta al forno";
final Topic topic = clusteringRule.createTopic(topicName, PARTITION_COUNT);
// when
final Integer[] partitionIds = topic.getPartitions().stream().mapToInt(p -> p.getId()).boxed().toArray(Integer[]::new);
createTaskOnPartition(topicName, partitionIds[0]);
createTaskOnPartition(topicName, partitionIds[1]);
createTaskOnPartition(topicName, partitionIds[2]);
createTaskOnPartition(topicName, partitionIds[3]);
createTaskOnPartition(topicName, partitionIds[4]);
// and
final RecordingEventHandler recordingEventHandler = new RecordingEventHandler();
final List<Integer> receivedPartitionIds = new ArrayList<>();
client.topics().newSubscription(topicName).handler(recordingEventHandler).taskEventHandler(e -> {
if ("CREATE".equals(e.getState())) {
receivedPartitionIds.add(e.getMetadata().getPartitionId());
}
}).startAtHeadOfTopic().name("SubscriptionName").open();
// then
waitUntil(() -> receivedPartitionIds.size() == PARTITION_COUNT);
assertThat(receivedPartitionIds).containsExactlyInAnyOrder(partitionIds);
}
use of io.zeebe.client.topic.Topic in project zeebe by zeebe-io.
the class DeploymentClusteredTest method shouldCreateInstancesOnRestartedBroker.
@Test
public void shouldCreateInstancesOnRestartedBroker() {
// given
final int workCount = PARTITION_COUNT;
final Topic topic = clusteringRule.createTopic("test", PARTITION_COUNT);
clusteringRule.stopBroker(ClusteringRule.BROKER_3_CLIENT_ADDRESS);
client.workflows().deploy("test").addWorkflowModel(WORKFLOW, "workflow.bpmn").execute();
// when
clusteringRule.restartBroker(ClusteringRule.BROKER_3_CLIENT_ADDRESS);
// then create wf instance on each partition
final Integer[] partitionIds = topic.getPartitions().stream().mapToInt(p -> p.getId()).boxed().toArray(Integer[]::new);
for (int partition : partitionIds) {
final WorkflowInstanceEvent workflowInstanceEvent = createWorkflowInstanceOnPartition("test", partition, "process");
assertThat(workflowInstanceEvent.getState()).isEqualTo("WORKFLOW_INSTANCE_CREATED");
}
}
Aggregations