Search in sources :

Example 6 with SerializationContext

use of org.infinispan.protostream.SerializationContext in project teiid by teiid.

the class TestTeiidTableMarsheller method testWriteComplex.

@Test
public void testWriteComplex() throws Exception {
    IckleConversionVisitor visitor = helpExecute("select * from G2");
    TeiidTableMarsheller writeMarshaller = new TeiidTableMarsheller(ProtobufMetadataProcessor.getMessageName(visitor.getParentTable()), MarshallerBuilder.getWireMap(visitor.getParentTable(), visitor.getMetadata()));
    SerializationContext ctx = ProtobufUtil.newSerializationContext(Configuration.builder().build());
    ctx.registerProtoFiles(FileDescriptorSource.fromString("tables.proto", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("tables.proto"))));
    ctx.registerMarshaller(new G3Marshaller());
    ctx.registerMarshaller(new G4Marshaller());
    G2Marshaller readMarshaller = new G2Marshaller() {

        @Override
        public void writeTo(ProtoStreamWriter writer, G2 g2) throws IOException {
            throw new RuntimeException("Use Teiid marshaller for writing for this test..");
        }
    };
    InfinispanDocument g2 = buildG2(visitor);
    ctx.registerMarshaller(writeMarshaller);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    RawProtoStreamWriter out = RawProtoStreamWriterImpl.newInstance(baos);
    WrappedMessage.writeMessage(ctx, out, g2);
    out.flush();
    baos.flush();
    ctx.unregisterMarshaller(writeMarshaller);
    // this is used for writing, if reading is being attempted then fail
    ctx.registerMarshaller(readMarshaller);
    RawProtoStreamReader in = RawProtoStreamReaderImpl.newInstance(baos.toByteArray());
    G2 result = WrappedMessage.readMessage(ctx, in);
    ctx.unregisterMarshaller(readMarshaller);
    assertEquals(buildG2(), result);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) RawProtoStreamReader(org.infinispan.protostream.RawProtoStreamReader) TeiidTableMarsheller(org.teiid.infinispan.api.TeiidTableMarsheller) InfinispanDocument(org.teiid.infinispan.api.InfinispanDocument) G3Marshaller(org.teiid.translator.marshallers.G3Marshaller) RawProtoStreamWriter(org.infinispan.protostream.RawProtoStreamWriter) G2(org.teiid.translator.marshallers.G2) ByteArrayOutputStream(java.io.ByteArrayOutputStream) G2Marshaller(org.teiid.translator.marshallers.G2Marshaller) RawProtoStreamWriter(org.infinispan.protostream.RawProtoStreamWriter) G4Marshaller(org.teiid.translator.marshallers.G4Marshaller) Test(org.junit.Test)

Example 7 with SerializationContext

use of org.infinispan.protostream.SerializationContext in project teiid by teiid.

the class TestTeiidTableMarsheller method testMarshallWithComplexNative.

// this is for sanity debugging while writing the protocol decoder.
@Test
public void testMarshallWithComplexNative() throws Exception {
    SerializationContext ctx = ProtobufUtil.newSerializationContext(Configuration.builder().build());
    ctx.registerProtoFiles(FileDescriptorSource.fromString("tables.proto", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("tables.proto"))));
    ctx.registerMarshaller(new G3Marshaller());
    ctx.registerMarshaller(new G4Marshaller());
    ctx.registerMarshaller(new G2Marshaller());
    G2 g2 = buildG2();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    RawProtoStreamWriter out = RawProtoStreamWriterImpl.newInstance(baos);
    WrappedMessage.writeMessage(ctx, out, g2);
    out.flush();
    baos.flush();
    RawProtoStreamReader in = RawProtoStreamReaderImpl.newInstance(baos.toByteArray());
    G2 result = WrappedMessage.readMessage(ctx, in);
    // System.out.println(result);
    assertNotNull(result);
    assertEquals(g2, result);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) RawProtoStreamReader(org.infinispan.protostream.RawProtoStreamReader) RawProtoStreamWriter(org.infinispan.protostream.RawProtoStreamWriter) G3Marshaller(org.teiid.translator.marshallers.G3Marshaller) G4Marshaller(org.teiid.translator.marshallers.G4Marshaller) G2(org.teiid.translator.marshallers.G2) ByteArrayOutputStream(java.io.ByteArrayOutputStream) G2Marshaller(org.teiid.translator.marshallers.G2Marshaller) Test(org.junit.Test)

Aggregations

SerializationContext (org.infinispan.protostream.SerializationContext)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 RawProtoStreamReader (org.infinispan.protostream.RawProtoStreamReader)5 RawProtoStreamWriter (org.infinispan.protostream.RawProtoStreamWriter)5 Test (org.junit.Test)5 InfinispanDocument (org.teiid.infinispan.api.InfinispanDocument)4 TeiidTableMarsheller (org.teiid.infinispan.api.TeiidTableMarsheller)4 G2 (org.teiid.translator.marshallers.G2)3 G2Marshaller (org.teiid.translator.marshallers.G2Marshaller)3 G3Marshaller (org.teiid.translator.marshallers.G3Marshaller)3 G4Marshaller (org.teiid.translator.marshallers.G4Marshaller)3 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)2 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)2 ProtoStreamMarshaller (org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller)2 GenderMarshaller (org.infinispan.protostream.sampledomain.marshallers.GenderMarshaller)2 UserMarshaller (org.infinispan.protostream.sampledomain.marshallers.UserMarshaller)2 G1 (org.teiid.translator.marshallers.G1)2 G1Marshaller (org.teiid.translator.marshallers.G1Marshaller)2 List (java.util.List)1 Document (org.teiid.translator.document.Document)1