Search in sources :

Example 1 with ZeebeGatewayNode

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

the class RollingUpdateTest method shouldPerformRollingUpdate.

@Test
void shouldPerformRollingUpdate() {
    // given
    cluster.start();
    // when
    final long firstProcessInstanceKey;
    ZeebeGatewayNode<?> availableGateway = cluster.getGateways().get("0");
    try (final var client = newZeebeClient(availableGateway)) {
        deployProcess(client);
        // potentially retry in case we're faster than the deployment distribution
        firstProcessInstanceKey = Awaitility.await("process instance creation").atMost(Duration.ofSeconds(5)).pollInterval(Duration.ofMillis(100)).ignoreExceptions().until(() -> createProcessInstance(client), Objects::nonNull).getProcessInstanceKey();
    }
    for (int i = cluster.getBrokers().size() - 1; i >= 0; i--) {
        try (final ZeebeClient client = newZeebeClient(availableGateway)) {
            final var brokerId = i;
            final ZeebeBrokerNode<?> broker = cluster.getBrokers().get(i);
            broker.stop();
            Awaitility.await("broker is removed from topology").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> assertTopologyDoesNotContainerBroker(client, brokerId));
            updateBroker(broker);
            broker.start();
            Awaitility.await("updated broker is added to topology").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> assertTopologyContainsUpdatedBroker(client, brokerId));
            availableGateway = cluster.getGateways().get(String.valueOf(i));
        }
    }
    // then
    final Map<Long, List<String>> activatedJobs = new HashMap<>();
    final var expectedOrderedJobs = List.of("firstTask", "secondTask");
    final JobHandler jobHandler = (jobClient, job) -> {
        jobClient.newCompleteCommand(job.getKey()).send().join();
        activatedJobs.compute(job.getProcessInstanceKey(), (ignored, list) -> {
            final var appendedList = Optional.ofNullable(list).orElse(new CopyOnWriteArrayList<>());
            appendedList.add(job.getType());
            return appendedList;
        });
    };
    try (final var client = newZeebeClient(availableGateway)) {
        final var secondProcessInstanceKey = createProcessInstance(client).getProcessInstanceKey();
        final var expectedActivatedJobs = Map.of(firstProcessInstanceKey, expectedOrderedJobs, secondProcessInstanceKey, expectedOrderedJobs);
        client.newWorker().jobType("firstTask").handler(jobHandler).open();
        client.newWorker().jobType("secondTask").handler(jobHandler).open();
        Awaitility.await("all jobs have been activated").atMost(Duration.ofSeconds(5)).untilAsserted(() -> assertThat(activatedJobs).as("the expected number of jobs has been activated").isEqualTo(expectedActivatedJobs));
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) HashMap(java.util.HashMap) Network(org.testcontainers.containers.Network) ZeebeBrokerNode(io.zeebe.containers.ZeebeBrokerNode) PartitionStatus(io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient.PartitionStatus) ZeebeGatewayNode(io.zeebe.containers.ZeebeGatewayNode) Duration(java.time.Duration) Map(java.util.Map) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Either(io.camunda.zeebe.util.Either) VersionUtil(io.camunda.zeebe.util.VersionUtil) CloseHelper(org.agrona.CloseHelper) ZeebeVolume(io.zeebe.containers.ZeebeVolume) ContainerState(org.testcontainers.containers.ContainerState) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) EitherAssert(io.camunda.zeebe.test.util.asserts.EitherAssert) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ZeebeTestContainerDefaults(io.camunda.zeebe.test.util.testcontainers.ZeebeTestContainerDefaults) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) PartitionsActuatorClient(io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient) Optional(java.util.Optional) TopologyAssert(io.camunda.zeebe.test.util.asserts.TopologyAssert) ZeebeCluster(io.zeebe.containers.cluster.ZeebeCluster) Awaitility(org.awaitility.Awaitility) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) Objects(java.util.Objects) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test)

Example 2 with ZeebeGatewayNode

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

the class RollingUpdateTest method shouldPerformRollingUpdate.

