Search in sources :

Example 1 with ZeebeClock

use of io.zeebe.containers.clock.ZeebeClock 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 2 with ZeebeClock

use of io.zeebe.containers.clock.ZeebeClock 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)

Aggregations

ZeebeClient (io.camunda.zeebe.client.ZeebeClient)2 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 ZeebeContainer (io.zeebe.containers.ZeebeContainer)2 ZeebeClock (io.zeebe.containers.clock.ZeebeClock)2 Duration (java.time.Duration)2 Instant (java.time.Instant)2 List (java.util.List)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 TimeUnit (java.util.concurrent.TimeUnit)2 Assertions (org.assertj.core.api.Assertions)2 Awaitility (org.awaitility.Awaitility)2 Test (org.junit.jupiter.api.Test)2 Timeout (org.junit.jupiter.api.Timeout)2 Container (org.testcontainers.junit.jupiter.Container)2 Testcontainers (org.testcontainers.junit.jupiter.Testcontainers)2