Search in sources :

Example 1 with ZeebeContainer

use of io.zeebe.containers.ZeebeContainer in project zeebe-test-container by camunda-community-hub.

the class ClusterWithEmbeddedGatewaysExampleTest method getConfiguredClusterBroker.

/**
 * Will configure the broker in {@code brokers} at index {@code index} for a basic cluster that
 * contains all {@code brokers}. Note that depending on the machine on which you're running, the
 * containers may be quite slow, so make sure to provide them enough cores/memory.
 *
 * @param index the index of the broker to configure and return in {@code brokers}
 * @param brokers all the brokers part of the cluster
 * @return the broker at index {@code index} in {@code brokers}, configured for clustering
 */
private ZeebeContainer getConfiguredClusterBroker(final int index, final List<ZeebeContainer> brokers) {
    final int clusterSize = brokers.size();
    final String initialContactPoints = brokers.stream().map(ZeebeBrokerNode::getInternalClusterAddress).collect(Collectors.joining(","));
    final ZeebeContainer broker = brokers.get(index);
    return broker.withTopologyCheck(new ZeebeTopologyWaitStrategy().forBrokersCount(clusterSize).forReplicationFactor(clusterSize)).withStartupTimeout(Duration.ofMinutes(5)).withEnv("ZEEBE_BROKER_CLUSTER_NODEID", String.valueOf(index)).withEnv("ZEEBE_BROKER_CLUSTER_CLUSTERSIZE", String.valueOf(clusterSize)).withEnv("ZEEBE_BROKER_CLUSTER_REPLICATIONFACTOR", String.valueOf(clusterSize)).withEnv("ZEEBE_BROKER_CLUSTER_INITIALCONTACTPOINTS", initialContactPoints);
}
Also used : ZeebeTopologyWaitStrategy(io.zeebe.containers.ZeebeTopologyWaitStrategy) ZeebeContainer(io.zeebe.containers.ZeebeContainer)

Example 2 with ZeebeContainer

use of io.zeebe.containers.ZeebeContainer in project zeebe-test-container by camunda-community-hub.

the class TriggerTimerCatchEventTest method shouldTriggerTimerStartEvent.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void shouldTriggerTimerStartEvent() {
    // given
    final ZeebeClock clock = ZeebeClock.newDefaultClock(zeebeContainer);
    final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().intermediateCatchEvent().timerWithDate(TIMER_DATE.toString()).serviceTask("task", b -> b.zeebeJobType(JOB_TYPE)).endEvent().done();
    final List<ActivatedJob> activatedJobs = new CopyOnWriteArrayList<>();
    final Instant brokerTime;
    // when
    final JobHandler handler = (client, job) -> activatedJobs.add(job);
    try (final ZeebeClient client = newZeebeClient(zeebeContainer);
        final JobWorker worker = newJobWorker(handler, client)) {
        client.newDeployCommand().addProcessModel(process, "process.bpmn").send().join();
        client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().send().join();
        brokerTime = clock.addTime(TIME_OFFSET);
        Awaitility.await("until a job has been activated by the worker").untilAsserted(() -> Assertions.assertThat(activatedJobs).hasSize(1));
    }
    // then
    Assertions.assertThat(activatedJobs).as("the timer event was triggered and a job is now available").hasSize(1);
    Assertions.assertThat(brokerTime).as("the modified time is at least equal to one day from now").isAfterOrEqualTo(TIMER_DATE);
}
Also used : ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) ZeebeContainer(io.zeebe.containers.ZeebeContainer) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) Instant(java.time.Instant) ZeebeClock(io.zeebe.containers.clock.ZeebeClock) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) Duration(java.time.Duration) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Assertions(org.assertj.core.api.Assertions) JobWorker(io.camunda.zeebe.client.api.worker.JobWorker) Awaitility(org.awaitility.Awaitility) Timeout(org.junit.jupiter.api.Timeout) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Container(org.testcontainers.junit.jupiter.Container) ZeebeClock(io.zeebe.containers.clock.ZeebeClock) Instant(java.time.Instant) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) JobWorker(io.camunda.zeebe.client.api.worker.JobWorker) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 3 with ZeebeContainer

use of io.zeebe.containers.ZeebeContainer in project zeebe by camunda.

the class ContainerState method start.

public void start(final boolean enableDebug, final boolean withRemoteDebugging) {
    final String contactPoint;
    broker = new ZeebeContainer(ZeebeTestContainerDefaults.defaultTestImage().withTag(brokerVersion)).withEnv("ZEEBE_LOG_LEVEL", "DEBUG").withEnv("ZEEBE_BROKER_NETWORK_MAXMESSAGESIZE", "128KB").withEnv("ZEEBE_BROKER_DATA_LOGSEGMENTSIZE", "64MB").withEnv("ZEEBE_BROKER_DATA_SNAPSHOTPERIOD", "1m").withEnv("ZEEBE_BROKER_DATA_LOGINDEXDENSITY", "1").withZeebeData(volume).withNetwork(network);
    this.withRemoteDebugging = withRemoteDebugging;
    if (withRemoteDebugging) {
        RemoteDebugger.configureContainer(broker);
        LOG.info("================================================");
        LOG.info("About to start broker....");
        LOG.info("The broker will wait for a debugger to connect to it at port " + RemoteDebugger.DEFAULT_REMOTE_DEBUGGER_PORT + ". It will wait for " + RemoteDebugger.DEFAULT_START_TIMEOUT.toString());
        LOG.info("================================================");
    }
    if (enableDebug) {
        broker = broker.withEnv("ZEEBE_DEBUG", "true");
    }
    Failsafe.with(CONTAINER_START_RETRY_POLICY).run(() -> broker.self().start());
    if (gatewayVersion == null) {
        contactPoint = broker.getExternalGatewayAddress();
    } else {
        gateway = new ZeebeGatewayContainer(ZeebeTestContainerDefaults.defaultTestImage().withTag(gatewayVersion)).withEnv("ZEEBE_GATEWAY_CLUSTER_CONTACTPOINT", broker.getInternalClusterAddress()).withEnv("ZEEBE_LOG_LEVEL", "DEBUG").withNetwork(network);
        Failsafe.with(CONTAINER_START_RETRY_POLICY).run(() -> gateway.self().start());
        contactPoint = gateway.getExternalGatewayAddress();
    }
    client = ZeebeClient.newClientBuilder().gatewayAddress(contactPoint).usePlaintext().build();
    partitionsActuatorClient = new PartitionsActuatorClient(broker.getExternalMonitoringAddress());
}
Also used : PartitionsActuatorClient(io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer) ZeebeContainer(io.zeebe.containers.ZeebeContainer)

