Search in sources :

Example 1 with ReflectionDatumReader

use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.

the class ASMDatumCodecTest method testRecordContainer.

@Test
public void testRecordContainer() throws IOException, UnsupportedTypeException {
    TypeToken<List<Record>> type = new TypeToken<List<Record>>() {
    };
    PipedOutputStream os = new PipedOutputStream();
    PipedInputStream is = new PipedInputStream(os);
    DatumWriter<List<Record>> writer = getWriter(type);
    List<Record> writeValue = ImmutableList.of(new Record(10, "testing", ImmutableList.of("a", "b", "c"), TestEnum.VALUE2));
    writer.encode(writeValue, new BinaryEncoder(os));
    ReflectionDatumReader<List<Record>> reader = new ReflectionDatumReader<>(getSchema(type), type);
    List<Record> value = reader.read(new BinaryDecoder(is), getSchema(type));
    Assert.assertEquals(writeValue, value);
}
Also used : BinaryEncoder(io.cdap.cdap.common.io.BinaryEncoder) TypeToken(com.google.common.reflect.TypeToken) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) PipedOutputStream(java.io.PipedOutputStream) ReflectionDatumReader(io.cdap.cdap.internal.io.ReflectionDatumReader) PipedInputStream(java.io.PipedInputStream) BinaryDecoder(io.cdap.cdap.common.io.BinaryDecoder) Test(org.junit.Test)

Example 2 with ReflectionDatumReader

use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.

the class ASMDatumCodecTest method testUUID.

@Test
public void testUUID() throws UnsupportedTypeException, IOException {
    TypeToken<UUID> type = new TypeToken<UUID>() {
    };
    PipedOutputStream os = new PipedOutputStream();
    PipedInputStream is = new PipedInputStream(os);
    DatumWriter<UUID> writer = getWriter(type);
    UUID uuid = UUID.randomUUID();
    writer.encode(uuid, new BinaryEncoder(os));
    ReflectionDatumReader<UUID> reader = new ReflectionDatumReader<>(getSchema(type), type);
    UUID value = reader.read(new BinaryDecoder(is), getSchema(type));
    Assert.assertEquals(uuid, value);
}
Also used : BinaryEncoder(io.cdap.cdap.common.io.BinaryEncoder) TypeToken(com.google.common.reflect.TypeToken) PipedOutputStream(java.io.PipedOutputStream) ReflectionDatumReader(io.cdap.cdap.internal.io.ReflectionDatumReader) PipedInputStream(java.io.PipedInputStream) UUID(java.util.UUID) BinaryDecoder(io.cdap.cdap.common.io.BinaryDecoder) Test(org.junit.Test)

Example 3 with ReflectionDatumReader

use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.

the class ASMDatumCodecTest method testString.

@Test
public void testString() throws UnsupportedTypeException, IOException {
    TypeToken<String> type = new TypeToken<String>() {
    };
    PipedOutputStream os = new PipedOutputStream();
    PipedInputStream is = new PipedInputStream(os);
    DatumWriter<String> writer = getWriter(type);
    writer.encode("Testing message", new BinaryEncoder(os));
    ReflectionDatumReader<String> reader = new ReflectionDatumReader<>(getSchema(type), type);
    String value = reader.read(new BinaryDecoder(is), getSchema(type));
    Assert.assertEquals("Testing message", value);
}
Also used : BinaryEncoder(io.cdap.cdap.common.io.BinaryEncoder) TypeToken(com.google.common.reflect.TypeToken) PipedOutputStream(java.io.PipedOutputStream) ReflectionDatumReader(io.cdap.cdap.internal.io.ReflectionDatumReader) PipedInputStream(java.io.PipedInputStream) BinaryDecoder(io.cdap.cdap.common.io.BinaryDecoder) Test(org.junit.Test)

Example 4 with ReflectionDatumReader

use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.

the class ASMDatumCodecTest method testTree.

@Test
public void testTree() throws IOException, UnsupportedTypeException {
    TypeToken<Node> type = new TypeToken<Node>() {
    };
    PipedOutputStream os = new PipedOutputStream();
    PipedInputStream is = new PipedInputStream(os);
    DatumWriter<Node> writer = getWriter(type);
    Node root = new Node((short) 1, new Node((short) 2, null, new Node((short) 3, null, null)), new Node((short) 4, new Node((short) 5, null, null), null));
    writer.encode(root, new BinaryEncoder(os));
    ReflectionDatumReader<Node> reader = new ReflectionDatumReader<>(getSchema(type), type);
    Node value = reader.read(new BinaryDecoder(is), getSchema(type));
    Assert.assertEquals(root, value);
}
Also used : BinaryEncoder(io.cdap.cdap.common.io.BinaryEncoder) TypeToken(com.google.common.reflect.TypeToken) PipedOutputStream(java.io.PipedOutputStream) ReflectionDatumReader(io.cdap.cdap.internal.io.ReflectionDatumReader) PipedInputStream(java.io.PipedInputStream) BinaryDecoder(io.cdap.cdap.common.io.BinaryDecoder) Test(org.junit.Test)

Example 5 with ReflectionDatumReader

use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.

the class ASMDatumCodecTest method testURI.

@Test
public void testURI() throws IOException, UnsupportedTypeException {
    TypeToken<List<URI>> type = new TypeToken<List<URI>>() {
    };
    PipedOutputStream os = new PipedOutputStream();
    PipedInputStream is = new PipedInputStream(os);
    DatumWriter<List<URI>> writer = getWriter(type);
    List<URI> writeValue = ImmutableList.of(URI.create("http://www.abc.com"));
    writer.encode(writeValue, new BinaryEncoder(os));
    ReflectionDatumReader<List<URI>> reader = new ReflectionDatumReader<>(getSchema(type), type);
    Assert.assertEquals(writeValue, reader.read(new BinaryDecoder(is), getSchema(type)));
}
Also used : BinaryEncoder(io.cdap.cdap.common.io.BinaryEncoder) TypeToken(com.google.common.reflect.TypeToken) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) PipedOutputStream(java.io.PipedOutputStream) ReflectionDatumReader(io.cdap.cdap.internal.io.ReflectionDatumReader) PipedInputStream(java.io.PipedInputStream) URI(java.net.URI) BinaryDecoder(io.cdap.cdap.common.io.BinaryDecoder) Test(org.junit.Test)

Aggregations

ReflectionDatumReader (io.cdap.cdap.internal.io.ReflectionDatumReader)18 Test (org.junit.Test)18 BinaryDecoder (io.cdap.cdap.common.io.BinaryDecoder)17 BinaryEncoder (io.cdap.cdap.common.io.BinaryEncoder)17 PipedInputStream (java.io.PipedInputStream)16 PipedOutputStream (java.io.PipedOutputStream)16 TypeToken (com.google.common.reflect.TypeToken)15 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 Schema (io.cdap.cdap.api.data.schema.Schema)2 ReflectionDatumWriter (io.cdap.cdap.internal.io.ReflectionDatumWriter)2 ReflectionSchemaGenerator (io.cdap.cdap.internal.io.ReflectionSchemaGenerator)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 MetricValues (io.cdap.cdap.api.metrics.MetricValues)1 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)1 TypeRepresentation (io.cdap.cdap.internal.io.TypeRepresentation)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URI (java.net.URI)1 Map (java.util.Map)1