Search in sources :

Example 1 with BrokerInfo

use of io.camunda.zeebe.client.api.response.BrokerInfo in project zeebe-test-container by camunda-community-hub.

the class ClusterWithGatewayExampleTest method shouldStartCluster.

@Test
@Timeout(value = 15, unit = TimeUnit.MINUTES)
void shouldStartCluster() {
    // given
    Startables.deepStart(brokers).join();
    gatewayContainer.start();
    // when
    final Topology topology;
    try (final ZeebeClient client = newZeebeClient(gatewayContainer)) {
        topology = client.newTopologyRequest().send().join(5, TimeUnit.SECONDS);
    }
    // then
    final List<BrokerInfo> brokers = topology.getBrokers();
    Assertions.assertThat(brokers).as("the topology contains all the brokers, advertising the right address").hasSize(3).extracting(BrokerInfo::getAddress).containsExactlyInAnyOrder(brokerZeroContainer.getInternalCommandAddress(), brokerOneContainer.getInternalCommandAddress(), brokerTwoContainer.getInternalCommandAddress());
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 2 with BrokerInfo

use of io.camunda.zeebe.client.api.response.BrokerInfo in project zeebe-test-container by camunda-community-hub.

the class ZeebeClusterSingleNodeExampleTest method shouldConnectToZeebe.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void shouldConnectToZeebe() {
    // given
    final Topology topology;
    // when
    try (final ZeebeClient client = cluster.newClientBuilder().build()) {
        topology = client.newTopologyRequest().send().join(5, TimeUnit.SECONDS);
    }
    // then
    final List<BrokerInfo> brokers = topology.getBrokers();
    Assertions.assertThat(brokers).as("the topology contains all the brokers, advertising the expected address").hasSize(1).extracting(BrokerInfo::getAddress).containsExactlyInAnyOrder(cluster.getBrokers().get(0).getInternalCommandAddress());
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 3 with BrokerInfo

use of io.camunda.zeebe.client.api.response.BrokerInfo in project zeebe-test-container by camunda-community-hub.

the class ZeebeClusterWithEmbeddedGatewaysExampleTest method shouldStartCluster.

@Test
@Timeout(value = 15, unit = TimeUnit.MINUTES)
void shouldStartCluster() {
    // given
    final Topology topology;
    // when
    try (final ZeebeClient client = cluster.newClientBuilder().build()) {
        topology = client.newTopologyRequest().send().join(5, TimeUnit.SECONDS);
    }
    // then
    final List<BrokerInfo> brokers = topology.getBrokers();
    Assertions.assertThat(brokers).as("the topology contains all the brokers, advertising the expected address").hasSize(2).extracting(BrokerInfo::getAddress).containsExactlyInAnyOrder(cluster.getBrokers().get(0).getInternalCommandAddress(), cluster.getBrokers().get(1).getInternalCommandAddress());
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 4 with BrokerInfo

use of io.camunda.zeebe.client.api.response.BrokerInfo in project zeebe-test-container by camunda-community-hub.

the class ZeebeTopologyWaitStrategy method buildPartitionsMap.

private Map<Integer, Partition> buildPartitionsMap(final Topology topology) {
    final Map<Integer, Partition> partitions = new HashMap<>();
    for (final BrokerInfo broker : topology.getBrokers()) {
        final int nodeId = broker.getNodeId();
        for (final PartitionInfo partitionInfo : broker.getPartitions()) {
            final int partitionId = partitionInfo.getPartitionId();
            partitions.putIfAbsent(partitionId, new Partition());
            final Partition partition = partitions.get(partitionId);
            if (partitionInfo.isLeader()) {
                partition.leaderIds.add(nodeId);
            } else {
                partition.followerIds.add(nodeId);
            }
        }
    }
    return partitions;
}
Also used : HashMap(java.util.HashMap) PartitionInfo(io.camunda.zeebe.client.api.response.PartitionInfo) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo)

Example 5 with BrokerInfo

use of io.camunda.zeebe.client.api.response.BrokerInfo in project zeebe by camunda.

the class ClusteringRule method hasPartitionsWithReplicationFactor.

private boolean hasPartitionsWithReplicationFactor(final List<BrokerInfo> brokers, final int partitionCount, final int replicationFactor) {
    final AtomicLong leaders = new AtomicLong();
    final AtomicLong followers = new AtomicLong();
    brokers.stream().flatMap(b -> b.getPartitions().stream()).forEach(p -> {
        if (p.isLeader()) {
            leaders.getAndIncrement();
        } else {
            followers.getAndIncrement();
        }
    });
    return leaders.get() >= partitionCount && followers.get() >= partitionCount * (replicationFactor - 1);
}
Also used : DEBUG_EXPORTER(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.DEBUG_EXPORTER) START_PARTITION_ID(io.camunda.zeebe.protocol.Protocol.START_PARTITION_ID) Address(io.atomix.utils.net.Address) AutoCloseableRule(io.camunda.zeebe.test.util.AutoCloseableRule) EmbeddedBrokerRule.assignSocketAddresses(io.camunda.zeebe.broker.test.EmbeddedBrokerRule.assignSocketAddresses) TimeoutException(java.util.concurrent.TimeoutException) Gateway(io.camunda.zeebe.gateway.Gateway) UncheckedExecutionException(io.camunda.zeebe.util.exception.UncheckedExecutionException) Duration(java.time.Duration) Map(java.util.Map) ClusterCfg(io.camunda.zeebe.gateway.impl.configuration.ClusterCfg) LangUtil(org.agrona.LangUtil) SocketBindingCfg(io.camunda.zeebe.broker.system.configuration.SocketBindingCfg) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService) Path(java.nio.file.Path) EmbeddedBrokerConfigurator.setCluster(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.setCluster) ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) ProcessInstanceCreationRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceCreationRecord) BrokerAdminService(io.camunda.zeebe.broker.system.management.BrokerAdminService) PartitionManagerImpl(io.camunda.zeebe.broker.partitioning.PartitionManagerImpl) Predicate(java.util.function.Predicate) SystemContext(io.camunda.zeebe.broker.system.SystemContext) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Set(java.util.Set) Description(org.junit.runner.Description) DISABLE_EMBEDDED_GATEWAY(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.DISABLE_EMBEDDED_GATEWAY) RecordingExporterTestWatcher(io.camunda.zeebe.test.util.record.RecordingExporterTestWatcher) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) SwimMembershipProtocol(io.atomix.cluster.protocol.SwimMembershipProtocol) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ExternalResource(org.junit.rules.ExternalResource) NetworkCfg(io.camunda.zeebe.broker.system.configuration.NetworkCfg) SnapshotId(io.camunda.zeebe.snapshots.SnapshotId) BootstrapDiscoveryProvider(io.atomix.cluster.discovery.BootstrapDiscoveryProvider) Broker(io.camunda.zeebe.broker.Broker) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Optional(java.util.Optional) Awaitility(org.awaitility.Awaitility) IntStream(java.util.stream.IntStream) Statement(org.junit.runners.model.Statement) AtomixClusterBuilder(io.atomix.cluster.AtomixClusterBuilder) PartitionStatus(io.camunda.zeebe.broker.system.management.PartitionStatus) EmbeddedBrokerConfigurator.setInitialContactPoints(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.setInitialContactPoints) ActorFuture(io.camunda.zeebe.util.sched.future.ActorFuture) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) SpringBrokerBridge(io.camunda.zeebe.broker.SpringBrokerBridge) FileBasedSnapshotMetadata(io.camunda.zeebe.snapshots.impl.FileBasedSnapshotMetadata) PartitionInfo(io.camunda.zeebe.client.api.response.PartitionInfo) RaftPartition(io.atomix.raft.partition.RaftPartition) MemberId(io.atomix.cluster.MemberId) BrokerResponse(io.camunda.zeebe.gateway.impl.broker.response.BrokerResponse) BrokerContext(io.camunda.zeebe.broker.bootstrap.BrokerContext) SocketUtil(io.camunda.zeebe.test.util.socket.SocketUtil) LOG(io.camunda.zeebe.broker.Broker.LOG) Topology(io.camunda.zeebe.client.api.response.Topology) ExporterDirectorContext(io.camunda.zeebe.broker.exporter.stream.ExporterDirectorContext) ClusterConfig(io.atomix.cluster.ClusterConfig) BrokerCfg(io.camunda.zeebe.broker.system.configuration.BrokerCfg) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) Files(java.nio.file.Files) AtomixCluster(io.atomix.cluster.AtomixCluster) NetUtil(io.netty.util.NetUtil) IOException(java.io.IOException) ZeebeClientBuilder(io.camunda.zeebe.client.ZeebeClientBuilder) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) PartitionListener(io.camunda.zeebe.broker.PartitionListener) LogStream(io.camunda.zeebe.logstreams.log.LogStream) Paths(java.nio.file.Paths) QueryService(io.camunda.zeebe.engine.state.QueryService) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) CompletableActorFuture(io.camunda.zeebe.util.sched.future.CompletableActorFuture) NettyUnicastService(io.atomix.cluster.messaging.impl.NettyUnicastService) TEST_RECORDER(io.camunda.zeebe.broker.test.EmbeddedBrokerConfigurator.TEST_RECORDER) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