Example 4 with ZeebeContainer

use of io.zeebe.containers.ZeebeContainer in project zeebe by camunda-cloud.

the class ContainerState method start.

public void start(final boolean enableDebug, final boolean withRemoteDebugging) {
    final String contactPoint;
    broker = new ZeebeContainer(brokerImage).withEnv("ZEEBE_LOG_LEVEL", "DEBUG").withEnv("ZEEBE_BROKER_NETWORK_MAXMESSAGESIZE", "128KB").withEnv("ZEEBE_BROKER_DATA_LOGSEGMENTSIZE", "64MB").withEnv("ZEEBE_BROKER_DATA_SNAPSHOTPERIOD", "1m").withEnv("ZEEBE_BROKER_DATA_LOGINDEXDENSITY", "1").withZeebeData(volume).withNetwork(network);
    this.withRemoteDebugging = withRemoteDebugging;
    if (withRemoteDebugging) {
        RemoteDebugger.configureContainer(broker);
        LOG.info("================================================");
        LOG.info("About to start broker....");
        LOG.info("The broker will wait for a debugger to connect to it at port " + RemoteDebugger.DEFAULT_REMOTE_DEBUGGER_PORT + ". It will wait for " + RemoteDebugger.DEFAULT_START_TIMEOUT.toString());
        LOG.info("================================================");
    }
    if (enableDebug) {
        broker = broker.withEnv("ZEEBE_DEBUG", "true");
    }
    Failsafe.with(CONTAINER_START_RETRY_POLICY).run(() -> broker.self().start());
    if (gatewayImage == null) {
        contactPoint = broker.getExternalGatewayAddress();
    } else {
        gateway = new ZeebeGatewayContainer(gatewayImage).withEnv("ZEEBE_GATEWAY_CLUSTER_CONTACTPOINT", broker.getInternalClusterAddress()).withEnv("ZEEBE_LOG_LEVEL", "DEBUG").withNetwork(network);
        Failsafe.with(CONTAINER_START_RETRY_POLICY).run(() -> gateway.self().start());
        contactPoint = gateway.getExternalGatewayAddress();
    }
    client = ZeebeClient.newClientBuilder().gatewayAddress(contactPoint).usePlaintext().build();
    partitionsActuatorClient = new PartitionsActuatorClient(broker.getExternalMonitoringAddress());
}
Also used : PartitionsActuatorClient(io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient) ZeebeGatewayContainer(io.zeebe.containers.ZeebeGatewayContainer) ZeebeContainer(io.zeebe.containers.ZeebeContainer)

Example 5 with ZeebeContainer

use of io.zeebe.containers.ZeebeContainer in project zeebe by zeebe-io.

the class BrokerMonitoringEndpointTest method setUpClass.

@BeforeClass
public static void setUpClass() {
    sutBroker = new ZeebeContainer(ZeebeTestContainerDefaults.defaultTestImage());
    sutBroker.start();
    final Integer monitoringPort = sutBroker.getMappedPort(ZeebePort.MONITORING.getPort());
    final String containerIPAddress = sutBroker.getExternalHost();
    brokerServerSpec = new RequestSpecBuilder().setContentType(ContentType.TEXT).setBaseUri("http://" + containerIPAddress).setPort(monitoringPort).addFilter(new ResponseLoggingFilter()).addFilter(new RequestLoggingFilter()).build();
}
Also used : RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RequestSpecBuilder(io.restassured.builder.RequestSpecBuilder) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) ZeebeContainer(io.zeebe.containers.ZeebeContainer) BeforeClass(org.junit.BeforeClass)

Aggregations

ZeebeContainer (io.zeebe.containers.ZeebeContainer)13 Test (org.junit.jupiter.api.Test)5 Timeout (org.junit.jupiter.api.Timeout)5 ZeebeClient (io.camunda.zeebe.client.ZeebeClient)3 PartitionsActuatorClient (io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient)3 RequestSpecBuilder (io.restassured.builder.RequestSpecBuilder)3 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)3 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)3 ZeebeGatewayContainer (io.zeebe.containers.ZeebeGatewayContainer)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 BeforeClass (org.junit.BeforeClass)3 ActivatedJob (io.camunda.zeebe.client.api.response.ActivatedJob)2 JobHandler (io.camunda.zeebe.client.api.worker.JobHandler)2 JobWorker (io.camunda.zeebe.client.api.worker.JobWorker)2 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)2 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)2 ZeebeClock (io.zeebe.containers.clock.ZeebeClock)2 Path (java.nio.file.Path)2 Duration (java.time.Duration)2 Instant (java.time.Instant)2