Search in sources :

Example 1 with PublishMessageClient

use of io.camunda.zeebe.engine.util.client.PublishMessageClient in project zeebe by camunda.

the class MessageCorrelationTest method shouldCorrelateMessageOnlyOnceIfEnteredBefore.

@Test
public void shouldCorrelateMessageOnlyOnceIfEnteredBefore() {
    // given
    engine.deployment().withXmlResource(TWO_MESSAGES_PROCESS).deploy();
    engine.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable("key", "123").create();
    // when
    assertThat(RecordingExporter.processMessageSubscriptionRecords(ProcessMessageSubscriptionIntent.CREATED).exists()).isTrue();
    final PublishMessageClient messageClient = engine.message().withName("ping").withCorrelationKey("123");
    messageClient.withVariables(asMsgPack("nr", 1)).publish();
    assertThat(RecordingExporter.processMessageSubscriptionRecords(ProcessMessageSubscriptionIntent.CREATED).limit(2).count()).isEqualTo(2);
    messageClient.withVariables(asMsgPack("nr", 2)).publish();
    // then
    final List<Object> correlatedValues = RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).filter(r -> r.getValue().getElementId().startsWith("message")).limit(2).map(event -> tuple(event.getValue().getElementId(), ProcessInstances.getCurrentVariables(event.getValue().getProcessInstanceKey(), event.getPosition()).get("nr"))).collect(Collectors.toList());
    assertThat(correlatedValues).contains(tuple("message1", "1"), tuple("message2", "2"));
}
Also used : RecordType(io.camunda.zeebe.protocol.record.RecordType) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) MessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent) Record(io.camunda.zeebe.protocol.record.Record) ProcessMessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.ProcessMessageSubscriptionIntent) Duration(java.time.Duration) Map(java.util.Map) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ProcessMessageSubscriptionRecordValue(io.camunda.zeebe.protocol.record.value.ProcessMessageSubscriptionRecordValue) MsgPackUtil.asMsgPack(io.camunda.zeebe.test.util.MsgPackUtil.asMsgPack) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Test(org.junit.Test) UUID(java.util.UUID) Assertions.entry(org.assertj.core.api.Assertions.entry) Collectors(java.util.stream.Collectors) Assertions(io.camunda.zeebe.protocol.record.Assertions) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) List(java.util.List) ProcessInstances(io.camunda.zeebe.test.util.record.ProcessInstances) Rule(org.junit.Rule) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) Test(org.junit.Test)

Example 2 with PublishMessageClient

use of io.camunda.zeebe.engine.util.client.PublishMessageClient in project zeebe by camunda.

the class MessageCorrelationTest method shouldCorrelateOnlyOneMessagePerCatchElement.

@Test
public void shouldCorrelateOnlyOneMessagePerCatchElement() {
    // given
    engine.deployment().withXmlResource(TWO_MESSAGES_PROCESS).deploy();
    engine.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable("key", "123").create();
    assertThat(RecordingExporter.processMessageSubscriptionRecords(ProcessMessageSubscriptionIntent.CREATED).exists()).isTrue();
    // when
    final PublishMessageClient messageClient = engine.message().withName("ping").withCorrelationKey("123");
    messageClient.withVariables(asMsgPack("nr", 1)).publish();
    messageClient.withVariables(asMsgPack("nr", 2)).publish();
    // then
    final List<Object> correlatedValues = RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).filter(r -> r.getValue().getElementId().startsWith("message")).limit(2).map(event -> tuple(event.getValue().getElementId(), ProcessInstances.getCurrentVariables(event.getValue().getProcessInstanceKey(), event.getPosition()).get("nr"))).collect(Collectors.toList());
    assertThat(correlatedValues).contains(tuple("message1", "1"), tuple("message2", "2"));
}
Also used : RecordType(io.camunda.zeebe.protocol.record.RecordType) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) MessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent) Record(io.camunda.zeebe.protocol.record.Record) ProcessMessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.ProcessMessageSubscriptionIntent) Duration(java.time.Duration) Map(java.util.Map) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ProcessMessageSubscriptionRecordValue(io.camunda.zeebe.protocol.record.value.ProcessMessageSubscriptionRecordValue) MsgPackUtil.asMsgPack(io.camunda.zeebe.test.util.MsgPackUtil.asMsgPack) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Test(org.junit.Test) UUID(java.util.UUID) Assertions.entry(org.assertj.core.api.Assertions.entry) Collectors(java.util.stream.Collectors) Assertions(io.camunda.zeebe.protocol.record.Assertions) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) List(java.util.List) ProcessInstances(io.camunda.zeebe.test.util.record.ProcessInstances) Rule(org.junit.Rule) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) Test(org.junit.Test)

