Search in sources :

Example 6 with CursorStream

use of org.mule.runtime.api.streaming.bytes.CursorStream in project mule by mulesoft.

the class ReconnectionWithStreamingTestCase method createMockCursor.

private CursorStream createMockCursor() throws IOException {
    CursorStream cursorStream = mock(CursorStream.class);
    when(cursorStream.getPosition()).thenReturn(ORIGINAL_POSITION);
    when(cursorStream.read(any(byte[].class), anyInt(), anyInt())).thenThrow(new RuntimeException(new ConnectionException("kaboom"))).thenAnswer(i -> {
        byte[] buffer = (byte[]) i.getArguments()[0];
        buffer[0] = 'h';
        buffer[1] = 'n';
        return 2;
    }).thenReturn(-1);
    return cursorStream;
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) AbstractExtensionFunctionalTestCase(org.mule.test.module.extension.AbstractExtensionFunctionalTestCase) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) Matchers.any(org.mockito.Matchers.any) List(java.util.List) ConnectionException(org.mule.runtime.api.connection.ConnectionException) CursorStream(org.mule.runtime.api.streaming.bytes.CursorStream) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Matchers.anyInt(org.mockito.Matchers.anyInt) Mockito.mock(org.mockito.Mockito.mock) ConnectionException(org.mule.runtime.api.connection.ConnectionException) CursorStream(org.mule.runtime.api.streaming.bytes.CursorStream)

Example 7 with CursorStream

use of org.mule.runtime.api.streaming.bytes.CursorStream in project mule by mulesoft.

the class DrStrangeOperations method seekStream.

@MediaType(TEXT_PLAIN)
public String seekStream(@Config DrStrange dr, @Optional(defaultValue = PAYLOAD) InputStream stream, int position) throws IOException {
    checkArgument(stream instanceof CursorStream, "Stream was not cursored");
    CursorStream cursor = (CursorStream) stream;
    cursor.seek(position);
    return readStream(dr, cursor);
}
Also used : CursorStream(org.mule.runtime.api.streaming.bytes.CursorStream) MediaType(org.mule.runtime.extension.api.annotation.param.MediaType)

Aggregations

CursorStream (org.mule.runtime.api.streaming.bytes.CursorStream)7 Test (org.junit.Test)4 CursorStreamProvider (org.mule.runtime.api.streaming.bytes.CursorStreamProvider)3 IOException (java.io.IOException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 List (java.util.List)1 CoreMatchers.instanceOf (org.hamcrest.CoreMatchers.instanceOf)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 Matchers.hasSize (org.hamcrest.Matchers.hasSize)1 Assert.assertThat (org.junit.Assert.assertThat)1 Matchers.any (org.mockito.Matchers.any)1 Matchers.anyInt (org.mockito.Matchers.anyInt)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 CollectionDataType (org.mule.runtime.api.metadata.CollectionDataType)1 DataType (org.mule.runtime.api.metadata.DataType)1