Search in sources :

Example 11 with ZeebeClient

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

the class ZeebeClusterWithEmbeddedGatewaysExampleTest method shouldStartCluster.

@Test
@Timeout(value = 15, unit = TimeUnit.MINUTES)
void shouldStartCluster() {
    // given
    final Topology topology;
    // when
    try (final ZeebeClient client = cluster.newClientBuilder().build()) {
        topology = client.newTopologyRequest().send().join(5, TimeUnit.SECONDS);
    }
    // then
    final List<BrokerInfo> brokers = topology.getBrokers();
    Assertions.assertThat(brokers).as("the topology contains all the brokers, advertising the expected address").hasSize(2).extracting(BrokerInfo::getAddress).containsExactlyInAnyOrder(cluster.getBrokers().get(0).getInternalCommandAddress(), cluster.getBrokers().get(1).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) Timeout(org.junit.jupiter.api.Timeout)

Example 12 with ZeebeClient

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

the class ZeebeBrokerNodeTest method shouldReuseHostDataOnRestart.

@Timeout(value = 5, unit = TimeUnit.MINUTES)
@ParameterizedTest(name = "{0}")
@MethodSource("reuseDataTestCases")
@EnabledOnOs(LINUX)
void shouldReuseHostDataOnRestart(@SuppressWarnings("unused") final String testName, final BrokerNodeProvider brokerNodeProvider, @TempDir final Path dataDir) {
    // given
    final ZeebeBrokerNode<?> broker = brokerNodeProvider.apply(dataDir);
    final ZeebeGatewayContainer gateway = new ZeebeGatewayContainer().withEnv("ZEEBE_GATEWAY_CLUSTER_CONTACTPOINT", broker.getInternalClusterAddress());
    // when
    broker.start();
    gateway.start();
    try (final ZeebeClient client = ZeebeClientFactory.newZeebeClient(gateway)) {
        // deploy a new process, which we can use on restart to assert that the data was correctly
        // reused
        final DeploymentEvent deployment = deploySampleProcess(client);
        broker.stop();
        // on restart we need to wait until the gateway is aware of the new leader
        broker.start();
        awaitUntilTopologyIsComplete(client);
        final ProcessInstanceEvent processInstance = createSampleProcessInstance(client);
        // then
        assertThat(processInstance).as("the process instance was successfully created").isNotNull().extracting(ProcessInstanceEvent::getProcessDefinitionKey).isEqualTo(deployment.getProcesses().get(0).getProcessDefinitionKey());
    } finally {
        CloseHelper.quietCloseAll(gateway, broker);
    }
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Timeout(org.junit.jupiter.api.Timeout) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with ZeebeClient

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

the class ZeebeContainerTest method shouldStartWithEmbeddedGatewayByDefault.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void shouldStartWithEmbeddedGatewayByDefault() {
    // given
    final Topology topology;
    // when
    try (final ZeebeClient client = ZeebeClientFactory.newZeebeClient(zeebeContainer)) {
        topology = client.newTopologyRequest().send().join(5, TimeUnit.SECONDS);
    }
    // then
    // as we're not testing the client/gateway themselves, it's fine to simply assert we get a
    // successful response here  - the property we assert isn't too important
    Assertions.assertThat(topology.getGatewayVersion()).as("the gateway is started").isEqualTo(ZeebeDefaults.getInstance().getDefaultVersion());
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 14 with ZeebeClient

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

the class DeploymentPostProcessor method apply.

@Override
public Consumer<ZeebeClient> apply(final ClassInfo beanInfo) {
    final ZeebeDeploymentValue value = reader.applyOrThrow(beanInfo);
    LOGGER.info("deployment: {}", value);
    return client -> {
        DeployResourceCommandStep1 deployResourceCommand = client.newDeployResourceCommand();
        DeploymentEvent deploymentResult = value.getResources().stream().flatMap(resource -> Stream.of(getResources(resource))).map(resource -> {
            try (InputStream inputStream = resource.getInputStream()) {
                return deployResourceCommand.addResourceStream(inputStream, resource.getFilename());
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage());
            }
        }).filter(Objects::nonNull).reduce((first, second) -> second).orElseThrow(() -> new IllegalArgumentException("Requires at least one resource to deploy")).send().join();
        LOGGER.info("Deployed: {}", Stream.concat(deploymentResult.getDecisionRequirements().stream().map(wf -> String.format("<%s:%d>", wf.getDmnDecisionRequirementsId(), wf.getVersion())), deploymentResult.getProcesses().stream().map(wf -> String.format("<%s:%d>", wf.getBpmnProcessId(), wf.getVersion()))).collect(Collectors.joining(",")));
    };
}
Also used : Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) ZeebeDeploymentValue(io.camunda.zeebe.spring.client.bean.value.ZeebeDeploymentValue) Collectors(java.util.stream.Collectors) ClassInfo(io.camunda.zeebe.spring.client.bean.ClassInfo) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Objects(java.util.Objects) Consumer(java.util.function.Consumer) Stream(java.util.stream.Stream) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) ReadZeebeDeploymentValue(io.camunda.zeebe.spring.client.bean.value.factory.ReadZeebeDeploymentValue) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) DeployResourceCommandStep1(io.camunda.zeebe.client.api.command.DeployResourceCommandStep1) ZeebeDeployment(io.camunda.zeebe.spring.client.annotation.ZeebeDeployment) Resource(org.springframework.core.io.Resource) InputStream(java.io.InputStream) DeployResourceCommandStep1(io.camunda.zeebe.client.api.command.DeployResourceCommandStep1) InputStream(java.io.InputStream) IOException(java.io.IOException) ZeebeDeploymentValue(io.camunda.zeebe.spring.client.bean.value.ZeebeDeploymentValue) ReadZeebeDeploymentValue(io.camunda.zeebe.spring.client.bean.value.factory.ReadZeebeDeploymentValue) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent)

Example 15 with ZeebeClient

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

the class InitializeAllZeebePostProcessor method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
    final ClassInfo beanInfo = ClassInfo.builder().bean(bean).beanName(beanName).build();
    for (final AbstractZeebePostProcessor p : processors) {
        if (!p.test(beanInfo)) {
            continue;
        }
        final Consumer<ZeebeClient> c = p.apply(beanInfo);
        clientLifecycle.addStartListener(c);
    }
    return bean;
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) ClassInfo(io.camunda.zeebe.spring.client.bean.ClassInfo)

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