private byte[] loadResource(String resourceName) { try (InputStream resourceAsStream = DebugHttpServer.class.getResourceAsStream(resourceName)) { if (resourceAsStream != null) { return StreamUtil.read(resourceAsStream); } else { throw new RuntimeException( "Failed to find resource " + resourceName + " for debug http exporter"); } } catch (IOException e) { throw new RuntimeException( "Failed to read resource " + resourceName + " for debug http exporter", e); } }
private byte[] loadResource(String resourceName) { try (InputStream resourceAsStream = DebugHttpServer.class.getResourceAsStream(resourceName)) { if (resourceAsStream != null) { return StreamUtil.read(resourceAsStream); } else { throw new RuntimeException( "Failed to find resource " + resourceName + " for debug http exporter"); } } catch (IOException e) { throw new RuntimeException( "Failed to read resource " + resourceName + " for debug http exporter", e); } }
@Override public void recoverFromSnapshot(InputStream inputStream) throws Exception { final byte[] byteArray = StreamUtil.read(inputStream); indexBuffer.putBytes(0, byteArray); }
@Override public void recoverFromSnapshot(InputStream inputStream) throws Exception { final byte[] byteArray = StreamUtil.read(inputStream); indexBuffer.putBytes(0, byteArray); }
@Override public DeployWorkflowCommandBuilderStep2 addResourceStream( final InputStream resourceStream, final String resourceName) { ensureNotNull("resource stream", resourceStream); try { final byte[] bytes = StreamUtil.read(resourceStream); return addResourceBytes(bytes, resourceName); } catch (final IOException e) { final String exceptionMsg = String.format("Cannot deploy bpmn resource from stream. %s", e.getMessage()); throw new ClientException(exceptionMsg, e); } }
@Override public DeployWorkflowCommandBuilderStep2 addResourceStream( final InputStream resourceStream, final String resourceName) { ensureNotNull("resource stream", resourceStream); try { final byte[] bytes = StreamUtil.read(resourceStream); return addResourceBytes(bytes, resourceName); } catch (final IOException e) { final String exceptionMsg = String.format("Cannot deploy bpmn resource from stream. %s", e.getMessage()); throw new ClientException(exceptionMsg, e); } }
public static boolean canRead(final File file, final MessageDigest messageDigest) { boolean isReadable = false; final File checksum = new File(file.getAbsolutePath() + "." + messageDigest.getAlgorithm().toLowerCase()); if (file.exists() && checksum.exists()) { String checksumDigest = null; String checksumFileName = null; try (InputStream is = new FileInputStream(checksum)) { final byte[] data = new byte[(int) checksum.length()]; read(is, data); final String content = fromBytes(data); final String[] parts = content.split(" "); checksumDigest = parts[0]; checksumFileName = parts[1]; } catch (final IOException e) { // ignore } if (checksumFileName.equals(file.getName())) { try (InputStream is = new FileInputStream(file)) { updateDigest(messageDigest, is); } catch (final IOException e) { // ignore } final String digest = digestAsHex(messageDigest); isReadable = digest.equals(checksumDigest); } } return isReadable; }
public static boolean canRead(final File file, final MessageDigest messageDigest) { boolean isReadable = false; final File checksum = new File(file.getAbsolutePath() + "." + messageDigest.getAlgorithm().toLowerCase()); if (file.exists() && checksum.exists()) { String checksumDigest = null; String checksumFileName = null; try (InputStream is = new FileInputStream(checksum)) { final byte[] data = new byte[(int) checksum.length()]; read(is, data); final String content = fromBytes(data); final String[] parts = content.split(" "); checksumDigest = parts[0]; checksumFileName = parts[1]; } catch (final IOException e) { // ignore } if (checksumFileName.equals(file.getName())) { try (InputStream is = new FileInputStream(file)) { updateDigest(messageDigest, is); } catch (final IOException e) { // ignore } final String digest = digestAsHex(messageDigest); isReadable = digest.equals(checksumDigest); } } return isReadable; }
public static int read( final InputStream input, final MutableDirectBuffer buffer, final int offset) throws IOException { int bytesRead; if (buffer.byteArray() == null) { throw new RuntimeException("Cannot be used with direct byte buffers"); } int writeOffset = offset; do { buffer.checkLimit( offset + DEFAULT_BUFFER_SIZE); // for expandable buffers, this triggers expansion bytesRead = input.read(buffer.byteArray(), writeOffset, DEFAULT_BUFFER_SIZE); if (bytesRead > 0) { writeOffset += bytesRead; } } while (bytesRead >= 0); return writeOffset - offset; }
public static int read( final InputStream input, final MutableDirectBuffer buffer, final int offset) throws IOException { int bytesRead; if (buffer.byteArray() == null) { throw new RuntimeException("Cannot be used with direct byte buffers"); } int writeOffset = offset; do { buffer.checkLimit( offset + DEFAULT_BUFFER_SIZE); // for expandable buffers, this triggers expansion bytesRead = input.read(buffer.byteArray(), writeOffset, DEFAULT_BUFFER_SIZE); if (bytesRead > 0) { writeOffset += bytesRead; } } while (bytesRead >= 0); return writeOffset - offset; }
@Test public void shouldCreateDeploymentResourceWithCollaboration() throws IOException { // given final InputStream resourceAsStream = getClass().getResourceAsStream("/workflows/collaboration.bpmn"); // when final ExecuteCommandResponse resp = apiRule .partitionClient() .deployWithResponse( StreamUtil.read(resourceAsStream), ResourceType.BPMN_XML.name(), "collaboration.bpmn"); // then assertThat(resp.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(resp.getIntent()).isEqualTo(DeploymentIntent.CREATED); final List<Map<String, Object>> deployedWorkflows = Arrays.asList(getDeployedWorkflow(resp, 0), getDeployedWorkflow(resp, 1)); assertThat(deployedWorkflows) .extracting(s -> s.get(WorkflowInstanceRecord.PROP_WORKFLOW_BPMN_PROCESS_ID)) .contains("process1", "process2"); }
@Test public void shouldCreateDeploymentResourceWithCollaboration() throws IOException { // given final InputStream resourceAsStream = getClass().getResourceAsStream("/workflows/collaboration.bpmn"); // when final ExecuteCommandResponse resp = apiRule .partitionClient() .deployWithResponse( StreamUtil.read(resourceAsStream), ResourceType.BPMN_XML.name(), "collaboration.bpmn"); // then assertThat(resp.getRecordType()).isEqualTo(RecordType.EVENT); assertThat(resp.getIntent()).isEqualTo(DeploymentIntent.CREATED); final List<Map<String, Object>> deployedWorkflows = Arrays.asList(getDeployedWorkflow(resp, 0), getDeployedWorkflow(resp, 1)); assertThat(deployedWorkflows) .extracting(s -> s.get(WorkflowInstanceRecord.PROP_WORKFLOW_BPMN_PROCESS_ID)) .contains("process1", "process2"); }
@Test public void shouldCreateWorkflowInstanceOfCollaboration() throws IOException { final InputStream resourceAsStream = getClass().getResourceAsStream("/workflows/collaboration.bpmn"); apiRule .partitionClient() .deployWithResponse( StreamUtil.read(resourceAsStream), ResourceType.BPMN_XML.name(), "collaboration.bpmn"); // when final long wfInstance1 = testClient.createWorkflowInstance("process1"); final long wfInstance2 = testClient.createWorkflowInstance("process2"); // then final Record<WorkflowInstanceRecordValue> event1 = testClient.receiveFirstWorkflowInstanceEvent( wfInstance1, WorkflowInstanceIntent.ELEMENT_READY); assertThat(event1.getValue().getBpmnProcessId()).isEqualTo("process1"); final Record<WorkflowInstanceRecordValue> event2 = testClient.receiveFirstWorkflowInstanceEvent( wfInstance2, WorkflowInstanceIntent.ELEMENT_READY); assertThat(event2.getValue().getBpmnProcessId()).isEqualTo("process2"); }
@Test public void shouldCreateWorkflowInstanceOfCollaboration() throws IOException { final InputStream resourceAsStream = getClass().getResourceAsStream("/workflows/collaboration.bpmn"); apiRule .partitionClient() .deployWithResponse( StreamUtil.read(resourceAsStream), ResourceType.BPMN_XML.name(), "collaboration.bpmn"); // when final long wfInstance1 = testClient.createWorkflowInstance("process1"); final long wfInstance2 = testClient.createWorkflowInstance("process2"); // then final Record<WorkflowInstanceRecordValue> event1 = testClient.receiveFirstWorkflowInstanceEvent( wfInstance1, WorkflowInstanceIntent.ELEMENT_ACTIVATING); assertThat(event1.getValue().getBpmnProcessId()).isEqualTo("process1"); final Record<WorkflowInstanceRecordValue> event2 = testClient.receiveFirstWorkflowInstanceEvent( wfInstance2, WorkflowInstanceIntent.ELEMENT_ACTIVATING); assertThat(event2.getValue().getBpmnProcessId()).isEqualTo("process2"); }
@Test public void shouldCreateInstanceOfYamlWorkflow() throws Exception { // given final InputStream resourceAsStream = getClass().getResourceAsStream("/workflows/simple-workflow.yaml"); apiRule .partitionClient() .deployWithResponse( StreamUtil.read(resourceAsStream), ResourceType.YAML_WORKFLOW.name(), "simple-workflow.yaml"); // when final long workflowInstanceKey = testClient.createWorkflowInstance("yaml-workflow"); // then final Record<WorkflowInstanceRecordValue> workflowInstanceEvent = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_READY) .getFirst(); assertWorkflowInstanceRecord( "yaml-workflow", 1, workflowInstanceKey, "yaml-workflow", workflowInstanceEvent); }
@Test public void shouldCreateInstanceOfYamlWorkflow() throws Exception { // given final InputStream resourceAsStream = getClass().getResourceAsStream("/workflows/simple-workflow.yaml"); apiRule .partitionClient() .deployWithResponse( StreamUtil.read(resourceAsStream), ResourceType.YAML_WORKFLOW.name(), "simple-workflow.yaml"); // when final long workflowInstanceKey = testClient.createWorkflowInstance("yaml-workflow"); // then final Record<WorkflowInstanceRecordValue> workflowInstanceEvent = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATING) .getFirst(); assertWorkflowInstanceRecord( "yaml-workflow", 1, workflowInstanceKey, "yaml-workflow", workflowInstanceEvent); }