public static DirectBuffer asMsgPack(String json) { return new UnsafeBuffer(asMsgPackReturnArray(json)); } }
public static DirectBuffer asMsgPack(String key, Object value) { return asMsgPack(Collections.singletonMap(key, value)); }
public static void assertWorkflowInstancePayload( Record<WorkflowInstanceRecordValue> event, String expectedPayload) { final byte[] payload = MsgPackUtil.asMsgPackReturnArray(event.getValue().getPayload()); MsgPackUtil.assertEquality(payload, expectedPayload); }
/** Making sure the method is reusable and does not leave data structures dirty */ @Test public void shouldSetVariablesFromDocumentRepeatedly() { // given final long scope1 = 1; final long scope2 = 2; declareScope(scope1); declareScope(scope2); variablesState.setVariablesFromDocument(scope1, MsgPackUtil.asMsgPack("{'a': 1, 'b': 2}")); // when variablesState.setVariablesFromDocument(scope2, MsgPackUtil.asMsgPack("{'x': 3}")); // then final DirectBuffer scope1Doc = variablesState.getVariablesAsDocument(scope1); MsgPackUtil.assertEquality(scope1Doc, "{'a': 1, 'b': 2}"); final DirectBuffer scope2Doc = variablesState.getVariablesAsDocument(scope2); MsgPackUtil.assertEquality(scope2Doc, "{'x': 3}"); }
@Test public void shouldPropagatePayloadOnSplit() { // given testClient.deploy(FORK_PROCESS); final byte[] payload = BufferUtil.bufferAsArray(MsgPackUtil.asMsgPack("key", "val")); // when testClient.createWorkflowInstance(PROCESS_ID, payload); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents) .extracting(e -> MsgPackUtil.asMsgPackReturnArray(e.getValue().getPayload())) .allSatisfy(p -> p.equals(payload)); }
public static void assertEquality(DirectBuffer actualMsgPack, String expectedJson) { assertNotNull("actual msg pack is null", actualMsgPack); final byte[] msgPackArray = new byte[actualMsgPack.capacity()]; actualMsgPack.getBytes(0, msgPackArray); assertEquality(msgPackArray, expectedJson); }
public static void assertEqualityExcluding( DirectBuffer actualMsgPack, String expectedJson, String... excludedProperties) { assertNotNull("actual msg pack is null", actualMsgPack); final byte[] msgPackArray = new byte[actualMsgPack.capacity()]; actualMsgPack.getBytes(0, msgPackArray); assertEqualityExcluding(msgPackArray, expectedJson, excludedProperties); }
private byte[] stringToMsgpack(String value) { return MsgPackUtil.encodeMsgPack(b -> b.packString(value)).byteArray(); }
/** Making sure the method is reusable and does not leave data structures dirty */ @Test public void shouldSetVariablesFromDocumentRepeatedly() { // given final long scope1 = 1; final long scope2 = 2; declareScope(scope1); declareScope(scope2); variablesState.setVariablesFromDocument(scope1, MsgPackUtil.asMsgPack("{'a': 1, 'b': 2}")); // when variablesState.setVariablesFromDocument(scope2, MsgPackUtil.asMsgPack("{'x': 3}")); // then final DirectBuffer scope1Doc = variablesState.getVariablesAsDocument(scope1); MsgPackUtil.assertEquality(scope1Doc, "{'a': 1, 'b': 2}"); final DirectBuffer scope2Doc = variablesState.getVariablesAsDocument(scope2); MsgPackUtil.assertEquality(scope2Doc, "{'x': 3}"); }
@Test public void shouldPropagatePayloadOnSplit() { // given testClient.deploy(FORK_PROCESS); final byte[] payload = BufferUtil.bufferAsArray(MsgPackUtil.asMsgPack("key", "val")); // when testClient.createWorkflowInstance(PROCESS_ID, payload); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents) .extracting(e -> MsgPackUtil.asMsgPackReturnArray(e.getValue().getPayload())) .allSatisfy(p -> p.equals(payload)); }
public static void assertEquality(DirectBuffer actualMsgPack, String expectedJson) { assertNotNull("actual msg pack is null", actualMsgPack); final byte[] msgPackArray = new byte[actualMsgPack.capacity()]; actualMsgPack.getBytes(0, msgPackArray); assertEquality(msgPackArray, expectedJson); }
public static void assertEqualityExcluding( DirectBuffer actualMsgPack, String expectedJson, String... excludedProperties) { assertNotNull("actual msg pack is null", actualMsgPack); final byte[] msgPackArray = new byte[actualMsgPack.capacity()]; actualMsgPack.getBytes(0, msgPackArray); assertEqualityExcluding(msgPackArray, expectedJson, excludedProperties); }
private byte[] stringToMsgpack(String value) { return MsgPackUtil.encodeMsgPack(b -> b.packString(value)).byteArray(); }
@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}"); }
public ExecuteCommandResponse completeJob(long key, String payload) { return completeJob(key, MsgPackUtil.asMsgPackReturnArray(payload)); }
public static void assertWorkflowInstancePayload( Record<WorkflowInstanceRecordValue> event, String expectedPayload) { final byte[] payload = MsgPackUtil.asMsgPackReturnArray(event.getValue().getPayload()); MsgPackUtil.assertEquality(payload, expectedPayload); }
@Test public void shouldUpdatePayloadWhenCatchEventIsEntered() { // given testClient.deploy( Bpmn.createExecutableProcess("wf") .startEvent() .intermediateCatchEvent("catch-event") .message(b -> b.name("msg").zeebeCorrelationKey("$.id")) .done()); testClient.createWorkflowInstance("wf", asMsgPack("id", "123")); final Record<WorkflowInstanceRecordValue> catchEventEntered = testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.ELEMENT_ACTIVATED); // when updatePayload( catchEventEntered.getKey(), MsgPackUtil.asMsgPackReturnArray("{'id':'123', 'x': 1}")); testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.PAYLOAD_UPDATED); testClient.publishMessage("msg", "123", asMsgPack("y", 2)); // then final Record<WorkflowInstanceRecordValue> catchEventOccurred = testClient.receiveFirstWorkflowInstanceEvent(WorkflowInstanceIntent.ELEMENT_COMPLETED); assertWorkflowInstancePayload(catchEventOccurred, "{'id':'123', 'x': 1, 'y': 2}"); }
public static DirectBuffer asMsgPack(String key, Object value) { return asMsgPack(Collections.singletonMap(key, value)); }
@Test public void shouldCollectNoVariablesAsEmptyDocument() { // given final long scopeKey = 1; declareScope(scopeKey); // when final DirectBuffer variablesDocument = variablesState.getVariablesAsDocument(scopeKey); // then MsgPackUtil.assertEquality(variablesDocument, "{}"); }
@Test public void shouldWriteEntireEventOnCancel() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); final io.zeebe.exporter.record.Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId(PROCESS_ID) .getFirst(); // when final ExecuteCommandResponse response = cancelWorkflowInstance(workflowInstanceKey); // then MsgPackUtil.assertEqualityExcluding( response.getRawValue(), activatedEvent.getValue().toJson(), "payload"); final io.zeebe.exporter.record.Record<WorkflowInstanceRecordValue> cancelingEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_TERMINATING) .withElementId(PROCESS_ID) .getFirst(); assertThat(cancelingEvent.getValue()).isEqualTo(activatedEvent.getValue()); }