Search in sources :

Example 16 with ReflectionDatumReader

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);
}
Also used : BinaryEncoder(co.cask.cdap.common.io.BinaryEncoder) TypeToken(com.google.common.reflect.TypeToken) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) PipedOutputStream(java.io.PipedOutputStream) ReflectionDatumReader(co.cask.cdap.internal.io.ReflectionDatumReader) PipedInputStream(java.io.PipedInputStream) BinaryDecoder(co.cask.cdap.common.io.BinaryDecoder) Test(org.junit.Test)

Example 17 with ReflectionDatumReader

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);
}
Also used : BinaryEncoder(co.cask.cdap.common.io.BinaryEncoder) TypeToken(com.google.common.reflect.TypeToken) PipedOutputStream(java.io.PipedOutputStream) ReflectionDatumReader(co.cask.cdap.internal.io.ReflectionDatumReader) PipedInputStream(java.io.PipedInputStream) BinaryDecoder(co.cask.cdap.common.io.BinaryDecoder) Test(org.junit.Test)

Example 18 with ReflectionDatumReader

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);
}
Also used : BinaryEncoder(co.cask.cdap.common.io.BinaryEncoder) TypeToken(com.google.common.reflect.TypeToken) PipedOutputStream(java.io.PipedOutputStream) ReflectionDatumReader(co.cask.cdap.internal.io.ReflectionDatumReader) PipedInputStream(java.io.PipedInputStream) UUID(java.util.UUID) BinaryDecoder(co.cask.cdap.common.io.BinaryDecoder) Test(org.junit.Test)

Example 19 with ReflectionDatumReader

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)));
}
Also used : BinaryEncoder(co.cask.cdap.common.io.BinaryEncoder) TypeToken(com.google.common.reflect.TypeToken) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) PipedOutputStream(java.io.PipedOutputStream) ReflectionDatumReader(co.cask.cdap.internal.io.ReflectionDatumReader) PipedInputStream(java.io.PipedInputStream) URI(java.net.URI) BinaryDecoder(co.cask.cdap.common.io.BinaryDecoder) Test(org.junit.Test)

Example 20 with ReflectionDatumReader

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);
}
Also used : MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) ReflectionDatumReader(co.cask.cdap.internal.io.ReflectionDatumReader) MetricValues(co.cask.cdap.api.metrics.MetricValues) Test(org.junit.Test)

Aggregations

ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)20 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)19 Test (org.junit.Test)19 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)18 PipedInputStream (java.io.PipedInputStream)17 PipedOutputStream (java.io.PipedOutputStream)17 TypeToken (com.google.common.reflect.TypeToken)16 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 Schema (co.cask.cdap.api.data.schema.Schema)3 ReflectionDatumWriter (co.cask.cdap.internal.io.ReflectionDatumWriter)2 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)2 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)1 MetricValues (co.cask.cdap.api.metrics.MetricValues)1 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)1 TypeRepresentation (co.cask.cdap.internal.io.TypeRepresentation)1 ByteBufferInputStream (co.cask.common.io.ByteBufferInputStream)1 Function (com.google.common.base.Function)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1