Search in sources :

Example 26 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe-process-test by camunda-cloud.

the class ZeebeProcessTestExtension method afterEach.

/**
 * After each test the test engine en client will be closed. The {@link RecordStream} will get
 * reset.
 *
 * @param extensionContext jUnit5 extension context
 */
@Override
public void afterEach(final ExtensionContext extensionContext) {
    BpmnAssert.resetRecordStream();
    final Object clientContent = getStore(extensionContext).get(KEY_ZEEBE_CLIENT);
    final ZeebeClient client = (ZeebeClient) clientContent;
    client.close();
    final Object engineContent = getStore(extensionContext).get(KEY_ZEEBE_ENGINE);
    final ZeebeTestEngine engine = (ZeebeTestEngine) engineContent;
    engine.stop();
}
Also used : ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) ZeebeClient(io.camunda.zeebe.client.ZeebeClient)

Example 27 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe by zeebe-io.

the class ResponsiveHealthIndicatorTest method testCreateZeebeClientShouldPassCertificateChainPathIfSecurityIsEnabled.

@Test
public void testCreateZeebeClientShouldPassCertificateChainPathIfSecurityIsEnabled() {
    // given
    final var securityEnabledGatewayCfg = new GatewayCfg();
    securityEnabledGatewayCfg.getNetwork().setHost("testhost");
    securityEnabledGatewayCfg.getNetwork().setPort(1234);
    securityEnabledGatewayCfg.getSecurity().setEnabled(true);
    securityEnabledGatewayCfg.getSecurity().setCertificateChainPath(new File(CERTIFICATE_CHAIN_PATH));
    securityEnabledGatewayCfg.init();
    // when
    final ZeebeClient actualZeebeClient = ResponsiveHealthIndicator.createZeebeClient(securityEnabledGatewayCfg, TEST_DURATION);
    // then
    assertThat(actualZeebeClient.getConfiguration().isPlaintextConnectionEnabled()).isFalse();
    assertThat(actualZeebeClient.getConfiguration().getCaCertificatePath()).isEqualTo(CERTIFICATE_CHAIN_PATH);
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) GatewayCfg(io.camunda.zeebe.gateway.impl.configuration.GatewayCfg) File(java.io.File) Test(org.junit.Test)

Example 28 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe by zeebe-io.

the class ResponsiveHealthIndicatorTest method testCreateZeebeClientShouldConfigureContactPoint.

@Test
public void testCreateZeebeClientShouldConfigureContactPoint() {
    // when
    final ZeebeClient actual = ResponsiveHealthIndicator.createZeebeClient(TEST_CFG, TEST_DURATION);
    // then
    assertThat(actual.getConfiguration().getGatewayAddress()).isEqualTo("testhost:1234");
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Test(org.junit.Test)

Example 29 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe by zeebe-io.

the class ResponsiveHealthIndicatorTest method testCreateZeebeClientShouldEnablePlainTextCommunicationIfSecurityIsDisabled.

@Test
public void testCreateZeebeClientShouldEnablePlainTextCommunicationIfSecurityIsDisabled() {
    // when
    final ZeebeClient actual = ResponsiveHealthIndicator.createZeebeClient(TEST_CFG, TEST_DURATION);
    // then
    assertThat(actual.getConfiguration().isPlaintextConnectionEnabled()).isTrue();
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Test(org.junit.Test)

Example 30 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe by zeebe-io.

the class WorkloadGenerator method performSampleWorkload.

/**
 * Given a client, deploy a process, start instances, work on service tasks, create and resolve
 * incidents and finish the instance.
 */
public static void performSampleWorkload(final ZeebeClient client) {
    client.newDeployResourceCommand().addProcessModel(SAMPLE_PROCESS, "sample_process.bpmn").send().join();
    final Map<String, Object> variables = new HashMap<>();
    variables.put("orderId", "foo-bar-123");
    variables.put("largeValue", "x".repeat(8192));
    variables.put("unicode", "Á");
    variables.put("nullable", null);
    final long processInstanceKey = client.newCreateInstanceCommand().bpmnProcessId("testProcess").latestVersion().variables(variables).send().join().getProcessInstanceKey();
    // create job worker which fails on first try and sets retries to 0 to create an incident
    final AtomicBoolean fail = new AtomicBoolean(true);
    final JobWorker worker = client.newWorker().jobType("work").handler((handlerClient, job) -> {
        if (fail.getAndSet(false)) {
            // fail job
            handlerClient.newFailCommand(job.getKey()).retries(0).errorMessage("failed").send().join();
        } else {
            handlerClient.newCompleteCommand(job.getKey()).send().join();
        }
    }).open();
    client.newPublishMessageCommand().messageName("catch").correlationKey("foo-bar-123").send().join();
    // wait for incident and resolve it
    final Record<IncidentRecordValue> incident = Awaitility.await("the incident was created").timeout(Duration.ofMinutes(1)).until(() -> RecordingExporter.incidentRecords(IncidentIntent.CREATED).withProcessInstanceKey(processInstanceKey).withElementId("task").findFirst(), Optional::isPresent).orElseThrow();
    client.newUpdateRetriesCommand(incident.getValue().getJobKey()).retries(3).send().join();
    client.newResolveIncidentCommand(incident.getKey()).send().join();
    // wrap up
    Awaitility.await("the process instance was completed").timeout(Duration.ofMinutes(1)).until(() -> RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).filter(r -> r.getKey() == processInstanceKey).exists());
    worker.close();
}
Also used : ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) IncidentRecordValue(io.camunda.zeebe.protocol.record.value.IncidentRecordValue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) HashMap(java.util.HashMap) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) Record(io.camunda.zeebe.protocol.record.Record) IncidentIntent(io.camunda.zeebe.protocol.record.intent.IncidentIntent) Duration(java.time.Duration) Map(java.util.Map) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) Optional(java.util.Optional) JobWorker(io.camunda.zeebe.client.api.worker.JobWorker) Awaitility(org.awaitility.Awaitility) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) IncidentRecordValue(io.camunda.zeebe.protocol.record.value.IncidentRecordValue) JobWorker(io.camunda.zeebe.client.api.worker.JobWorker)

Aggregations

ZeebeClient (io.camunda.zeebe.client.ZeebeClient)90 ZeebeClientBuilder (io.camunda.zeebe.client.ZeebeClientBuilder)27 Test (org.junit.jupiter.api.Test)23 Topology (io.camunda.zeebe.client.api.response.Topology)16 ProcessInstanceEvent (io.camunda.zeebe.client.api.response.ProcessInstanceEvent)13 JobWorker (io.camunda.zeebe.client.api.worker.JobWorker)13 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)13 Test (org.junit.Test)12 Timeout (org.junit.jupiter.api.Timeout)11 Duration (java.time.Duration)10 DeploymentEvent (io.camunda.zeebe.client.api.response.DeploymentEvent)9 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)9 Awaitility (org.awaitility.Awaitility)8 Map (java.util.Map)7 BrokerInfo (io.camunda.zeebe.client.api.response.BrokerInfo)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Optional (java.util.Optional)6 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)6 Future (java.util.concurrent.Future)6