Search in sources :

Example 1 with G2

use of org.teiid.translator.marshallers.G2 in project teiid by teiid.

the class TestTeiidTableMarsheller method buildG2.

private G2 buildG2() {
    G3 g3 = new G3();
    g3.setE1(1);
    g3.setE2("bar");
    G4 g41 = new G4();
    g41.setE1(1);
    g41.setE2("hello");
    G4 g42 = new G4();
    g42.setE1(2);
    g42.setE2("world");
    G2 g2 = new G2();
    g2.setE1(1);
    g2.setE2("foo");
    g2.setG3(g3);
    g2.setG4(Arrays.asList(g41, g42));
    g2.setE5("Hello Infinispan".getBytes());
    g2.setE6(new Timestamp(1489835322801L));
    return g2;
}
Also used : G2(org.teiid.translator.marshallers.G2) G3(org.teiid.translator.marshallers.G3) G4(org.teiid.translator.marshallers.G4) Timestamp(java.sql.Timestamp)

Example 2 with G2

use of org.teiid.translator.marshallers.G2 in project teiid by teiid.

the class TestTeiidTableMarsheller method testReadComplex.

@Test
public void testReadComplex() throws Exception {
    IckleConversionVisitor visitor = helpExecute("select * from G2");
    TeiidTableMarsheller readMarshaller = 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 writeMarshaller = new G2Marshaller() {

        @Override
        public G2 readFrom(ProtoStreamReader reader) throws IOException {
            throw new RuntimeException("Use Teiid marshaller for reading for this test..");
        }
    };
    G2 g2 = buildG2();
    // this is used for writing, if reading is being attempted then fail
    ctx.registerMarshaller(writeMarshaller);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    RawProtoStreamWriter out = RawProtoStreamWriterImpl.newInstance(baos);
    WrappedMessage.writeMessage(ctx, out, g2);
    out.flush();
    baos.flush();
    ctx.unregisterMarshaller(writeMarshaller);
    ctx.registerMarshaller(readMarshaller);
    RawProtoStreamReader in = RawProtoStreamReaderImpl.newInstance(baos.toByteArray());
    InfinispanDocument result = WrappedMessage.readMessage(ctx, in);
    // System.out.println(result.flatten());
    assertG2(result);
    ctx.unregisterMarshaller(readMarshaller);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) RawProtoStreamReader(org.infinispan.protostream.RawProtoStreamReader) TeiidTableMarsheller(org.teiid.infinispan.api.TeiidTableMarsheller) InfinispanDocument(org.teiid.infinispan.api.InfinispanDocument) RawProtoStreamReader(org.infinispan.protostream.RawProtoStreamReader) G3Marshaller(org.teiid.translator.marshallers.G3Marshaller) 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 3 with G2

use of org.teiid.translator.marshallers.G2 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 4 with G2

use of org.teiid.translator.marshallers.G2 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

G2 (org.teiid.translator.marshallers.G2)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 RawProtoStreamReader (org.infinispan.protostream.RawProtoStreamReader)3 RawProtoStreamWriter (org.infinispan.protostream.RawProtoStreamWriter)3 SerializationContext (org.infinispan.protostream.SerializationContext)3 Test (org.junit.Test)3 G2Marshaller (org.teiid.translator.marshallers.G2Marshaller)3 G3Marshaller (org.teiid.translator.marshallers.G3Marshaller)3 G4Marshaller (org.teiid.translator.marshallers.G4Marshaller)3 InfinispanDocument (org.teiid.infinispan.api.InfinispanDocument)2 TeiidTableMarsheller (org.teiid.infinispan.api.TeiidTableMarsheller)2 Timestamp (java.sql.Timestamp)1 G3 (org.teiid.translator.marshallers.G3)1 G4 (org.teiid.translator.marshallers.G4)1