Search in sources :

Example 1 with TestConfigurationFactory

use of io.camunda.zeebe.test.util.TestConfigurationFactory in project zeebe by camunda.

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();
    }
    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;
        });
    }
    dataDirectory = broker.getSystemContext().getBrokerConfiguration().getData().getDirectory();
}
Also used : Broker(io.camunda.zeebe.broker.Broker) TestConfigurationFactory(io.camunda.zeebe.test.util.TestConfigurationFactory) SystemContext(io.camunda.zeebe.broker.system.SystemContext) InputStream(java.io.InputStream) BrokerTopologyManager(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerTopologyManager) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerClient(io.camunda.zeebe.gateway.impl.broker.BrokerClient) BrokerCfg(io.camunda.zeebe.broker.system.configuration.BrokerCfg) EmbeddedGatewayService(io.camunda.zeebe.broker.system.EmbeddedGatewayService) BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)

Example 2 with TestConfigurationFactory

use of io.camunda.zeebe.test.util.TestConfigurationFactory in project zeebe by camunda.

the class GatewayCfgTest method readConfig.

private GatewayCfg readConfig(final String filename) {
    try (final InputStream inputStream = GatewayCfgTest.class.getResourceAsStream(filename)) {
        if (inputStream != null) {
            final GatewayCfg gatewayCfg = new TestConfigurationFactory().create(new Environment(environment), "zeebe.gateway", filename, GatewayCfg.class);
            gatewayCfg.init();
            return gatewayCfg;
        } else {
            throw new AssertionError("Unable to find configuration file: " + filename);
        }
    } catch (final IOException e) {
        throw new AssertionError("Failed to read configuration from file: " + filename, e);
    }
}
Also used : TestConfigurationFactory(io.camunda.zeebe.test.util.TestConfigurationFactory) InputStream(java.io.InputStream) Environment(io.camunda.zeebe.util.Environment) IOException(java.io.IOException)

Example 3 with TestConfigurationFactory

use of io.camunda.zeebe.test.util.TestConfigurationFactory in project zeebe by zeebe-io.

the class TestConfigReader method readConfig.

public static BrokerCfg readConfig(final String name, final Map<String, String> environment) {
    final String configPath = "/system/" + name + ".yaml";
    final Environment environmentVariables = new Environment(environment);
    final BrokerCfg config = new TestConfigurationFactory().create(environmentVariables, "zeebe.broker", configPath, BrokerCfg.class);
    config.init(BROKER_BASE, environmentVariables);
    return config;
}
Also used : TestConfigurationFactory(io.camunda.zeebe.test.util.TestConfigurationFactory) Environment(io.camunda.zeebe.util.Environment)

Example 4 with TestConfigurationFactory

use of io.camunda.zeebe.test.util.TestConfigurationFactory in project zeebe by zeebe-io.

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();
    }
    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;
        });
    }
    dataDirectory = broker.getSystemContext().getBrokerConfiguration().getData().getDirectory();
}
Also used : Broker(io.camunda.zeebe.broker.Broker) TestConfigurationFactory(io.camunda.zeebe.test.util.TestConfigurationFactory) SystemContext(io.camunda.zeebe.broker.system.SystemContext) InputStream(java.io.InputStream) BrokerTopologyManager(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerTopologyManager) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerClient(io.camunda.zeebe.gateway.impl.broker.BrokerClient) BrokerCfg(io.camunda.zeebe.broker.system.configuration.BrokerCfg) EmbeddedGatewayService(io.camunda.zeebe.broker.system.EmbeddedGatewayService) BrokerClusterState(io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)

Example 5 with TestConfigurationFactory

use of io.camunda.zeebe.test.util.TestConfigurationFactory 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)

Aggregations

TestConfigurationFactory (io.camunda.zeebe.test.util.TestConfigurationFactory)9 Environment (io.camunda.zeebe.util.Environment)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Broker (io.camunda.zeebe.broker.Broker)3 SystemContext (io.camunda.zeebe.broker.system.SystemContext)3 BrokerCfg (io.camunda.zeebe.broker.system.configuration.BrokerCfg)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 EmbeddedGatewayService (io.camunda.zeebe.broker.system.EmbeddedGatewayService)2 BrokerClient (io.camunda.zeebe.gateway.impl.broker.BrokerClient)2 BrokerClusterState (io.camunda.zeebe.gateway.impl.broker.cluster.BrokerClusterState)2 BrokerTopologyManager (io.camunda.zeebe.gateway.impl.broker.cluster.BrokerTopologyManager)2