@Test public void operationWithPlainInputStreamOutput() throws Exception { when(outputModel.getType()).thenReturn(typeLoader.load(InputStream.class)); when(componentModel.supportsStreaming()).thenReturn(true); assertStreamIsWrapped(new ByteArrayInputStream(HELLO_WORLD_MSG.getBytes(UTF_8))); }
@Test public void operationWithResultInputStreamOutput() throws Exception { when(outputModel.getType()).thenReturn(typeLoader.load(InputStream.class)); when(componentModel.supportsStreaming()).thenReturn(true); assertStreamIsWrapped(Result.builder().output(new ByteArrayInputStream(HELLO_WORLD_MSG.getBytes(UTF_8))).build()); }
@Test public void operationWithResultInputStreamCollectionOutput() throws Exception { MetadataType metadataType = BaseTypeBuilder.create(JAVA).arrayType().of(new MessageMetadataTypeBuilder().build()).build(); when(outputModel.getType()).thenReturn(metadataType); when(componentModel.supportsStreaming()).thenReturn(true); delegate = createReturnDelegate(); List<Result> resultList = new ArrayList<>(); resultList.add(Result.builder().output(new ByteArrayInputStream(HELLO_WORLD_MSG.getBytes(UTF_8))).build()); CoreEvent result = delegate.asReturnValue(resultList, operationContext); Message message = getOutputMessage(result); Message message1 = ((ResultsToMessageList) message.getPayload().getValue()).get(0); ManagedCursorStreamProvider actual = (ManagedCursorStreamProvider) message1.getPayload().getValue(); InputStream resultingStream = actual.openCursor(); assertThat(IOUtils.toString(resultingStream), is(HELLO_WORLD_MSG)); resultingStream.close(); actual.releaseResources(); disposeStreamingManager(); probe(5000, 500, () -> { verify(connectionHandler, atLeastOnce()).release(); return true; }); }