use of co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
the class RecordWithString method testEnum.
@Test
public void testEnum() throws IOException, UnsupportedTypeException {
PipedOutputStream output = new PipedOutputStream();
PipedInputStream input = new PipedInputStream(output);
Schema schema = new ReflectionSchemaGenerator().generate(TestEnum.class);
ReflectionDatumWriter<TestEnum> writer = new ReflectionDatumWriter<>(schema);
BinaryEncoder encoder = new BinaryEncoder(output);
writer.encode(TestEnum.VALUE1, encoder);
writer.encode(TestEnum.VALUE3, encoder);
writer.encode(TestEnum.VALUE2, encoder);
BinaryDecoder decoder = new BinaryDecoder(input);
Schema readSchema = Schema.parseJson(schema.toString());
ReflectionDatumReader<TestEnum> reader = new ReflectionDatumReader<>(readSchema, TypeToken.of(TestEnum.class));
Assert.assertEquals(TestEnum.VALUE1, reader.read(decoder, readSchema));
Assert.assertEquals(TestEnum.VALUE3, reader.read(decoder, readSchema));
Assert.assertEquals(TestEnum.VALUE2, reader.read(decoder, readSchema));
}
use of co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
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 co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
the class ASMDatumCodecTest method testStreamEvent.
@Test
public void testStreamEvent() throws IOException, UnsupportedTypeException {
TypeToken<StreamEvent> type = new TypeToken<StreamEvent>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<StreamEvent> writer = getWriter(type);
StreamEvent event = new StreamEvent(ImmutableMap.of("key", "value"), ByteBuffer.wrap("Testing message".getBytes(Charsets.UTF_8)));
writer.encode(event, new BinaryEncoder(os));
ReflectionDatumReader<StreamEvent> reader = new ReflectionDatumReader<>(getSchema(type), type);
StreamEvent value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(event.getHeaders(), value.getHeaders());
Assert.assertEquals(event.getBody(), value.getBody());
}
use of co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
the class ASMDatumCodecTest method testInt.
@Test
public void testInt() throws UnsupportedTypeException, IOException {
TypeToken<Integer> type = new TypeToken<Integer>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Integer> writer = getWriter(type);
writer.encode(12234234, new BinaryEncoder(os));
ReflectionDatumReader<Integer> reader = new ReflectionDatumReader<>(getSchema(type), type);
int value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(12234234, value);
}
use of co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
the class ASMDatumCodecTest method testShort.
@Test
public void testShort() throws UnsupportedTypeException, IOException {
TypeToken<Short> type = new TypeToken<Short>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Short> writer = getWriter(type);
writer.encode((short) 3000, new BinaryEncoder(os));
ReflectionDatumReader<Short> reader = new ReflectionDatumReader<>(getSchema(type), type);
short value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals((short) 3000, value);
}
Aggregations