Search in sources :

Example 11 with ZeebeContainer

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

the class RestartWithExtractedDataExampleTest method shouldGenerateData.

/**
 * Start a container with a volume, deploy a process, and extract the generated data to some
 * folder. In the next test, we will reuse this data to create a process instance, proving that
 * the data was successfully reused.
 *
 * <p>NOTE: since Zeebe is an asynchronous system, and we cannot guarantee when the engine is
 * idle, we stop the container before extracting the data. This causes us to start a second
 * (albeit tiny) container to extract the data.
 *
 * <p>If you all you wanted was to extract data from a live container, then you can use the {@link
 * ContainerArchive#builder()} directly and pass in your live container. For such a use case, you
 * wouldn't even need to be using a volume.
 */
@Test
@Order(1)
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void shouldGenerateData() throws IOException {
    // given
    final ZeebeVolume volume = ZeebeVolume.newVolume();
    final Path destination = tempDir.resolve(DATA_DIR);
    // when
    try (final ZeebeContainer container = new ZeebeContainer().withZeebeData(volume)) {
        container.start();
        deployProcess(container);
    }
    volume.extract(destination);
    // then
    assertThat(destination).isNotEmptyDirectory();
}
Also used : Path(java.nio.file.Path) ZeebeContainer(io.zeebe.containers.ZeebeContainer) ZeebeVolume(io.zeebe.containers.ZeebeVolume) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 12 with ZeebeContainer

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

the class TriggerTimerStartEventTest 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().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();
        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 13 with ZeebeContainer

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

the class ClusterWithEmbeddedGatewaysExampleTest method shouldStartCluster.

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

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