Search in sources :

Example 1 with CursorStream

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

the class CustomJavaSerializationProtocol method doSerialize.

/**
 * {@inheritDoc}
 */
@Override
protected byte[] doSerialize(Object object) throws Exception {
    // TODO: MULE-11939
    if (object instanceof CursorStreamProvider) {
        try (CursorStream cursor = ((CursorStreamProvider) object).openCursor()) {
            object = toByteArray(cursor);
        }
    }
    validateForSerialization(object);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(512);
    try (ObjectOutputStream out = new ArtifactClassLoaderObjectOutputStream(classLoaderRepository, outputStream)) {
        out.writeObject(object);
    } catch (IOException ex) {
        throw new SerializationException("Cannot serialize object", ex);
    }
    return outputStream.toByteArray();
}
Also used : CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) SerializationException(org.mule.runtime.api.serialization.SerializationException) ArtifactClassLoaderObjectOutputStream(org.mule.runtime.module.artifact.api.serializer.ArtifactClassLoaderObjectOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ArtifactClassLoaderObjectOutputStream(org.mule.runtime.module.artifact.api.serializer.ArtifactClassLoaderObjectOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) CursorStream(org.mule.runtime.api.streaming.bytes.CursorStream)

Example 2 with CursorStream

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

the class ReconnectionWithStreamingTestCase method standaloneCursorIsResetOnReconnection.

@Test
public void standaloneCursorIsResetOnReconnection() throws Exception {
    CursorStream cursorStream = createMockCursor();
    assertReconnection(cursorStream, cursorStream);
}
Also used : CursorStream(org.mule.runtime.api.streaming.bytes.CursorStream) Test(org.junit.Test)

Example 3 with CursorStream

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

the class CursorStreamProviderTestCase method ioExceptionIfClosed.

@Test(expected = IOException.class)
public void ioExceptionIfClosed() throws Exception {
    CursorStream cursor = streamProvider.openCursor();
    cursor.close();
    cursor.read();
}
Also used : CursorStream(org.mule.runtime.api.streaming.bytes.CursorStream) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with CursorStream

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

the class StreamingUtils method updateTypedValueWithCursorProvider.

/**
 * Updates the {@link Cursor} value a given {@link TypedValue} instance by replacing it with a {@link CursorProvider}.
 *
 * @param value the typed value to update
 * @param event the current event
 * @param streamingManager the streaming manager
 * @return updated {@link TypedValue instance}
 */
public static TypedValue updateTypedValueWithCursorProvider(final TypedValue value, final CoreEvent event, final StreamingManager streamingManager) {
    if (event == null) {
        return value;
    } else {
        Object payload = value.getValue();
        if (payload instanceof CursorStream) {
            CursorProvider provider = ((CursorStream) value.getValue()).getProvider();
            DataType dataType = DataType.builder(value.getDataType()).type(provider.getClass()).build();
            return new TypedValue(provider, dataType, value.getByteLength());
        } else {
            return value;
        }
    }
}
Also used : CursorProvider(org.mule.runtime.api.streaming.CursorProvider) DataType(org.mule.runtime.api.metadata.DataType) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) CursorStream(org.mule.runtime.api.streaming.bytes.CursorStream) TypedValue(org.mule.runtime.api.metadata.TypedValue)

Example 5 with CursorStream

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

the class ReconnectionWithStreamingTestCase method cursorComingFromProviderIsResetOnReconnection.

@Test
public void cursorComingFromProviderIsResetOnReconnection() throws Exception {
    CursorStream cursorStream = createMockCursor();
    CursorStreamProvider provider = mock(CursorStreamProvider.class);
    when(provider.openCursor()).thenReturn(cursorStream);
    assertReconnection(cursorStream, provider);
}
Also used : CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) CursorStream(org.mule.runtime.api.streaming.bytes.CursorStream) Test(org.junit.Test)

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