Search in sources :

Example 21 with Broker

use of io.camunda.zeebe.broker.Broker in project zeebe by camunda-cloud.

the class ReaderCloseTest method shouldDeleteCompactedSegmentsFilesAfterLeaderChange.

// Regression test for https://github.com/camunda/zeebe/issues/7767
@Test
public void shouldDeleteCompactedSegmentsFilesAfterLeaderChange() throws IOException {
    // given
    fillSegments();
    final var leaderId = clusteringRule.getLeaderForPartition(1).getNodeId();
    final var followerId = clusteringRule.getOtherBrokerObjects(leaderId).stream().findAny().orElseThrow().getConfig().getCluster().getNodeId();
    clusteringRule.forceClusterToHaveNewLeader(followerId);
    // because of https://github.com/camunda/zeebe/issues/8329
    // we need to add another record so we can do a snapshot
    clientRule.getClient().newPublishMessageCommand().messageName("test").correlationKey("test").send();
    // when
    clusteringRule.triggerAndWaitForSnapshots();
    // then
    for (final Broker broker : clusteringRule.getBrokers()) {
        assertThatFilesOfDeletedSegmentsDoesNotExist(broker);
    }
    assertThat(leaderId).isNotEqualTo(clusteringRule.getLeaderForPartition(1).getNodeId());
}
Also used : Broker(io.camunda.zeebe.broker.Broker) Test(org.junit.Test)

Example 22 with Broker

use of io.camunda.zeebe.broker.Broker in project zeebe by camunda-cloud.

the class EmbeddedBrokerRule method startBroker.

public void startBroker(final PartitionListener... listeners) {
    if (brokerCfg == null) {
        try (final InputStream configStream = configSupplier.get()) {
            if (configStream == null) {
                brokerCfg = new BrokerCfg();
            } else {
                brokerCfg = new TestConfigurationFactory().create(null, "zeebe.broker", configStream, BrokerCfg.class);
            }
            configureBroker(brokerCfg);
        } catch (final IOException e) {
            throw new RuntimeException("Unable to open configuration", e);
        }
    }
    systemContext = new SystemContext(brokerCfg, newTemporaryFolder.getAbsolutePath(), controlledActorClock);
    systemContext.getScheduler().start();
    final var additionalListeners = new ArrayList<>(Arrays.asList(listeners));
    final CountDownLatch latch = new CountDownLatch(brokerCfg.getCluster().getPartitionsCount());
    additionalListeners.add(new LeaderPartitionListener(latch));
    broker = new Broker(systemContext, springBrokerBridge, additionalListeners);
    broker.start().join();
    try {
        latch.await(INSTALL_TIMEOUT, INSTALL_TIMEOUT_UNIT);
    } catch (final InterruptedException e) {
        LOG.info("Broker was not started in 15 seconds", e);
        Thread.currentThread().interrupt();
    }
    if (brokerCfg.getGateway().isEnable()) {
        try (final var client = ZeebeClient.newClientBuilder().gatewayAddress(NetUtil.toSocketAddressString(getGatewayAddress())).usePlaintext().build()) {
            Awaitility.await("until we have a complete topology").untilAsserted(() -> {
                final var topology = client.newTopologyRequest().send().join();
                TopologyAssert.assertThat(topology).isComplete(brokerCfg.getCluster().getClusterSize(), brokerCfg.getCluster().getPartitionsCount()).isHealthy();
            });
        }
    }
    dataDirectory = broker.getSystemContext().getBrokerConfiguration().getData().getDirectory();
}
Also used : BrokerCfg(io.camunda.zeebe.broker.system.configuration.BrokerCfg) Broker(io.camunda.zeebe.broker.Broker) TestConfigurationFactory(io.camunda.zeebe.test.util.TestConfigurationFactory) SystemContext(io.camunda.zeebe.broker.system.SystemContext) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 23 with Broker

use of io.camunda.zeebe.broker.Broker in project zeebe by camunda-cloud.

the class HealthMonitoringTest method shouldReportUnhealthyWhenRaftInactive.

