Search in sources :

Example 1 with RecordStream

use of io.camunda.zeebe.process.test.filters.RecordStream in project spring-zeebe by camunda-community-hub.

the class ZeebeTestExecutionListener method beforeTestMethod.

public void beforeTestMethod(@NonNull TestContext testContext) {
    final RecordStream recordStream = RecordStream.of(zeebeEngine.getRecordStreamSource());
    BpmnAssert.initRecordStream(recordStream);
    ZeebeTestThreadSupport.setEngineForCurrentThread(zeebeEngine);
}
Also used : RecordStream(io.camunda.zeebe.process.test.filters.RecordStream)

Example 2 with RecordStream

use of io.camunda.zeebe.process.test.filters.RecordStream 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);
}
Also used : ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) RecordStream(io.camunda.zeebe.process.test.filters.RecordStream) ZeebeClient(io.camunda.zeebe.client.ZeebeClient)

Example 3 with RecordStream

use of io.camunda.zeebe.process.test.filters.RecordStream in project zeebe-process-test by camunda-cloud.

the class EngineClientTest method shouldPrintRecords.

@Test
void shouldPrintRecords() {
    // given
    zeebeClient.newDeployCommand().addProcessModel(Bpmn.createExecutableProcess("simpleProcess").startEvent().endEvent().done(), "simpleProcess.bpmn").send().join();
    // when
    zeebeClient.newCreateInstanceCommand().bpmnProcessId("simpleProcess").latestVersion().variables(Map.of("test", 1)).send().join();
    // then
    final RecordStream recordStream = RecordStream.of(zeebeEngine.getRecordStreamSource());
    Awaitility.await().untilAsserted(() -> {
        final Optional<Record<ProcessInstanceRecordValue>> processRecords = StreamSupport.stream(recordStream.processInstanceRecords().spliterator(), false).filter(r -> r.getValue().getBpmnElementType() == BpmnElementType.PROCESS).filter(r -> r.getIntent() == ProcessInstanceIntent.ELEMENT_COMPLETED).findFirst();
        assertThat(processRecords).isNotEmpty();
    });
    recordStream.print(true);
}
Also used : PartitionBrokerRole(io.camunda.zeebe.client.api.response.PartitionBrokerRole) TimerIntent(io.camunda.zeebe.protocol.record.intent.TimerIntent) BeforeEach(org.junit.jupiter.api.BeforeEach) RecordType(io.camunda.zeebe.protocol.record.RecordType) ClientException(io.camunda.zeebe.client.api.command.ClientException) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) TimerRecordValue(io.camunda.zeebe.protocol.record.value.TimerRecordValue) ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) Record(io.camunda.zeebe.protocol.record.Record) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PartitionInfo(io.camunda.zeebe.client.api.response.PartitionInfo) Duration(java.time.Duration) Map(java.util.Map) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) Process(io.camunda.zeebe.client.api.response.Process) ProcessInstanceResult(io.camunda.zeebe.client.api.response.ProcessInstanceResult) StreamSupport(java.util.stream.StreamSupport) PartitionBrokerHealth(io.camunda.zeebe.client.api.response.PartitionBrokerHealth) VersionUtil(io.camunda.zeebe.util.VersionUtil) Topology(io.camunda.zeebe.client.api.response.Topology) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) ZeebeFuture(io.camunda.zeebe.client.api.ZeebeFuture) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) Optional(java.util.Optional) ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse) Awaitility(org.awaitility.Awaitility) RecordStream(io.camunda.zeebe.process.test.filters.RecordStream) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) RecordStream(io.camunda.zeebe.process.test.filters.RecordStream) Record(io.camunda.zeebe.protocol.record.Record) Test(org.junit.jupiter.api.Test)

Example 4 with RecordStream

use of io.camunda.zeebe.process.test.filters.RecordStream in project zeebe-process-test by camunda-cloud.

the class ZeebeProcessTestExtension method beforeEach.

