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"));
}
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"));
}
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"));
}
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"));
}
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");
}
Aggregations