@Test
void shouldPerformRollingUpdate() {
    // given
    cluster.start();
    // when
    final long firstProcessInstanceKey;
    ZeebeGatewayNode<?> availableGateway = cluster.getGateways().get("0");
    try (final var client = newZeebeClient(availableGateway)) {
        deployProcess(client);
        // potentially retry in case we're faster than the deployment distribution
        firstProcessInstanceKey = Awaitility.await("process instance creation").atMost(Duration.ofSeconds(5)).pollInterval(Duration.ofMillis(100)).ignoreExceptions().until(() -> createProcessInstance(client), Objects::nonNull).getProcessInstanceKey();
    }
    for (int i = cluster.getBrokers().size() - 1; i >= 0; i--) {
        try (final ZeebeClient client = newZeebeClient(availableGateway)) {
            final var brokerId = i;
            final ZeebeBrokerNode<?> broker = cluster.getBrokers().get(i);
            broker.stop();
            Awaitility.await("broker is removed from topology").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> assertTopologyDoesNotContainerBroker(client, brokerId));
            updateBroker(broker);
            broker.start();
            Awaitility.await("updated broker is added to topology").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> assertTopologyContainsUpdatedBroker(client, brokerId));
            availableGateway = cluster.getGateways().get(String.valueOf(i));
        }
    }
    // then
    final Map<Long, List<String>> activatedJobs = new HashMap<>();
    final var expectedOrderedJobs = List.of("firstTask", "secondTask");
    final JobHandler jobHandler = (jobClient, job) -> {
        jobClient.newCompleteCommand(job.getKey()).send().join();
        activatedJobs.compute(job.getProcessInstanceKey(), (ignored, list) -> {
            final var appendedList = Optional.ofNullable(list).orElse(new CopyOnWriteArrayList<>());
            appendedList.add(job.getType());
            return appendedList;
        });
    };
    try (final var client = newZeebeClient(availableGateway)) {
        final var secondProcessInstanceKey = createProcessInstance(client).getProcessInstanceKey();
        final var expectedActivatedJobs = Map.of(firstProcessInstanceKey, expectedOrderedJobs, secondProcessInstanceKey, expectedOrderedJobs);
        client.newWorker().jobType("firstTask").handler(jobHandler).open();
        client.newWorker().jobType("secondTask").handler(jobHandler).open();
        Awaitility.await("all jobs have been activated").atMost(Duration.ofSeconds(5)).untilAsserted(() -> assertThat(activatedJobs).as("the expected number of jobs has been activated").isEqualTo(expectedActivatedJobs));
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DockerImageName(org.testcontainers.utility.DockerImageName) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) HashMap(java.util.HashMap) Network(org.testcontainers.containers.Network) ZeebeBrokerNode(io.zeebe.containers.ZeebeBrokerNode) PartitionStatus(io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient.PartitionStatus) ZeebeGatewayNode(io.zeebe.containers.ZeebeGatewayNode) Duration(java.time.Duration) Map(java.util.Map) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Either(io.camunda.zeebe.util.Either) VersionUtil(io.camunda.zeebe.util.VersionUtil) CloseHelper(org.agrona.CloseHelper) ZeebeVolume(io.zeebe.containers.ZeebeVolume) ContainerState(org.testcontainers.containers.ContainerState) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) EitherAssert(io.camunda.zeebe.test.util.asserts.EitherAssert) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ZeebeTestContainerDefaults(io.camunda.zeebe.test.util.testcontainers.ZeebeTestContainerDefaults) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) PartitionsActuatorClient(io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient) Optional(java.util.Optional) TopologyAssert(io.camunda.zeebe.test.util.asserts.TopologyAssert) ZeebeCluster(io.zeebe.containers.cluster.ZeebeCluster) Awaitility(org.awaitility.Awaitility) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) Objects(java.util.Objects) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test)

Example 3 with ZeebeGatewayNode

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

the class RollingUpdateTest method shouldPerformRollingUpdate.