BrokerInfo (io.camunda.zeebe.client.api.response.BrokerInfo)52 Test (org.junit.Test)39 Topology (io.camunda.zeebe.client.api.response.Topology)29 PartitionInfo (io.camunda.zeebe.client.api.response.PartitionInfo)16 ZeebeClient (io.camunda.zeebe.client.ZeebeClient)9 ActivatedJob (io.camunda.zeebe.client.api.response.ActivatedJob)6 InetSocketAddress (java.net.InetSocketAddress)6 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)5 Test (org.junit.jupiter.api.Test)5 AtomixCluster (io.atomix.cluster.AtomixCluster)3 AtomixClusterBuilder (io.atomix.cluster.AtomixClusterBuilder)3 ClusterConfig (io.atomix.cluster.ClusterConfig)3 MemberId (io.atomix.cluster.MemberId)3 BootstrapDiscoveryProvider (io.atomix.cluster.discovery.BootstrapDiscoveryProvider)3 NettyMessagingService (io.atomix.cluster.messaging.impl.NettyMessagingService)3 NettyUnicastService (io.atomix.cluster.messaging.impl.NettyUnicastService)3 SwimMembershipProtocol (io.atomix.cluster.protocol.SwimMembershipProtocol)3 RaftPartition (io.atomix.raft.partition.RaftPartition)3 Address (io.atomix.utils.net.Address)3