use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.
the class CreateTopicStreamProcessorTest method shouldDistributePartitionsRoundRobinWhenCreatingMultipleTopics.
@Test
public void shouldDistributePartitionsRoundRobinWhenCreatingMultipleTopics() {
// given
partitionManager.addMember(SOCKET_ADDRESS1);
partitionManager.addMember(SOCKET_ADDRESS2);
rule.runStreamProcessor(this::buildStreamProcessor);
// creating a first partition
rule.writeEvent(createTopic("foo", 1));
waitUntil(() -> partitionEventsInState(PartitionState.CREATING).count() == 1);
final SocketAddress firstPartitionCreator = partitionManager.getPartitionRequests().get(0).endpoint;
// when creating a second partition
rule.writeEvent(createTopic("bar", 1));
waitUntil(() -> partitionEventsInState(PartitionState.CREATING).count() == 2);
// then round-robin distribution continues
final SocketAddress secondPartitionCreator = partitionManager.getPartitionRequests().get(1).endpoint;
assertThat(secondPartitionCreator).isNotEqualTo(firstPartitionCreator);
}
use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.
the class ExpirePartitionCreationProcessor method writeEvent.
@Override
public long writeEvent(TypedEvent<PartitionEvent> event, TypedStreamWriter writer) {
final PartitionEvent value = event.getValue();
final TypedBatchWriter batchWriter = writer.newBatch().addFollowUpEvent(event.getKey(), value);
if (value.getState() == PartitionState.CREATE_EXPIRED) {
// create a new partition
final SocketAddress nextCreator = creatorStrategy.selectBrokerForNewPartition();
if (nextCreator == null) {
return -1;
}
newEvent.reset();
newEvent.setState(PartitionState.CREATE);
newEvent.setTopicName(value.getTopicName());
newEvent.setId(idGenerator.currentId());
newEvent.setCreator(nextCreator.getHostBuffer(), nextCreator.port());
batchWriter.addNewEvent(newEvent);
}
return batchWriter.write();
}
use of io.zeebe.transport.SocketAddress 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.transport.SocketAddress in project zeebe by zeebe-io.
the class TopologyRequestTest method shouldUpdateClientTopologyOnTopologyRequest.
@Test
public void shouldUpdateClientTopologyOnTopologyRequest() {
// given
final SocketAddress oldLeader = BROKER_1_CLIENT_ADDRESS;
// when
clusteringRule.stopBroker(oldLeader);
// then
zeebeClient.topics().create("foo", 1).execute();
}
use of io.zeebe.transport.SocketAddress in project zeebe by zeebe-io.
the class TopologyRequestTest method shouldUpdateClientTopologyOnAsyncTopologyRequest.
@Test
public void shouldUpdateClientTopologyOnAsyncTopologyRequest() {
// given
final SocketAddress oldLeader = BROKER_1_CLIENT_ADDRESS;
// when
final List<Integer> partitions = clusteringRule.getBrokersLeadingPartitions(oldLeader);
clusteringRule.brokers.remove(oldLeader).close();
doRepeatedly(this::requestTopologyAsync).until(topologyBrokers -> topologyBrokers != null && topologyBrokers.stream().filter(broker -> !broker.getSocketAddress().equals(oldLeader)).flatMap(broker -> broker.getPartitions().stream()).filter(BrokerPartitionState::isLeader).map(BrokerPartitionState::getPartitionId).collect(Collectors.toSet()).containsAll(partitions));
// then
zeebeClient.topics().create("foo", 1).execute();
}
Aggregations