@Test
void shouldPerformRollingUpdate() {
    // given
    cluster.start();
    // when
    final long firstProcessInstanceKey;
    ZeebeGatewayNode<?> availableGateway = cluster.getGateways().get("0");
    try (final var client = newZeebeClient(availableGateway)) {
        deployProcess(client);
        // potentially retry in case we're faster than the deployment distribution
        firstProcessInstanceKey = Awaitility.await("process instance creation").atMost(Duration.ofSeconds(5)).pollInterval(Duration.ofMillis(100)).ignoreExceptions().until(() -> createProcessInstance(client), Objects::nonNull).getProcessInstanceKey();
    }
    for (int i = cluster.getBrokers().size() - 1; i >= 0; i--) {
        try (final ZeebeClient client = newZeebeClient(availableGateway)) {
            final var brokerId = i;
            final ZeebeBrokerNode<?> broker = cluster.getBrokers().get(i);
            broker.stop();
            Awaitility.await("broker is removed from topology").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> assertTopologyDoesNotContainerBroker(client, brokerId));
            updateBroker(broker);
            broker.start();
            Awaitility.await("updated broker is added to topology").atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofMillis(100)).untilAsserted(() -> assertTopologyContainsUpdatedBroker(client, brokerId));
            availableGateway = cluster.getGateways().get(String.valueOf(i));
        }
    }
    // then
    final Map<Long, List<String>> activatedJobs = new HashMap<>();
    final var expectedOrderedJobs = List.of("firstTask", "secondTask");
    final JobHandler jobHandler = (jobClient, job) -> {
        jobClient.newCompleteCommand(job.getKey()).send().join();
        activatedJobs.compute(job.getProcessInstanceKey(), (ignored, list) -> {
            final var appendedList = Optional.ofNullable(list).orElse(new CopyOnWriteArrayList<>());
            appendedList.add(job.getType());
            return appendedList;
        });
    };
    try (final var client = newZeebeClient(availableGateway)) {
        final var secondProcessInstanceKey = createProcessInstance(client).getProcessInstanceKey();
        final var expectedActivatedJobs = Map.of(firstProcessInstanceKey, expectedOrderedJobs, secondProcessInstanceKey, expectedOrderedJobs);
        client.newWorker().jobType("firstTask").handler(jobHandler).open();
        client.newWorker().jobType("secondTask").handler(jobHandler).open();
        Awaitility.await("all jobs have been activated").atMost(Duration.ofSeconds(5)).untilAsserted(() -> assertThat(activatedJobs).as("the expected number of jobs has been activated").isEqualTo(expectedActivatedJobs));
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DockerImageName(org.testcontainers.utility.DockerImageName) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) HashMap(java.util.HashMap) Network(org.testcontainers.containers.Network) ZeebeBrokerNode(io.zeebe.containers.ZeebeBrokerNode) PartitionStatus(io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient.PartitionStatus) ZeebeGatewayNode(io.zeebe.containers.ZeebeGatewayNode) Duration(java.time.Duration) Map(java.util.Map) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Either(io.camunda.zeebe.util.Either) VersionUtil(io.camunda.zeebe.util.VersionUtil) CloseHelper(org.agrona.CloseHelper) ZeebeVolume(io.zeebe.containers.ZeebeVolume) ContainerState(org.testcontainers.containers.ContainerState) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) EitherAssert(io.camunda.zeebe.test.util.asserts.EitherAssert) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ZeebeTestContainerDefaults(io.camunda.zeebe.test.util.testcontainers.ZeebeTestContainerDefaults) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) PartitionsActuatorClient(io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient) Optional(java.util.Optional) TopologyAssert(io.camunda.zeebe.test.util.asserts.TopologyAssert) ZeebeCluster(io.zeebe.containers.cluster.ZeebeCluster) Awaitility(org.awaitility.Awaitility) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) JobHandler(io.camunda.zeebe.client.api.worker.JobHandler) Objects(java.util.Objects) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

ZeebeClient (io.camunda.zeebe.client.ZeebeClient)3 ProcessInstanceEvent (io.camunda.zeebe.client.api.response.ProcessInstanceEvent)3 JobHandler (io.camunda.zeebe.client.api.worker.JobHandler)3 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)3 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)3 PartitionsActuatorClient (io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient)3 PartitionStatus (io.camunda.zeebe.test.util.actuator.PartitionsActuatorClient.PartitionStatus)3 EitherAssert (io.camunda.zeebe.test.util.asserts.EitherAssert)3 TopologyAssert (io.camunda.zeebe.test.util.asserts.TopologyAssert)3 ZeebeTestContainerDefaults (io.camunda.zeebe.test.util.testcontainers.ZeebeTestContainerDefaults)3 Either (io.camunda.zeebe.util.Either)3 VersionUtil (io.camunda.zeebe.util.VersionUtil)3 ZeebeBrokerNode (io.zeebe.containers.ZeebeBrokerNode)3 ZeebeGatewayNode (io.zeebe.containers.ZeebeGatewayNode)3 ZeebeVolume (io.zeebe.containers.ZeebeVolume)3 ZeebeCluster (io.zeebe.containers.cluster.ZeebeCluster)3 Duration (java.time.Duration)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3