public static DirectBuffer asMsgPack(String key, Object value) { return asMsgPack(Collections.singletonMap(key, value)); }
public static DirectBuffer asMsgPack(Consumer<MapBuilder<DirectBuffer>> consumer) { final DirectBuffer buffer = new UnsafeBuffer(0, 0); final MapBuilder<DirectBuffer> builder = new MapBuilder<>(buffer, map -> buffer.wrap(asMsgPack(map))); consumer.accept(builder); return builder.done(); }
public static DirectBuffer asMsgPack(Consumer<MapBuilder<DirectBuffer>> consumer) { final DirectBuffer buffer = new UnsafeBuffer(0, 0); final MapBuilder<DirectBuffer> builder = new MapBuilder<>(buffer, map -> buffer.wrap(asMsgPack(map))); consumer.accept(builder); return builder.done(); }
@Test public void shouldCorrelateFirstPublishedMessage() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); testClient.publishMessage("message", "order-123", asMsgPack("nr", 1)); testClient.publishMessage("message", "order-123", asMsgPack("nr", 2)); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); // then final Record<WorkflowInstanceRecordValue> event = testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.ELEMENT_COMPLETED); assertWorkflowInstancePayload(event, "{'key':'order-123', 'nr':1}"); }
@Test public void shouldCorrelateMessageIfCorrelationKeyIsANumber() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); testClient.publishMessage("message", "123", asMsgPack("foo", "bar")); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", 123)); // then final Record<WorkflowInstanceRecordValue> event = testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.ELEMENT_COMPLETED); assertWorkflowInstancePayload(event, "{'key':123, 'foo':'bar'}"); }
@Test public void shouldCorrelateMessageIfPublishedBefore() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); testClient.publishMessage("message", "order-123", asMsgPack("foo", "bar")); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); // then final Record<WorkflowInstanceRecordValue> event = testClient.receiveElementInState("receive-message", WorkflowInstanceIntent.EVENT_TRIGGERED); assertWorkflowInstancePayload(event, "{'key':'order-123', 'foo':'bar'}"); }
@Test public void shouldCorrelateMessageIfPublishedBefore() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); testClient.publishMessage("message", "order-123", asMsgPack("foo", "bar")); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "order-123")); // then final Record<WorkflowInstanceRecordValue> event = testClient.receiveElementInState( "receive-message", WorkflowInstanceIntent.ELEMENT_COMPLETED); assertWorkflowInstancePayload(event, "{'key':'order-123', 'foo':'bar'}"); }
@Test public void shouldCorrelateMessageIfCorrelationKeyIsANumber() { // given testClient.deploy(SINGLE_MESSAGE_WORKFLOW); testClient.publishMessage("message", "123", asMsgPack("foo", "bar")); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", 123)); // then final Record<WorkflowInstanceRecordValue> event = testClient.receiveFirstWorkflowInstanceEvent( WorkflowInstanceIntent.ELEMENT_COMPLETED, BpmnElementType.PROCESS); assertWorkflowInstancePayload(event, "{'key':123, 'foo':'bar'}"); }
@Test public void shouldOverwriteLocalVariableFromDocument() { // given final long scope = 1; declareScope(scope); variablesState.setVariableLocal(scope, BufferUtil.wrapString("a"), MsgPackUtil.asMsgPack("1")); final DirectBuffer document = MsgPackUtil.asMsgPack("a", 2); // when variablesState.setVariablesLocalFromDocument(scope, document); // then final DirectBuffer varA = variablesState.getVariableLocal(scope, BufferUtil.wrapString("a")); MsgPackUtil.assertEquality(varA, "2"); }
@Test public void shouldCollectVariablesAsDocument() { // given final long scopeKey = 1; declareScope(scopeKey); final DirectBuffer var1Value = MsgPackUtil.asMsgPack("a", 1); variablesState.setVariableLocal(scopeKey, BufferUtil.wrapString("var1"), var1Value); final DirectBuffer var2Value = MsgPackUtil.asMsgPack("x", 10); variablesState.setVariableLocal(scopeKey, BufferUtil.wrapString("var2"), var2Value); // when final DirectBuffer variablesDocument = variablesState.getVariablesAsDocument(scopeKey); // then MsgPackUtil.assertEquality(variablesDocument, "{'var1': {'a': 1}, 'var2': {'x': 10}}"); }
@Test public void shouldSetLocalVariableFromDocumentAsObject() { // given final long scope = 1; declareScope(scope); final DirectBuffer document = MsgPackUtil.asMsgPack(b -> b.put("var", Collections.singletonMap("a", 1))); // when variablesState.setVariablesLocalFromDocument(scope, document); // then final DirectBuffer varA = variablesState.getVariableLocal(scope, BufferUtil.wrapString("var")); MsgPackUtil.assertEquality(varA, "{'a': 1}"); }
@Test public void shouldSetVariablesFromDocumentAsObject() { // given final long scope = 1; declareScope(scope); final DirectBuffer document = MsgPackUtil.asMsgPack(b -> b.put("a", Collections.singletonMap("x", 1))); // when variablesState.setVariablesFromDocument(scope, document); // then final DirectBuffer varA = variablesState.getVariableLocal(scope, BufferUtil.wrapString("a")); MsgPackUtil.assertEquality(varA, "{'x': 1}"); }
@Test public void shouldSetLocalVariableFromDocumentAsObject() { // given final long scope = 1; declareScope(scope); final DirectBuffer document = MsgPackUtil.asMsgPack(b -> b.put("var", Collections.singletonMap("a", 1))); // when variablesState.setVariablesLocalFromDocument(scope, document); // then final DirectBuffer varA = variablesState.getVariableLocal(scope, BufferUtil.wrapString("var")); MsgPackUtil.assertEquality(varA, "{'a': 1}"); }
@Test public void shouldCollectLocalVariables() { // given final long parent = 1; final long child = 2; declareScope(parent); declareScope(parent, child); variablesState.setVariableLocal(parent, BufferUtil.wrapString("a"), MsgPackUtil.asMsgPack("1")); variablesState.setVariableLocal(child, BufferUtil.wrapString("b"), MsgPackUtil.asMsgPack("3")); // then MsgPackUtil.assertEquality(variablesState.getVariablesLocalAsDocument(parent), "{'a': 1}"); MsgPackUtil.assertEquality(variablesState.getVariablesLocalAsDocument(child), "{'b': 3}"); }
@Test public void shouldCollectOnlyExistingVariablesByName() { // given final long scope = 1; declareScope(scope); variablesState.setVariableLocal(scope, BufferUtil.wrapString("a"), MsgPackUtil.asMsgPack("1")); // when final DirectBuffer variablesDocument = variablesState.getVariablesAsDocument( scope, Arrays.asList(BufferUtil.wrapString("a"), BufferUtil.wrapString("c"))); // then MsgPackUtil.assertEquality(variablesDocument, "{'a': 1}"); }
@Test public void shouldCollectOnlyExistingVariablesByName() { // given final long scope = 1; declareScope(scope); variablesState.setVariableLocal(scope, BufferUtil.wrapString("a"), MsgPackUtil.asMsgPack("1")); // when final DirectBuffer variablesDocument = variablesState.getVariablesAsDocument( scope, Arrays.asList(BufferUtil.wrapString("a"), BufferUtil.wrapString("c"))); // then MsgPackUtil.assertEquality(variablesDocument, "{'a': 1}"); }
private MessageRecord message() { final MessageRecord message = new MessageRecord(); message .setName(wrapString("order canceled")) .setCorrelationKey(wrapString("order-123")) .setTimeToLive(1L) .setPayload(asMsgPack("orderId", "order-123")); return message; }
private MessageRecord message() { final MessageRecord message = new MessageRecord(); message .setName(wrapString("order canceled")) .setCorrelationKey(wrapString("order-123")) .setTimeToLive(1L) .setPayload(asMsgPack("orderId", "order-123")); return message; }
@Test public void shouldSetLocalVariablesFromDocument() { // given final long scope = 1; declareScope(scope); final DirectBuffer document = MsgPackUtil.asMsgPack(b -> b.put("a", 1).put("b", 2)); // when variablesState.setVariablesLocalFromDocument(scope, document); // then final DirectBuffer varA = variablesState.getVariableLocal(scope, BufferUtil.wrapString("a")); MsgPackUtil.assertEquality(varA, "1"); final DirectBuffer varB = variablesState.getVariableLocal(scope, BufferUtil.wrapString("b")); MsgPackUtil.assertEquality(varB, "2"); }
@Test public void shouldCreateJobForServiceTaskInEmbeddedSubprocess() { // given testClient.deploy(ONE_TASK_SUBPROCESS); final byte[] payload = BufferUtil.bufferAsArray(MsgPackUtil.asMsgPack("key", "val")); // when testClient.createWorkflowInstance(PROCESS_ID, payload); // then final Record<JobRecordValue> jobCreatedEvent = testClient.receiveFirstJobEvent(JobIntent.CREATED); MsgPackUtil.assertEquality(payload, jobCreatedEvent.getValue().getPayload()); final Headers headers = jobCreatedEvent.getValue().getHeaders(); Assertions.assertThat(headers).hasElementId("subProcessTask"); }