use of co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
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 co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
the class ASMDatumCodecTest method testDouble.
@Test
public void testDouble() throws UnsupportedTypeException, IOException {
TypeToken<Double> type = new TypeToken<Double>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<Double> writer = getWriter(type);
writer.encode(3.14d, new BinaryEncoder(os));
ReflectionDatumReader<Double> reader = new ReflectionDatumReader<>(getSchema(type), type);
double value = reader.read(new BinaryDecoder(is), getSchema(type));
Assert.assertEquals(3.14d, value, 0.000001d);
}
use of co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
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 co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
the class ASMDatumCodecTest method testURI.
@Test
public void testURI() throws IOException, UnsupportedTypeException {
TypeToken<List<URI>> type = new TypeToken<List<URI>>() {
};
PipedOutputStream os = new PipedOutputStream();
PipedInputStream is = new PipedInputStream(os);
DatumWriter<List<URI>> writer = getWriter(type);
List<URI> writeValue = ImmutableList.of(URI.create("http://www.abc.com"));
writer.encode(writeValue, new BinaryEncoder(os));
ReflectionDatumReader<List<URI>> reader = new ReflectionDatumReader<>(getSchema(type), type);
Assert.assertEquals(writeValue, reader.read(new BinaryDecoder(is), getSchema(type)));
}
use of co.cask.cdap.internal.io.ReflectionDatumReader in project cdap by caskdata.
the class MessagingMetricsCollectionServiceTest method testMessagingPublish.
@Test
public void testMessagingPublish() throws UnsupportedTypeException, InterruptedException, TopicNotFoundException, IOException {
MetricsCollectionService collectionService = new MessagingMetricsCollectionService(TOPIC_PREFIX, PARTITION_SIZE, 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