Search in sources :

Example 6 with MarshallerFactory

use of org.jboss.marshalling.MarshallerFactory in project netty by netty.

the class AbstractCompatibleMarshallingEncoderTest method testMarshalling.

@Test
public void testMarshalling() throws Exception {
    @SuppressWarnings("RedundantStringConstructorCall") String testObject = new String("test");
    final MarshallerFactory marshallerFactory = createMarshallerFactory();
    final MarshallingConfiguration configuration = createMarshallingConfig();
    EmbeddedChannel ch = new EmbeddedChannel(createEncoder());
    ch.writeOutbound(testObject);
    assertTrue(ch.finish());
    ByteBuf buffer = ch.readOutbound();
    Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
    unmarshaller.start(Marshalling.createByteInput(truncate(buffer).nioBuffer()));
    String read = (String) unmarshaller.readObject();
    assertEquals(testObject, read);
    assertEquals(-1, unmarshaller.read());
    assertNull(ch.readOutbound());
    unmarshaller.finish();
    unmarshaller.close();
    buffer.release();
}
Also used : MarshallerFactory(org.jboss.marshalling.MarshallerFactory) MarshallingConfiguration(org.jboss.marshalling.MarshallingConfiguration) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Unmarshaller(org.jboss.marshalling.Unmarshaller) Test(org.junit.jupiter.api.Test)

Example 7 with MarshallerFactory

use of org.jboss.marshalling.MarshallerFactory in project netty by netty.

the class AbstractCompatibleMarshallingDecoderTest method testSimpleUnmarshalling.

@Test
public void testSimpleUnmarshalling() throws IOException {
    MarshallerFactory marshallerFactory = createMarshallerFactory();
    MarshallingConfiguration configuration = createMarshallingConfig();
    EmbeddedChannel ch = new EmbeddedChannel(createDecoder(Integer.MAX_VALUE));
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
    marshaller.start(Marshalling.createByteOutput(bout));
    marshaller.writeObject(testObject);
    marshaller.finish();
    marshaller.close();
    byte[] testBytes = bout.toByteArray();
    ch.writeInbound(input(testBytes));
    assertTrue(ch.finish());
    String unmarshalled = ch.readInbound();
    assertEquals(testObject, unmarshalled);
    assertNull(ch.readInbound());
}
Also used : MarshallerFactory(org.jboss.marshalling.MarshallerFactory) Marshaller(org.jboss.marshalling.Marshaller) MarshallingConfiguration(org.jboss.marshalling.MarshallingConfiguration) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

MarshallerFactory (org.jboss.marshalling.MarshallerFactory)7 MarshallingConfiguration (org.jboss.marshalling.MarshallingConfiguration)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 Test (org.junit.jupiter.api.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Marshaller (org.jboss.marshalling.Marshaller)3 ByteBuf (io.netty.buffer.ByteBuf)2 MediaContent (data.media.MediaContent)1 ChannelHandler (io.netty.channel.ChannelHandler)1 Unmarshaller (org.jboss.marshalling.Unmarshaller)1 RiverMarshallerFactory (org.jboss.marshalling.river.RiverMarshallerFactory)1 SerialMarshallerFactory (org.jboss.marshalling.serial.SerialMarshallerFactory)1