/**
 * Before each test the {@link ContainerizedEngine} is started. A client to communicate with the
 * engine will 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 Object engineContent = getStore(extensionContext.getParent().get()).get(KEY_ZEEBE_ENGINE);
    final ContainerizedEngine engine = (ContainerizedEngine) engineContent;
    engine.start();
    final ZeebeClient client = engine.createClient();
    final RecordStream recordStream = RecordStream.of(new RecordStreamSourceImpl(engine));
    BpmnAssert.initRecordStream(recordStream);
    getStore(extensionContext).put(KEY_ZEEBE_CLIENT, client);
    injectFields(extensionContext, engine, client, recordStream);
}
Also used : RecordStream(io.camunda.zeebe.process.test.filters.RecordStream) ZeebeClient(io.camunda.zeebe.client.ZeebeClient)

Example 5 with RecordStream

use of io.camunda.zeebe.process.test.filters.RecordStream in project zeebe-process-test by camunda.

the class EngineClientTest method shouldPrintRecords.

@Test
void shouldPrintRecords() {
    // given
    zeebeClient.newDeployCommand().addProcessModel(Bpmn.createExecutableProcess("simpleProcess").startEvent().endEvent().done(), "simpleProcess.bpmn").send().join();
    // when
    zeebeClient.newCreateInstanceCommand().bpmnProcessId("simpleProcess").latestVersion().variables(Map.of("test", 1)).send().join();
    // then
    final RecordStream recordStream = RecordStream.of(zeebeEngine.getRecordStreamSource());
    Awaitility.await().untilAsserted(() -> {
        final Optional<Record<ProcessInstanceRecordValue>> processRecords = StreamSupport.stream(recordStream.processInstanceRecords().spliterator(), false).filter(r -> r.getValue().getBpmnElementType() == BpmnElementType.PROCESS).filter(r -> r.getIntent() == ProcessInstanceIntent.ELEMENT_COMPLETED).findFirst();
        assertThat(processRecords).isNotEmpty();
    });
    recordStream.print(true);
}
Also used : PartitionBrokerRole(io.camunda.zeebe.client.api.response.PartitionBrokerRole) TimerIntent(io.camunda.zeebe.protocol.record.intent.TimerIntent) BeforeEach(org.junit.jupiter.api.BeforeEach) RecordType(io.camunda.zeebe.protocol.record.RecordType) ClientException(io.camunda.zeebe.client.api.command.ClientException) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobRecordValue(io.camunda.zeebe.protocol.record.value.JobRecordValue) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) TimerRecordValue(io.camunda.zeebe.protocol.record.value.TimerRecordValue) ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) Record(io.camunda.zeebe.protocol.record.Record) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PartitionInfo(io.camunda.zeebe.client.api.response.PartitionInfo) Duration(java.time.Duration) Map(java.util.Map) ActivatedJob(io.camunda.zeebe.client.api.response.ActivatedJob) Process(io.camunda.zeebe.client.api.response.Process) ProcessInstanceResult(io.camunda.zeebe.client.api.response.ProcessInstanceResult) StreamSupport(java.util.stream.StreamSupport) PartitionBrokerHealth(io.camunda.zeebe.client.api.response.PartitionBrokerHealth) VersionUtil(io.camunda.zeebe.util.VersionUtil) Topology(io.camunda.zeebe.client.api.response.Topology) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent) ZeebeFuture(io.camunda.zeebe.client.api.ZeebeFuture) BrokerInfo(io.camunda.zeebe.client.api.response.BrokerInfo) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) Optional(java.util.Optional) ActivateJobsResponse(io.camunda.zeebe.client.api.response.ActivateJobsResponse) Awaitility(org.awaitility.Awaitility) RecordStream(io.camunda.zeebe.process.test.filters.RecordStream) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) RecordStream(io.camunda.zeebe.process.test.filters.RecordStream) Record(io.camunda.zeebe.protocol.record.Record) Test(org.junit.jupiter.api.Test)

Aggregations

RecordStream (io.camunda.zeebe.process.test.filters.RecordStream)8 ZeebeClient (io.camunda.zeebe.client.ZeebeClient)6 ZeebeTestEngine (io.camunda.zeebe.process.test.api.ZeebeTestEngine)4 ZeebeFuture (io.camunda.zeebe.client.api.ZeebeFuture)2 ClientException (io.camunda.zeebe.client.api.command.ClientException)2 ActivateJobsResponse (io.camunda.zeebe.client.api.response.ActivateJobsResponse)2 ActivatedJob (io.camunda.zeebe.client.api.response.ActivatedJob)2 BrokerInfo (io.camunda.zeebe.client.api.response.BrokerInfo)2 DeploymentEvent (io.camunda.zeebe.client.api.response.DeploymentEvent)2 PartitionBrokerHealth (io.camunda.zeebe.client.api.response.PartitionBrokerHealth)2 PartitionBrokerRole (io.camunda.zeebe.client.api.response.PartitionBrokerRole)2 PartitionInfo (io.camunda.zeebe.client.api.response.PartitionInfo)2 Process (io.camunda.zeebe.client.api.response.Process)2 ProcessInstanceEvent (io.camunda.zeebe.client.api.response.ProcessInstanceEvent)2 ProcessInstanceResult (io.camunda.zeebe.client.api.response.ProcessInstanceResult)2 SetVariablesResponse (io.camunda.zeebe.client.api.response.SetVariablesResponse)2 Topology (io.camunda.zeebe.client.api.response.Topology)2 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)2 Record (io.camunda.zeebe.protocol.record.Record)2 RecordType (io.camunda.zeebe.protocol.record.RecordType)2