Example 3 with PublishMessageClient

use of io.camunda.zeebe.engine.util.client.PublishMessageClient in project zeebe by camunda.

the class MessageCorrelationTest method shouldCorrelateFirstPublishedMessage.

@Test
public void shouldCorrelateFirstPublishedMessage() {
    // given
    engine.deployment().withXmlResource(SINGLE_MESSAGE_PROCESS).deploy();
    final PublishMessageClient messageClient = engine.message().withName("message").withCorrelationKey("order-123");
    messageClient.withVariables(asMsgPack("nr", 1)).publish();
    messageClient.withVariables(asMsgPack("nr", 2)).publish();
    // when
    final long processInstanceKey = engine.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable("key", "order-123").create();
    // then
    final Record<ProcessInstanceRecordValue> event = RecordingExporter.processInstanceRecords().withElementType(BpmnElementType.PROCESS).withIntent(ProcessInstanceIntent.ELEMENT_COMPLETED).getFirst();
    final Map<String, String> variables = ProcessInstances.getCurrentVariables(processInstanceKey, event.getPosition());
    assertThat(variables).containsOnly(entry("key", "\"order-123\""), entry("nr", "1"));
}
Also used : PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) Test(org.junit.Test)

Example 4 with PublishMessageClient

use of io.camunda.zeebe.engine.util.client.PublishMessageClient in project zeebe by zeebe-io.

the class MessageCorrelationTest method shouldCorrelateMessageOnlyOnceIfPublishedBefore.

@Test
public void shouldCorrelateMessageOnlyOnceIfPublishedBefore() {
    // given
    engine.deployment().withXmlResource(TWO_MESSAGES_PROCESS).deploy();
    final PublishMessageClient messageClient = engine.message().withName("ping").withCorrelationKey("123");
    messageClient.withVariables(asMsgPack("nr", 1)).publish();
    messageClient.withVariables(asMsgPack("nr", 2)).publish();
    // when
    engine.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable("key", "123").create();
    // then
    final List<Object> correlatedValues = RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).filter(r -> r.getValue().getElementId().startsWith("message")).limit(2).map(event -> tuple(event.getValue().getElementId(), ProcessInstances.getCurrentVariables(event.getValue().getProcessInstanceKey(), event.getPosition()).get("nr"))).collect(Collectors.toList());
    assertThat(correlatedValues).contains(tuple("message1", "1"), tuple("message2", "2"));
}
Also used : RecordType(io.camunda.zeebe.protocol.record.RecordType) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) MessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent) Record(io.camunda.zeebe.protocol.record.Record) ProcessMessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.ProcessMessageSubscriptionIntent) Duration(java.time.Duration) Map(java.util.Map) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ProcessMessageSubscriptionRecordValue(io.camunda.zeebe.protocol.record.value.ProcessMessageSubscriptionRecordValue) MsgPackUtil.asMsgPack(io.camunda.zeebe.test.util.MsgPackUtil.asMsgPack) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Test(org.junit.Test) UUID(java.util.UUID) Assertions.entry(org.assertj.core.api.Assertions.entry) Collectors(java.util.stream.Collectors) Assertions(io.camunda.zeebe.protocol.record.Assertions) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) List(java.util.List) ProcessInstances(io.camunda.zeebe.test.util.record.ProcessInstances) Rule(org.junit.Rule) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) Test(org.junit.Test)

Example 5 with PublishMessageClient

use of io.camunda.zeebe.engine.util.client.PublishMessageClient in project zeebe by zeebe-io.

the class MessageCorrelationTest method shouldCorrelateMessageOnlyOnceToInstance.

