Search in sources :

Example 6 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe-test-container by camunda-community-hub.

the class ZeebeClusterTest method shouldStartClusterWithMixedGateways.

@Test
void shouldStartClusterWithMixedGateways() {
    // given
    cluster = ZeebeCluster.builder().withEmbeddedGateway(true).withReplicationFactor(1).withPartitionsCount(1).withBrokersCount(1).withGatewaysCount(1).build();
    // when
    cluster.start();
    // then
    for (final ZeebeGatewayNode<?> gateway : cluster.getGateways().values()) {
        try (final ZeebeClient client = ZeebeClient.newClientBuilder().usePlaintext().gatewayAddress(gateway.getExternalGatewayAddress()).build()) {
            final Topology topology = client.newTopologyRequest().send().join();
            assertThat(topology.getPartitionsCount()).as("there is exactly one partition as configured").isEqualTo(1);
            assertThat(topology.getReplicationFactor()).as("there is a replication factor of 1 as configured").isEqualTo(1);
            TopologyAssert.assertThat(topology).as("the topology is complete for a one broker, one partition cluster").isComplete(1, 1, 1).hasBrokersCount(1);
        }
    }
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) Test(org.junit.jupiter.api.Test)

Example 7 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe-test-container by camunda-community-hub.

the class ZeebeClusterTest method shouldStartClusterWithEmbeddedGateways.

@Test
void shouldStartClusterWithEmbeddedGateways() {
    // given
    cluster = ZeebeCluster.builder().withEmbeddedGateway(true).withReplicationFactor(2).withPartitionsCount(2).withBrokersCount(2).build();
    // when
    cluster.start();
    // then
    for (final ZeebeGatewayNode<?> gateway : cluster.getGateways().values()) {
        try (final ZeebeClient client = ZeebeClient.newClientBuilder().usePlaintext().gatewayAddress(gateway.getExternalGatewayAddress()).build()) {
            final Topology topology = client.newTopologyRequest().send().join();
            assertThat(topology.getReplicationFactor()).as("there is replication factor of 2 as configured").isEqualTo(2);
            assertThat(topology.getPartitionsCount()).as("there are exactly two partitions as configured").isEqualTo(2);
            TopologyAssert.assertThat(topology).as("the topology is complete with 2 partitions and 2 brokers").hasBrokersCount(2).isComplete(2, 2, 2);
        }
    }
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) Test(org.junit.jupiter.api.Test)

Example 8 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient 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 9 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient 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 10 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient 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)

Aggregations

ZeebeClient (io.camunda.zeebe.client.ZeebeClient)90 ZeebeClientBuilder (io.camunda.zeebe.client.ZeebeClientBuilder)27 Test (org.junit.jupiter.api.Test)23 Topology (io.camunda.zeebe.client.api.response.Topology)16 ProcessInstanceEvent (io.camunda.zeebe.client.api.response.ProcessInstanceEvent)13 JobWorker (io.camunda.zeebe.client.api.worker.JobWorker)13 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)13 Test (org.junit.Test)12 Timeout (org.junit.jupiter.api.Timeout)11 Duration (java.time.Duration)10 DeploymentEvent (io.camunda.zeebe.client.api.response.DeploymentEvent)9 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)9 Awaitility (org.awaitility.Awaitility)8 Map (java.util.Map)7 BrokerInfo (io.camunda.zeebe.client.api.response.BrokerInfo)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Optional (java.util.Optional)6 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)6 Future (java.util.concurrent.Future)6