Search in sources :

Example 6 with WrappedMessage

use of org.infinispan.protostream.WrappedMessage in project protostream by infinispan.

the class ProtoSchemaBuilderTest method testGenericMessage.

@Test
public void testGenericMessage() throws Exception {
    SerializationContext ctx = createContext();
    String schema = new ProtoSchemaBuilder().fileName("generic_message.proto").addClass(GenericMessage.class).addClass(GenericMessage.OtherMessage.class).build(ctx);
    assertTrue(schema.contains("message GenericMessage"));
    GenericMessage genericMessage = new GenericMessage();
    genericMessage.field1 = new WrappedMessage(3.1415d);
    genericMessage.field2 = new WrappedMessage("qwerty".getBytes());
    genericMessage.field3 = new WrappedMessage(new WrappedMessage("azerty"));
    genericMessage.field4 = new WrappedMessage(new GenericMessage.OtherMessage("asdfg"));
    byte[] bytes = ProtobufUtil.toWrappedByteArray(ctx, genericMessage);
    GenericMessage o = ProtobufUtil.fromWrappedByteArray(ctx, bytes);
    assertNotNull(o);
    assertEquals(Double.class, genericMessage.field1.getValue().getClass());
    assertEquals(3.1415d, genericMessage.field1.getValue());
    assertArrayEquals("qwerty".getBytes(), (byte[]) genericMessage.field2.getValue());
    assertEquals("azerty", ((WrappedMessage) genericMessage.field3.getValue()).getValue());
    assertEquals("asdfg", ((GenericMessage.OtherMessage) genericMessage.field4.getValue()).field1);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) ProtoSchemaBuilder(org.infinispan.protostream.annotations.ProtoSchemaBuilder) WrappedMessage(org.infinispan.protostream.WrappedMessage) Test(org.junit.Test) AbstractProtoStreamTest(org.infinispan.protostream.test.AbstractProtoStreamTest)

Example 7 with WrappedMessage

use of org.infinispan.protostream.WrappedMessage in project protostream by infinispan.

the class AutoProtoSchemaBuilderTest method testGenericMessage.

@Test
public void testGenericMessage() throws Exception {
    SerializationContext ctx = ProtobufUtil.newSerializationContext();
    GeneratedSchema generatedSchema = new TestGenericMessageSerializationContextInitializerImpl();
    generatedSchema.registerSchema(ctx);
    generatedSchema.registerMarshallers(ctx);
    assertTrue(generatedSchema.getProtoFile().contains("message GenericMessage"));
    GenericMessage genericMessage = new GenericMessage();
    genericMessage.field1 = new WrappedMessage(3.1415d);
    genericMessage.field2 = new WrappedMessage("qwerty".getBytes());
    genericMessage.field3 = new WrappedMessage(new WrappedMessage("azerty"));
    genericMessage.field4 = new WrappedMessage(new GenericMessage.OtherMessage("asdfg"));
    byte[] bytes = ProtobufUtil.toWrappedByteArray(ctx, genericMessage);
    GenericMessage o = ProtobufUtil.fromWrappedByteArray(ctx, bytes);
    assertNotNull(o);
    assertEquals(Double.class, genericMessage.field1.getValue().getClass());
    assertEquals(3.1415d, genericMessage.field1.getValue());
    assertArrayEquals("qwerty".getBytes(), (byte[]) genericMessage.field2.getValue());
    assertEquals("azerty", ((WrappedMessage) genericMessage.field3.getValue()).getValue());
    assertEquals("asdfg", ((GenericMessage.OtherMessage) genericMessage.field4.getValue()).field1);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) WrappedMessage(org.infinispan.protostream.WrappedMessage) GeneratedSchema(org.infinispan.protostream.GeneratedSchema) Test(org.junit.Test)

Aggregations

WrappedMessage (org.infinispan.protostream.WrappedMessage)7 SerializationContext (org.infinispan.protostream.SerializationContext)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 GeneratedSchema (org.infinispan.protostream.GeneratedSchema)1 ProtoSchemaBuilder (org.infinispan.protostream.annotations.ProtoSchemaBuilder)1 ImportedProtoTypeMetadata (org.infinispan.protostream.annotations.impl.ImportedProtoTypeMetadata)1 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)1 AbstractProtoStreamTest (org.infinispan.protostream.test.AbstractProtoStreamTest)1 FilterResult (org.infinispan.query.remote.client.FilterResult)1 QueryResponse (org.infinispan.query.remote.client.impl.QueryResponse)1