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));
}
}
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));
}
}
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));
}
}
Aggregations