Search in sources :

Example 86 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe-test-container by camunda-community-hub.

the class ZeebeClusterTest method shouldStartSingleNodeCluster.

@Test
void shouldStartSingleNodeCluster() {
    // given
    cluster = ZeebeCluster.builder().withEmbeddedGateway(true).withReplicationFactor(1).withPartitionsCount(1).withBrokersCount(1).build();
    // when
    cluster.start();
    // then
    final ZeebeClient client = cluster.newClientBuilder().build();
    final Topology topology = client.newTopologyRequest().send().join();
    assertThat(topology.getPartitionsCount()).as("there is exactly one partition as configured").isEqualTo(1);
    assertThat(topology.getReplicationFactor()).as("there is a replication factor of 1 as configured").isEqualTo(1);
    TopologyAssert.assertThat(topology).as("the topology is complete for a one broker, one partition cluster").hasBrokersCount(1).isComplete(1, 1, 1);
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) Test(org.junit.jupiter.api.Test)

Example 87 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe-test-container by camunda-community-hub.

the class ZeebeClusterTest method shouldStartClusterWithStandaloneGateway.

@Test
void shouldStartClusterWithStandaloneGateway() {
    // given
    cluster = ZeebeCluster.builder().withEmbeddedGateway(false).withReplicationFactor(1).withPartitionsCount(1).withBrokersCount(1).withGatewaysCount(1).build();
    // when
    cluster.start();
    // then
    try (final ZeebeClient client = cluster.newClientBuilder().build()) {
        final Topology topology = client.newTopologyRequest().send().join();
        assertThat(topology.getPartitionsCount()).as("there is exactly one partition as configured").isEqualTo(1);
        assertThat(topology.getReplicationFactor()).as("there is a replication factor of 1 as configured").isEqualTo(1);
        TopologyAssert.assertThat(topology).as("the topology is complete for a one broker, one partition cluster").hasBrokersCount(1).isComplete(1, 1, 1);
    }
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) Test(org.junit.jupiter.api.Test)

Example 88 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe-test-container by camunda-community-hub.

the class SingleNodeTest method shouldConnectToZeebe.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void shouldConnectToZeebe() {
    // given
    final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().serviceTask().zeebeJobType("task").endEvent().done();
    final Map<String, Integer> variables = Maps.newHashMap("foo", 1);
    final DeploymentEvent deploymentEvent;
    final ProcessInstanceResult workflowInstanceResult;
    // when
    try (final ZeebeClient client = newZeebeClient(zeebeContainer)) {
        try (final JobWorker ignored = createJobWorker(variables, client)) {
            deploymentEvent = client.newDeployCommand().addProcessModel(process, "process.bpmn").send().join();
            workflowInstanceResult = client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().withResult().send().join();
        }
    }
    // then
    Assertions.assertThat(deploymentEvent.getProcesses()).as("the process instance was deployed").hasSize(1);
    Assertions.assertThat(workflowInstanceResult.getBpmnProcessId()).as("a process instance for the deployed process was created and completed").isEqualTo("process");
}
Also used : ProcessInstanceResult(io.camunda.zeebe.client.api.response.ProcessInstanceResult) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) JobWorker(io.camunda.zeebe.client.api.worker.JobWorker) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 89 with ZeebeClient

use of io.camunda.zeebe.client.ZeebeClient in project zeebe-test-container by camunda-community-hub.

the class ZeebeGatewayContainerTest method shouldConnectToBroker.

