Search in sources :

Example 1 with G1

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

the class TestTeiidTableMarsheller method testReadSimple.

@Test
public void testReadSimple() throws Exception {
    IckleConversionVisitor visitor = helpExecute("select * from G1");
    TeiidTableMarsheller g1ReadMarshaller = new TeiidTableMarsheller(ProtobufMetadataProcessor.getMessageName(visitor.getParentTable()), MarshallerBuilder.getWireMap(visitor.getParentTable(), visitor.getMetadata()));
    G1Marshaller g1WriteMarshller = new G1Marshaller() {

        @Override
        public G1 readFrom(ProtoStreamReader reader) throws IOException {
            throw new RuntimeException("Use Teiid marshaller for reading for this test..");
        }
    };
    SerializationContext ctx = ProtobufUtil.newSerializationContext(Configuration.builder().build());
    ctx.registerProtoFiles(FileDescriptorSource.fromString("tables.proto", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("tables.proto"))));
    G1 g1 = buildG1();
    ctx.registerMarshaller(g1WriteMarshller);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    RawProtoStreamWriter out = RawProtoStreamWriterImpl.newInstance(baos);
    WrappedMessage.writeMessage(ctx, out, g1);
    out.flush();
    baos.flush();
    ctx.unregisterMarshaller(g1WriteMarshller);
    ctx.registerMarshaller(g1ReadMarshaller);
    RawProtoStreamReader in = RawProtoStreamReaderImpl.newInstance(baos.toByteArray());
    Document result = WrappedMessage.readMessage(ctx, in);
    Map<String, Object> row = result.flatten().get(0);
    assertEquals(1, row.get("e1"));
    assertEquals("foo", row.get("e2"));
    assertEquals(1.234f, row.get("e3"));
    assertNull(row.get("e4"));
    List<String> e5 = (List<String>) row.get("e5");
    assertArrayEquals(new String[] { "hello", "world" }, e5.toArray(new String[e5.size()]));
    ctx.unregisterMarshaller(g1ReadMarshaller);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) RawProtoStreamReader(org.infinispan.protostream.RawProtoStreamReader) G1Marshaller(org.teiid.translator.marshallers.G1Marshaller) TeiidTableMarsheller(org.teiid.infinispan.api.TeiidTableMarsheller) RawProtoStreamReader(org.infinispan.protostream.RawProtoStreamReader) G1(org.teiid.translator.marshallers.G1) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.teiid.translator.document.Document) InfinispanDocument(org.teiid.infinispan.api.InfinispanDocument) RawProtoStreamWriter(org.infinispan.protostream.RawProtoStreamWriter) List(java.util.List) Test(org.junit.Test)

Example 2 with G1

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

the class TestTeiidTableMarsheller method testWriteSimple.

@Test
public void testWriteSimple() throws Exception {
    IckleConversionVisitor visitor = helpExecute("select * from G1");
    TeiidTableMarsheller g1WriteMarshaller = new TeiidTableMarsheller(ProtobufMetadataProcessor.getMessageName(visitor.getParentTable()), MarshallerBuilder.getWireMap(visitor.getParentTable(), visitor.getMetadata()));
    G1Marshaller g1ReadMarshaller = new G1Marshaller() {

        @Override
        public void writeTo(ProtoStreamWriter writer, G1 g1) throws IOException {
            throw new RuntimeException("Use Teiid marshaller for writing for this test..");
        }
    };
    SerializationContext ctx = ProtobufUtil.newSerializationContext(Configuration.builder().build());
    ctx.registerProtoFiles(FileDescriptorSource.fromString("tables.proto", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("tables.proto"))));
    InfinispanDocument g1 = new InfinispanDocument("pm1.G1", MarshallerBuilder.getWireMap(visitor.getParentTable(), visitor.getMetadata()), null);
    g1.addProperty("e1", 1);
    g1.addProperty("e2", "foo");
    g1.addProperty("e3", 1.234f);
    g1.addProperty("e4", null);
    g1.addArrayProperty("e5", "hello");
    g1.addArrayProperty("e5", "world");
    // write to buffer
    ctx.registerMarshaller(g1WriteMarshaller);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    RawProtoStreamWriter out = RawProtoStreamWriterImpl.newInstance(baos);
    WrappedMessage.writeMessage(ctx, out, g1);
    out.flush();
    baos.flush();
    ctx.unregisterMarshaller(g1WriteMarshaller);
    // read from buffer
    ctx.registerMarshaller(g1ReadMarshaller);
    RawProtoStreamReader in = RawProtoStreamReaderImpl.newInstance(baos.toByteArray());
    G1 result = WrappedMessage.readMessage(ctx, in);
    ctx.unregisterMarshaller(g1ReadMarshaller);
    assertEquals(buildG1(), result);
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) RawProtoStreamReader(org.infinispan.protostream.RawProtoStreamReader) G1Marshaller(org.teiid.translator.marshallers.G1Marshaller) TeiidTableMarsheller(org.teiid.infinispan.api.TeiidTableMarsheller) InfinispanDocument(org.teiid.infinispan.api.InfinispanDocument) RawProtoStreamWriter(org.infinispan.protostream.RawProtoStreamWriter) RawProtoStreamWriter(org.infinispan.protostream.RawProtoStreamWriter) G1(org.teiid.translator.marshallers.G1) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 3 with G1

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

the class TestTeiidTableMarsheller method buildG1.

private G1 buildG1() {
    G1 g1 = new G1();
    g1.setE1(1);
    g1.setE2("foo");
    g1.setE3(1.234f);
    g1.setE4(null);
    g1.setE5(new String[] { "hello", "world" });
    return g1;
}
Also used : G1(org.teiid.translator.marshallers.G1)

Aggregations

G1 (org.teiid.translator.marshallers.G1)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 RawProtoStreamReader (org.infinispan.protostream.RawProtoStreamReader)2 RawProtoStreamWriter (org.infinispan.protostream.RawProtoStreamWriter)2 SerializationContext (org.infinispan.protostream.SerializationContext)2 Test (org.junit.Test)2 InfinispanDocument (org.teiid.infinispan.api.InfinispanDocument)2 TeiidTableMarsheller (org.teiid.infinispan.api.TeiidTableMarsheller)2 G1Marshaller (org.teiid.translator.marshallers.G1Marshaller)2 List (java.util.List)1 Document (org.teiid.translator.document.Document)1