use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by cdapio.
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);
}
use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by cdapio.
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);
}
use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by cdapio.
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);
}
use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by cdapio.
the class ASMDatumCodecTest method testPrimitiveArray.
@Test
public void testPrimitiveArray() throws IOException, UnsupportedTypeException {
TypeToken<int[]> type = new TypeToken<int[]>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
int[] writeValue = { 1, 2, 3, 4, -5, -6, -7, -8 };
DatumWriter<int[]> writer = getWriter(type);
writer.encode(writeValue, new BinaryEncoder(os));
ReflectionDatumReader<int[]> reader = new ReflectionDatumReader<>(getSchema(type), type);
int[] value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertArrayEquals(writeValue, value);
}
use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by cdapio.
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);
}
Aggregations