Search in sources :

Example 1 with ASMFieldAccessorFactory

use of co.cask.cdap.internal.io.ASMFieldAccessorFactory in project cdap by caskdata.

the class MetricsTestBase method init.

@Before
public void init() throws IOException, UnsupportedTypeException {
    cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    injector = Guice.createInjector(getModules());
    messagingService = injector.getInstance(MessagingService.class);
    if (messagingService instanceof Service) {
        ((Service) messagingService).startAndWait();
    }
    metricValueType = TypeToken.of(MetricValues.class);
    schema = new ReflectionSchemaGenerator().generate(metricValueType.getType());
    recordWriter = new ASMDatumWriterFactory(new ASMFieldAccessorFactory()).create(metricValueType, schema);
}
Also used : ASMFieldAccessorFactory(co.cask.cdap.internal.io.ASMFieldAccessorFactory) ASMDatumWriterFactory(co.cask.cdap.internal.io.ASMDatumWriterFactory) MessagingService(co.cask.cdap.messaging.MessagingService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) NoOpMetricsCollectionService(co.cask.cdap.common.metrics.NoOpMetricsCollectionService) Service(com.google.common.util.concurrent.Service) MetricValues(co.cask.cdap.api.metrics.MetricValues) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) MessagingService(co.cask.cdap.messaging.MessagingService) Before(org.junit.Before)

Example 2 with ASMFieldAccessorFactory

use of co.cask.cdap.internal.io.ASMFieldAccessorFactory in project cdap by caskdata.

the class FieldAccessorTest method testSetter.

@Test
public void testSetter() {
    TypeToken<Child> type = TypeToken.of(Child.class);
    FieldAccessorFactory factory = new ASMFieldAccessorFactory();
    Child c = new Child();
    c.integer = 10;
    c.str = "child value";
    ((Parent<String>) c).value = "string value";
    ((Parent<String>) c).b = true;
    Child c2 = new Child();
    factory.getFieldAccessor(type, "integer").setInt(c2, c.integer);
    factory.getFieldAccessor(type, "str").set(c2, c.str);
    factory.getFieldAccessor(type, "value").set(c2, ((Parent) c).value);
    factory.getFieldAccessor(type, "b").setBoolean(c2, ((Parent) c).b);
    Assert.assertEquals(c.integer, c2.integer);
    Assert.assertSame(c.str, c2.str);
    Assert.assertSame(((Parent) c).value, ((Parent) c2).value);
    Assert.assertEquals(((Parent) c).b, ((Parent) c2).b);
}
Also used : ASMFieldAccessorFactory(co.cask.cdap.internal.io.ASMFieldAccessorFactory) FieldAccessorFactory(co.cask.cdap.internal.io.FieldAccessorFactory) ASMFieldAccessorFactory(co.cask.cdap.internal.io.ASMFieldAccessorFactory) Test(org.junit.Test)

Example 3 with ASMFieldAccessorFactory

use of co.cask.cdap.internal.io.ASMFieldAccessorFactory in project cdap by caskdata.

the class FieldAccessorTest method testGetter.

@Test
public void testGetter() {
    TypeToken<Child> type = TypeToken.of(Child.class);
    FieldAccessorFactory factory = new ASMFieldAccessorFactory();
    FieldAccessor accessor = factory.getFieldAccessor(type, "integer");
    Assert.assertSame(accessor, factory.getFieldAccessor(type, "integer"));
    Child c = new Child();
    c.integer = 10;
    c.str = "child value";
    ((Parent<String>) c).value = "string value";
    ((Parent<String>) c).b = true;
    Assert.assertEquals(c.integer, accessor.getInt(c));
    Assert.assertSame(c.str, factory.getFieldAccessor(type, "str").get(c));
    Assert.assertSame(((Parent) c).value, factory.getFieldAccessor(type, "value").get(c));
    Assert.assertEquals(((Parent) c).b, factory.getFieldAccessor(type, "b").get(c));
}
Also used : ASMFieldAccessorFactory(co.cask.cdap.internal.io.ASMFieldAccessorFactory) FieldAccessorFactory(co.cask.cdap.internal.io.FieldAccessorFactory) ASMFieldAccessorFactory(co.cask.cdap.internal.io.ASMFieldAccessorFactory) FieldAccessor(co.cask.cdap.internal.io.FieldAccessor) Test(org.junit.Test)

Aggregations

ASMFieldAccessorFactory (co.cask.cdap.internal.io.ASMFieldAccessorFactory)3 FieldAccessorFactory (co.cask.cdap.internal.io.FieldAccessorFactory)2 Test (org.junit.Test)2 MetricValues (co.cask.cdap.api.metrics.MetricValues)1 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)1 NoOpMetricsCollectionService (co.cask.cdap.common.metrics.NoOpMetricsCollectionService)1 ASMDatumWriterFactory (co.cask.cdap.internal.io.ASMDatumWriterFactory)1 FieldAccessor (co.cask.cdap.internal.io.FieldAccessor)1 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)1 MessagingService (co.cask.cdap.messaging.MessagingService)1 Service (com.google.common.util.concurrent.Service)1 Before (org.junit.Before)1