@Test
public void shouldReportUnhealthyWhenRaftInactive() {
    // given
    final Broker leader = embeddedBrokerRule.getBroker();
    /* timeouts are selected generously as at the time of this implementation there is a
     * 1 minute cycle to update the state
     */
    await("Broker is healthy").atMost(Duration.ofMinutes(2)).until(() -> {
        embeddedBrokerRule.getClock().addTime(Duration.ofMinutes(1));
        return isBrokerHealthy();
    });
    // when
    final var raftPartition = (RaftPartition) leader.getBrokerContext().getPartitionManager().getPartitionGroup().getPartition(PartitionId.from(PartitionManagerImpl.GROUP_NAME, START_PARTITION_ID));
    raftPartition.getServer().stop();
    // then
    /* timeouts are selected generously as at the time of this implementation there is a
     * 1 minute cycle to update the state
     */
    waitAtMost(Duration.ofMinutes(2)).until(() -> {
        embeddedBrokerRule.getClock().addTime(Duration.ofMinutes(1));
        return !isBrokerHealthy();
    });
}
Also used : Broker(io.camunda.zeebe.broker.Broker) RaftPartition(io.atomix.raft.partition.RaftPartition) Test(org.junit.Test)

Example 24 with Broker

use of io.camunda.zeebe.broker.Broker in project zeebe by zeebe-io.

the class EmbeddedBrokerRule method startBroker.

public void startBroker() {
    systemContext = new SystemContext(brokerCfg, newTemporaryFolder.getAbsolutePath(), controlledActorClock);
    systemContext.getScheduler().start();
    final CountDownLatch latch = new CountDownLatch(brokerCfg.getCluster().getPartitionsCount());
    broker = new Broker(systemContext, springBrokerBridge, Collections.singletonList(new LeaderPartitionListener(latch)));
    broker.start().join();
    try {
        final boolean hasLeaderPartition = latch.await(timeout.toMillis(), TimeUnit.MILLISECONDS);
        assertThat(hasLeaderPartition).describedAs("Expected the broker to have a leader of the partition within %s", timeout).isTrue();
    } catch (final InterruptedException e) {
        LOG.info("Timeout. Broker was not started within {}", timeout, e);
        Thread.currentThread().interrupt();
    }
    final EmbeddedGatewayService embeddedGatewayService = broker.getBrokerContext().getEmbeddedGatewayService();
    if (embeddedGatewayService != null) {
        final BrokerClient brokerClient = embeddedGatewayService.get().getBrokerClient();
        waitUntil(() -> {
            final BrokerTopologyManager topologyManager = brokerClient.getTopologyManager();
            final BrokerClusterState topology = topologyManager.getTopology();
            return topology != null && topology.getLeaderForPartition(1) >= 0;
        });
    }
}
Also used : Broker(io.camunda.zeebe.broker.Broker) EmbeddedGatewayService(io.camunda.zeebe.broker.system.EmbeddedGatewayService) SystemContext(io.camunda.zeebe.broker.system.SystemContext) BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState) BrokerTopologyManager(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerTopologyManager) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerClient(io.camunda.zeebe.gateway.impl.broker.BrokerClient)

Example 25 with Broker

use of io.camunda.zeebe.broker.Broker in project zeebe by zeebe-io.

the class ClusteringRule method stepDown.

public void stepDown(final Broker broker, final int partitionId) {
    final var atomix = broker.getBrokerContext().getClusterServices();
    final MemberId nodeId = atomix.getMembershipService().getLocalMember().id();
    final var raftPartition = broker.getBrokerContext().getPartitionManager().getPartitionGroup().getPartitions().stream().filter(partition -> partition.members().contains(nodeId)).filter(partition -> partition.id().id() == partitionId).map(RaftPartition.class::cast).findFirst().orElseThrow();
    raftPartition.getServer().stepDown().join();
}
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) MemberId(io.atomix.cluster.MemberId) RaftPartition(io.atomix.raft.partition.RaftPartition)

Aggregations

Broker (io.camunda.zeebe.broker.Broker)42 Test (org.junit.Test)18 SystemContext (io.camunda.zeebe.broker.system.SystemContext)15 InetSocketAddress (java.net.InetSocketAddress)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 BrokerCfg (io.camunda.zeebe.broker.system.configuration.BrokerCfg)12 RaftPartition (io.atomix.raft.partition.RaftPartition)9 LogStream (io.camunda.zeebe.logstreams.log.LogStream)9 UncheckedExecutionException (io.camunda.zeebe.util.exception.UncheckedExecutionException)9 File (java.io.File)9 Duration (java.time.Duration)9 ExecutionException (java.util.concurrent.ExecutionException)9 TimeUnit (java.util.concurrent.TimeUnit)9 Collectors (java.util.stream.Collectors)9 Awaitility (org.awaitility.Awaitility)9 AtomixCluster (io.atomix.cluster.AtomixCluster)6 AtomixClusterBuilder (io.atomix.cluster.AtomixClusterBuilder)6 ClusterConfig (io.atomix.cluster.ClusterConfig)6 MemberId (io.atomix.cluster.MemberId)6 BootstrapDiscoveryProvider (io.atomix.cluster.discovery.BootstrapDiscoveryProvider)6