@Test
public void shouldCorrelateMessageOnlyOnceToInstance() {
    // given
    engine.deployment().withXmlResource(Bpmn.createExecutableProcess(PROCESS_ID).startEvent().parallelGateway().intermediateCatchEvent("message1").message(m -> m.name("ping").zeebeCorrelationKeyExpression("key")).moveToLastGateway().intermediateCatchEvent("message2").message(m -> m.name("ping").zeebeCorrelationKeyExpression("key")).done()).deploy();
    engine.processInstance().ofBpmnProcessId(PROCESS_ID).withVariable("key", "123").create();
    // when
    assertThat(RecordingExporter.processMessageSubscriptionRecords(ProcessMessageSubscriptionIntent.CREATED).limit(2).count()).isEqualTo(2);
    final PublishMessageClient client = engine.message().withName("ping").withCorrelationKey("123");
    client.withVariables(asMsgPack("nr", 1)).publish();
    client.withVariables(asMsgPack("nr", 2)).publish();
    // then
    final List<Object> correlatedValues = RecordingExporter.processInstanceRecords(ProcessInstanceIntent.ELEMENT_COMPLETED).filter(r -> r.getValue().getElementId().startsWith("message")).limit(2).map(event -> ProcessInstances.getCurrentVariables(event.getValue().getProcessInstanceKey(), event.getPosition()).get("nr")).collect(Collectors.toList());
    assertThat(correlatedValues).contains("1", "2");
}
Also used : RecordType(io.camunda.zeebe.protocol.record.RecordType) ProcessInstanceIntent(io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Bpmn(io.camunda.zeebe.model.bpmn.Bpmn) MessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent) Record(io.camunda.zeebe.protocol.record.Record) ProcessMessageSubscriptionIntent(io.camunda.zeebe.protocol.record.intent.ProcessMessageSubscriptionIntent) Duration(java.time.Duration) Map(java.util.Map) EngineRule(io.camunda.zeebe.engine.util.EngineRule) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ProcessMessageSubscriptionRecordValue(io.camunda.zeebe.protocol.record.value.ProcessMessageSubscriptionRecordValue) MsgPackUtil.asMsgPack(io.camunda.zeebe.test.util.MsgPackUtil.asMsgPack) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Test(org.junit.Test) UUID(java.util.UUID) Assertions.entry(org.assertj.core.api.Assertions.entry) Collectors(java.util.stream.Collectors) Assertions(io.camunda.zeebe.protocol.record.Assertions) RecordingExporter(io.camunda.zeebe.test.util.record.RecordingExporter) List(java.util.List) ProcessInstances(io.camunda.zeebe.test.util.record.ProcessInstances) Rule(org.junit.Rule) ProcessInstanceRecordValue(io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) JobIntent(io.camunda.zeebe.protocol.record.intent.JobIntent) PublishMessageClient(io.camunda.zeebe.engine.util.client.PublishMessageClient) Test(org.junit.Test)

Aggregations

PublishMessageClient (io.camunda.zeebe.engine.util.client.PublishMessageClient)18 ProcessInstanceRecordValue (io.camunda.zeebe.protocol.record.value.ProcessInstanceRecordValue)18 Test (org.junit.Test)18 EngineRule (io.camunda.zeebe.engine.util.EngineRule)15 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)15 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)15 Assertions (io.camunda.zeebe.protocol.record.Assertions)15 Record (io.camunda.zeebe.protocol.record.Record)15 RecordType (io.camunda.zeebe.protocol.record.RecordType)15 JobIntent (io.camunda.zeebe.protocol.record.intent.JobIntent)15 MessageSubscriptionIntent (io.camunda.zeebe.protocol.record.intent.MessageSubscriptionIntent)15 ProcessInstanceIntent (io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent)15 ProcessMessageSubscriptionIntent (io.camunda.zeebe.protocol.record.intent.ProcessMessageSubscriptionIntent)15 BpmnElementType (io.camunda.zeebe.protocol.record.value.BpmnElementType)15 ProcessMessageSubscriptionRecordValue (io.camunda.zeebe.protocol.record.value.ProcessMessageSubscriptionRecordValue)15 MsgPackUtil.asMsgPack (io.camunda.zeebe.test.util.MsgPackUtil.asMsgPack)15 ProcessInstances (io.camunda.zeebe.test.util.record.ProcessInstances)15 RecordingExporter (io.camunda.zeebe.test.util.record.RecordingExporter)15 Duration (java.time.Duration)15 List (java.util.List)15