use of io.cdap.cdap.internal.io.ReflectionDatumReader 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 io.cdap.cdap.internal.io.ReflectionDatumReader 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 io.cdap.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 io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
the class MessagingMetricsCollectionServiceTest method testMessagingPublish.
@Test
public void testMessagingPublish() throws TopicNotFoundException {
MetricsCollectionService collectionService = new MessagingMetricsCollectionService(CConfiguration.create(), messagingService, recordWriter);
collectionService.startAndWait();
// publish metrics for different context
for (int i = 1; i <= 3; i++) {
collectionService.getContext(ImmutableMap.of("tag", "" + i)).increment("processed", i);
}
collectionService.stopAndWait();
// <Context, metricName, value>
Table<String, String, Long> expected = HashBasedTable.create();
expected.put("tag.1", "processed", 1L);
expected.put("tag.2", "processed", 2L);
expected.put("tag.3", "processed", 3L);
ReflectionDatumReader<MetricValues> recordReader = new ReflectionDatumReader<>(schema, metricValueType);
assertMetricsFromMessaging(schema, recordReader, expected);
}
use of io.cdap.cdap.internal.io.ReflectionDatumReader in project cdap by cdapio.
the class MessagingMetricsCollectionServiceTest method testMessagingPublish.
@Test
public void testMessagingPublish() throws TopicNotFoundException {
MetricsCollectionService collectionService = new MessagingMetricsCollectionService(CConfiguration.create(), messagingService, recordWriter);
collectionService.startAndWait();
// publish metrics for different context
for (int i = 1; i <= 3; i++) {
collectionService.getContext(ImmutableMap.of("tag", "" + i)).increment("processed", i);
}
collectionService.stopAndWait();
// <Context, metricName, value>
Table<String, String, Long> expected = HashBasedTable.create();
expected.put("tag.1", "processed", 1L);
expected.put("tag.2", "processed", 2L);
expected.put("tag.3", "processed", 3L);
ReflectionDatumReader<MetricValues> recordReader = new ReflectionDatumReader<>(schema, metricValueType);
assertMetricsFromMessaging(schema, recordReader, expected);
}
Aggregations