use of io.cdap.cdap.common.io.BinaryDecoder 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);
}
use of io.cdap.cdap.common.io.BinaryDecoder in project cdap by cdapio.
the class ASMDatumCodecTest method testRecordArray.
@Test
public void testRecordArray() throws IOException, UnsupportedTypeException {
TypeToken<Record[][]> type = new TypeToken<Record[][]>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Record[][]> writer = getWriter(type);
Record[][] writeValue = new Record[][] { { new Record(10, "testing", ImmutableList.of("a", "b", "c"), TestEnum.VALUE2) } };
writer.encode(writeValue, new BinaryEncoder(os));
ReflectionDatumReader<Record[][]> reader = new ReflectionDatumReader<>(getSchema(type), type);
Record[][] value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertArrayEquals(writeValue, value);
}
use of io.cdap.cdap.common.io.BinaryDecoder in project cdap by cdapio.
the class ASMDatumCodecTest method testRecord.
@Test
public void testRecord() throws IOException, UnsupportedTypeException {
TypeToken<Record> type = new TypeToken<Record>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Record> writer = getWriter(type);
Record writeValue = new Record(10, "testing", ImmutableList.of("a", "b", "c"), TestEnum.VALUE2);
writer.encode(writeValue, new BinaryEncoder(os));
ReflectionDatumReader<Record> reader = new ReflectionDatumReader<>(getSchema(type), type);
Record value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(writeValue, value);
}
use of io.cdap.cdap.common.io.BinaryDecoder in project cdap by cdapio.
the class ASMDatumCodecTest method testList.
@Test
public void testList() throws IOException, UnsupportedTypeException {
TypeToken<List<Long>> type = new TypeToken<List<Long>>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
List<Long> writeValue = ImmutableList.of(1L, 10L, 100L, 1000L);
DatumWriter<List<Long>> writer = getWriter(type);
writer.encode(writeValue, new BinaryEncoder(os));
ReflectionDatumReader<List<Long>> reader = new ReflectionDatumReader<>(getSchema(type), type);
List<Long> value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(writeValue, value);
}
use of io.cdap.cdap.common.io.BinaryDecoder in project cdap by cdapio.
the class ASMDatumCodecTest method testMap.
@Test
public void testMap() throws IOException, UnsupportedTypeException {
TypeToken<Map<String, List<String>>> type = new TypeToken<Map<String, List<String>>>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Map<String, List<String>>> writer = getWriter(type);
ImmutableMap<String, List<String>> map = ImmutableMap.<String, List<String>>of("k1", Lists.newArrayList("v1"), "k2", Lists.newArrayList("v2", null));
writer.encode(map, new BinaryEncoder(os));
ReflectionDatumReader<Map<String, List<String>>> reader = new ReflectionDatumReader<>(getSchema(type), type);
Assert.assertEquals(map, reader.read(new BinaryDecoder(is), getSchema(type)));
}
Aggregations