@Test
void shouldConnectToBroker() {
    // given
    final Topology topology;
    // when
    try (final ZeebeClient client = ZeebeClientFactory.newZeebeClient(gatewayContainer)) {
        topology = client.newTopologyRequest().send().join(5, TimeUnit.SECONDS);
    }
    // then
    final List<BrokerInfo> brokers = topology.getBrokers();
    Assertions.assertThat(brokers).as("the gateway should report one broker").hasSize(1);
    Assertions.assertThat(brokers.get(0).getAddress()).as("the gateway should report the correct contact point").isEqualTo(brokerContainer.getInternalCommandAddress());
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Test(org.junit.jupiter.api.Test)

Example 90 with ZeebeClient

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

the class ZeebeWorkerPostProcessor method apply.

@Override
public Consumer<ZeebeClient> apply(final ClassInfo beanInfo) {
    LOGGER.info("Registering Zeebe worker(s) of bean: {}", beanInfo.getBean());
    final List<ZeebeWorkerValue> annotatedMethods = new ArrayList<>();
    doWithMethods(beanInfo.getTargetClass(), method -> reader.apply(beanInfo.toMethodInfo(method)).ifPresent(annotatedMethods::add), ReflectionUtils.USER_DECLARED_METHODS);
    return client -> annotatedMethods.forEach(zeebeWorkerValue -> {
        final JobWorkerBuilderStep3 builder = client.newWorker().jobType(zeebeWorkerValue.getType()).handler(new JobHandlerInvokingSpringBeans(zeebeWorkerValue, commandExceptionHandlingStrategy));
        // using defaults from config if null, 0 or negative
        if (zeebeWorkerValue.getName() != null && zeebeWorkerValue.getName().length() > 0) {
            builder.name(zeebeWorkerValue.getName());
        } else {
            builder.name(beanInfo.getBeanName() + "#" + zeebeWorkerValue.getMethodInfo().getMethodName());
        }
        if (zeebeWorkerValue.getMaxJobsActive() > 0) {
            builder.maxJobsActive(zeebeWorkerValue.getMaxJobsActive());
        }
        if (zeebeWorkerValue.getTimeout() > 0) {
            builder.timeout(zeebeWorkerValue.getTimeout());
        }
        if (zeebeWorkerValue.getPollInterval() > 0) {
            builder.pollInterval(Duration.ofMillis(zeebeWorkerValue.getPollInterval()));
        }
        if (zeebeWorkerValue.getRequestTimeout() > 0) {
            builder.requestTimeout(Duration.ofSeconds(zeebeWorkerValue.getRequestTimeout()));
        }
        if (zeebeWorkerValue.getFetchVariables().length > 0) {
            builder.fetchVariables(zeebeWorkerValue.getFetchVariables());
        }
        builder.open();
        LOGGER.info(". Register Zeebe worker: {}", zeebeWorkerValue);
    });
}
Also used : JobHandlerInvokingSpringBeans(io.camunda.zeebe.spring.client.jobhandling.JobHandlerInvokingSpringBeans) BackoffSupplier(io.camunda.zeebe.client.api.worker.BackoffSupplier) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) ReadZeebeWorkerValue(io.camunda.zeebe.spring.client.bean.value.factory.ReadZeebeWorkerValue) ClassInfo(io.camunda.zeebe.spring.client.bean.ClassInfo) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) ZeebeWorkerValue(io.camunda.zeebe.spring.client.bean.value.ZeebeWorkerValue) List(java.util.List) ReflectionUtils(org.springframework.util.ReflectionUtils) Duration(java.time.Duration) ReflectionUtils.doWithMethods(org.springframework.util.ReflectionUtils.doWithMethods) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) ZeebeWorker(io.camunda.zeebe.spring.client.annotation.ZeebeWorker) JobWorkerBuilderStep3(io.camunda.zeebe.client.api.worker.JobWorkerBuilderStep1.JobWorkerBuilderStep3) DefaultCommandExceptionHandlingStrategy(io.camunda.zeebe.spring.client.jobhandling.DefaultCommandExceptionHandlingStrategy) ReadZeebeWorkerValue(io.camunda.zeebe.spring.client.bean.value.factory.ReadZeebeWorkerValue) ZeebeWorkerValue(io.camunda.zeebe.spring.client.bean.value.ZeebeWorkerValue) JobWorkerBuilderStep3(io.camunda.zeebe.client.api.worker.JobWorkerBuilderStep1.JobWorkerBuilderStep3) JobHandlerInvokingSpringBeans(io.camunda.zeebe.spring.client.jobhandling.JobHandlerInvokingSpringBeans) ArrayList(java.util.ArrayList)

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