use of co.cask.cdap.common.io.BinaryEncoder in project cdap by caskdata.
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 co.cask.cdap.common.io.BinaryEncoder 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);
}
use of co.cask.cdap.common.io.BinaryEncoder in project cdap by caskdata.
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 co.cask.cdap.common.io.BinaryEncoder in project cdap by caskdata.
the class ASMDatumCodecTest method testEnum.
@Test
public void testEnum() throws UnsupportedTypeException, IOException {
TypeToken<TestEnum> type = new TypeToken<TestEnum>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<TestEnum> writer = getWriter(type);
BinaryEncoder encoder = new BinaryEncoder(os);
writer.encode(TestEnum.VALUE1, encoder);
writer.encode(TestEnum.VALUE4, encoder);
writer.encode(TestEnum.VALUE3, encoder);
ReflectionDatumReader<TestEnum> reader = new ReflectionDatumReader<>(getSchema(type), type);
TestEnum value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(TestEnum.VALUE1, value);
value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(TestEnum.VALUE4, value);
value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(TestEnum.VALUE3, value);
}
use of co.cask.cdap.common.io.BinaryEncoder in project cdap by caskdata.
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);
}
Aggregations