Search in sources :

Example 1 with SocketAddress

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);
}
Also used : SocketAddress(io.zeebe.transport.SocketAddress) Test(org.junit.Test)

Example 2 with SocketAddress

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();
}
Also used : TypedBatchWriter(io.zeebe.broker.logstreams.processor.TypedBatchWriter) SocketAddress(io.zeebe.transport.SocketAddress)

Example 3 with SocketAddress

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");
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TaskEvent(io.zeebe.client.event.TaskEvent) SocketAddress(io.zeebe.transport.SocketAddress) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 4 with SocketAddress

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();
}
Also used : SocketAddress(io.zeebe.transport.SocketAddress) Test(org.junit.Test)

Example 5 with SocketAddress

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();
}
Also used : TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) TopologyResponse(io.zeebe.client.clustering.impl.TopologyResponse) Test(org.junit.Test) Collectors(java.util.stream.Collectors) BROKER_1_CLIENT_ADDRESS(io.zeebe.broker.it.clustering.ClusteringRule.BROKER_1_CLIENT_ADDRESS) TestUtil.doRepeatedly(io.zeebe.test.util.TestUtil.doRepeatedly) ZeebeClient(io.zeebe.client.ZeebeClient) BrokerPartitionState(io.zeebe.client.clustering.impl.BrokerPartitionState) RuleChain(org.junit.rules.RuleChain) ClientRule(io.zeebe.broker.it.ClientRule) List(java.util.List) Future(java.util.concurrent.Future) SocketAddress(io.zeebe.transport.SocketAddress) Rule(org.junit.Rule) Timeout(org.junit.rules.Timeout) AutoCloseableRule(io.zeebe.test.util.AutoCloseableRule) Before(org.junit.Before) BrokerPartitionState(io.zeebe.client.clustering.impl.BrokerPartitionState) SocketAddress(io.zeebe.transport.SocketAddress) Test(org.junit.Test)

Aggregations

SocketAddress (io.zeebe.transport.SocketAddress)21 Test (org.junit.Test)13 TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)6 TaskEvent (io.zeebe.client.event.TaskEvent)3 DirectBuffer (org.agrona.DirectBuffer)3 TopologyBroker (io.zeebe.broker.clustering.handler.TopologyBroker)2 TypedBatchWriter (io.zeebe.broker.logstreams.processor.TypedBatchWriter)2 Raft (io.zeebe.raft.Raft)2 TestUtil.doRepeatedly (io.zeebe.test.util.TestUtil.doRepeatedly)2 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MutableDirectBuffer (org.agrona.MutableDirectBuffer)2 Before (org.junit.Before)2 Topology (io.zeebe.broker.clustering.handler.Topology)1 Member (io.zeebe.broker.clustering.member.Member)1 ClientRule (io.zeebe.broker.it.ClientRule)1 BROKER_1_CLIENT_ADDRESS (io.zeebe.broker.it.clustering.ClusteringRule.BROKER_1_CLIENT_ADDRESS)1 TypedEvent (io.zeebe.broker.logstreams.processor.TypedEvent)1 TypedStreamEnvironment (io.zeebe.broker.logstreams.processor.TypedStreamEnvironment)1