use of io.zeebe.client.clustering.impl.TopologyBroker in project zeebe by zeebe-io.
the class CreateTopicClusteredTest method shouldCompleteTaskAfterNewLeaderWasChosen.
@Test
public void shouldCompleteTaskAfterNewLeaderWasChosen() throws Exception {
// 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());
final CompletableFuture<TaskEvent> taskCompleted = new CompletableFuture<>();
client.tasks().newTaskSubscription("foo").handler((taskClient, lockedEvent) -> {
final TaskEvent completedTask = taskClient.complete(lockedEvent).execute();
taskCompleted.complete(completedTask);
}).taskType("bar").lockOwner("owner").lockTime(5000).open();
waitUntil(() -> taskCompleted.isDone());
assertThat(taskCompleted).isCompleted();
final TaskEvent completedTask = taskCompleted.get();
assertThat(completedTask.getState()).isEqualTo("COMPLETED");
}
use of io.zeebe.client.clustering.impl.TopologyBroker in project zeebe by zeebe-io.
the class GossipDifferentNodeJoinTest method shouldRemoveLeaderFromCluster.
@Test
public void shouldRemoveLeaderFromCluster() {
// given
final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(0);
final SocketAddress[] otherBrokers = clusteringRule.getOtherBrokers(leaderForPartition.getSocketAddress());
// when
clusteringRule.stopBroker(leaderForPartition.getSocketAddress());
// then
final List<SocketAddress> topologyBrokers = clusteringRule.getBrokersInCluster();
assertThat(topologyBrokers).containsExactlyInAnyOrder(otherBrokers);
}
use of io.zeebe.client.clustering.impl.TopologyBroker in project zeebe by zeebe-io.
the class TaskEventClusteredTest method shouldCreateTaskWhenFollowerUnavailable.
@Test
public void shouldCreateTaskWhenFollowerUnavailable() {
// given
final ZeebeClient client = clientRule.getClient();
final String topicName = "foo";
clusteringRule.createTopic(topicName, 1);
final Topics topics = client.topics().getTopics().execute();
final Topic topic = topics.getTopics().stream().filter(t -> topicName.equals(t.getName())).findFirst().get();
final TopologyBroker leader = clusteringRule.getLeaderForPartition(topic.getPartitions().get(0).getId());
// choosing a new leader in a raft group where the previously leading broker is no longer available
clusteringRule.stopBroker(leader.getSocketAddress());
// when
final TaskEvent taskEvent = client.tasks().create(topicName, "bar").execute();
// then
assertThat(taskEvent.getState()).isEqualTo("CREATED");
}
use of io.zeebe.client.clustering.impl.TopologyBroker in project zeebe by zeebe-io.
the class BrokerLeaderChangeTest method shouldChangeLeaderAfterLeaderDies.
@Test
public void shouldChangeLeaderAfterLeaderDies() {
// given
clusteringRule.createTopic(clientRule.getDefaultTopic(), 2);
final TopologyBroker leaderForPartition = clusteringRule.getLeaderForPartition(1);
final SocketAddress leaderAddress = leaderForPartition.getSocketAddress();
final TaskEvent taskEvent = taskClient.create(clientRule.getDefaultTopic(), TASK_TYPE).execute();
// when
clusteringRule.stopBroker(leaderAddress);
final TaskCompleter taskCompleter = new TaskCompleter(taskEvent);
// then
taskCompleter.waitForTaskCompletion();
taskCompleter.close();
}
use of io.zeebe.client.clustering.impl.TopologyBroker in project zeebe by zeebe-io.
the class BrokerRestartTest method shouldCreateUniquePartitionIdsAfterRestart.
@Test
public void shouldCreateUniquePartitionIdsAfterRestart() {
// given
final ZeebeClient client = clientRule.getClient();
client.topics().create("foo", 2).execute();
restartBroker();
// when
client.topics().create("bar", 2).execute();
// then
final TopologyResponse topology = client.requestTopology().execute();
final List<TopologyBroker> brokers = topology.getBrokers();
assertThat(brokers).hasSize(1);
final TopologyBroker topologyBroker = brokers.get(0);
final List<BrokerPartitionState> partitions = topologyBroker.getPartitions();
// default partition + system partition + 4 partitions we create here
assertThat(partitions).hasSize(6);
assertThat(partitions).extracting("partitionId").doesNotHaveDuplicates();
}
Aggregations