use of io.camunda.zeebe.client.ZeebeClient in project zeebe by camunda.
the class LongPollingActivateJobsTest method sendActivateRequestsAndClose.
private void sendActivateRequestsAndClose(final String jobType, final int count) throws InterruptedException {
for (int i = 0; i < count; i++) {
final ZeebeClient client = ZeebeClient.newClientBuilder().gatewayAddress(NetUtil.toSocketAddressString(BROKER_RULE.getGatewayAddress())).usePlaintext().build();
client.newActivateJobsCommand().jobType(jobType).maxJobsToActivate(5).workerName("closed-" + i).send();
Thread.sleep(100);
client.close();
}
}
use of io.camunda.zeebe.client.ZeebeClient 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.camunda.zeebe.client.ZeebeClient in project zeebe by camunda.
the class TopologyViewer method main.
public static void main(final String[] args) {
final String defaultAddress = "localhost:26500";
final String envVarAddress = System.getenv("ZEEBE_ADDRESS");
final ZeebeClientBuilder clientBuilder;
final String contactPoint;
if (envVarAddress != null) {
/* Connect to Camunda Cloud Cluster, assumes that credentials are set in environment variables.
* See JavaDoc on class level for details
*/
contactPoint = envVarAddress;
clientBuilder = ZeebeClient.newClientBuilder().gatewayAddress(envVarAddress);
} else {
// connect to local deployment; assumes that authentication is disabled
contactPoint = defaultAddress;
clientBuilder = ZeebeClient.newClientBuilder().gatewayAddress(defaultAddress).usePlaintext();
}
try (final ZeebeClient client = clientBuilder.build()) {
System.out.println("Requesting topology with initial contact point " + contactPoint);
final Topology topology = client.newTopologyRequest().send().join();
System.out.println("Topology:");
topology.getBrokers().forEach(b -> {
System.out.println(" " + b.getAddress());
b.getPartitions().forEach(p -> System.out.println(" " + p.getPartitionId() + " - " + p.getRole()));
});
System.out.println("Done.");
}
}
use of io.camunda.zeebe.client.ZeebeClient in project zeebe-process-test by camunda-cloud.
the class ZeebeProcessTestExtension method afterEach.
/**
* After each test the client will be closed. At this point we will reset the engine. This will
* stop the current engine and create a new one. The new engine will not be started yet as that is
* done in the beforeEach method.
*
* @param extensionContext jUnit5 extension context
*/
@Override
public void afterEach(final ExtensionContext extensionContext) {
final Object clientContent = getStore(extensionContext).get(KEY_ZEEBE_CLIENT);
final ZeebeClient client = (ZeebeClient) clientContent;
client.close();
final Object engineContent = getStore(extensionContext.getParent().get()).get(KEY_ZEEBE_ENGINE);
final ContainerizedEngine engine = (ContainerizedEngine) engineContent;
engine.reset();
}
use of io.camunda.zeebe.client.ZeebeClient in project zeebe-process-test by camunda-cloud.
the class ZeebeProcessTestExtension method beforeEach.
/**
* Before each test a new test engine gets created and started. A client to communicate with the
* engine will also be created. Together with a {@link RecordStream} these will be injected in the
* fields of the test class, if they are available.
*
* @param extensionContext jUnit5 extension context
*/
@Override
public void beforeEach(final ExtensionContext extensionContext) {
final ZeebeTestEngine engine = EngineFactory.create();
engine.start();
final ZeebeClient client = engine.createClient();
final RecordStream recordStream = RecordStream.of(engine.getRecordStreamSource());
try {
injectFields(extensionContext, engine, client, recordStream);
} catch (final Exception ex) {
client.close();
engine.stop();
throw ex;
}
BpmnAssert.initRecordStream(recordStream);
getStore(extensionContext).put(KEY_ZEEBE_CLIENT, client);
getStore(extensionContext).put(KEY_ZEEBE_ENGINE, engine);
}
Aggregations