Search in sources :

Example 1 with ASMFieldAccessorFactory

use of io.cdap.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(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) ASMFieldAccessorFactory(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) FieldAccessorFactory(io.cdap.cdap.internal.io.FieldAccessorFactory) FieldAccessor(io.cdap.cdap.internal.io.FieldAccessor) Test(org.junit.Test)

Example 2 with ASMFieldAccessorFactory

use of io.cdap.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(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) ASMFieldAccessorFactory(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) FieldAccessorFactory(io.cdap.cdap.internal.io.FieldAccessorFactory) Test(org.junit.Test)

Example 3 with ASMFieldAccessorFactory

use of io.cdap.cdap.internal.io.ASMFieldAccessorFactory in project cdap by cdapio.

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());
    cConf.set(Constants.Metrics.TOPIC_PREFIX, TOPIC_PREFIX);
    cConf.setInt(Constants.Metrics.MESSAGING_TOPIC_NUM, 10);
    cConf.setInt(Constants.Metrics.QUEUE_SIZE, 1000);
    // Set it to really short delay for faster test
    cConf.setLong(Constants.Metrics.PROCESSOR_MAX_DELAY_MS, 5);
    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(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) ASMDatumWriterFactory(io.cdap.cdap.internal.io.ASMDatumWriterFactory) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MessagingService(io.cdap.cdap.messaging.MessagingService) MessagingMetricsProcessorManagerService(io.cdap.cdap.metrics.process.MessagingMetricsProcessorManagerService) Service(com.google.common.util.concurrent.Service) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) MetricValues(io.cdap.cdap.api.metrics.MetricValues) ReflectionSchemaGenerator(io.cdap.cdap.internal.io.ReflectionSchemaGenerator) MessagingService(io.cdap.cdap.messaging.MessagingService) Before(org.junit.Before)

Example 4 with ASMFieldAccessorFactory

use of io.cdap.cdap.internal.io.ASMFieldAccessorFactory in project cdap by cdapio.

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(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) ASMFieldAccessorFactory(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) FieldAccessorFactory(io.cdap.cdap.internal.io.FieldAccessorFactory) Test(org.junit.Test)

Example 5 with ASMFieldAccessorFactory

use of io.cdap.cdap.internal.io.ASMFieldAccessorFactory in project cdap by cdapio.

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(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) ASMFieldAccessorFactory(io.cdap.cdap.internal.io.ASMFieldAccessorFactory) FieldAccessorFactory(io.cdap.cdap.internal.io.FieldAccessorFactory) FieldAccessor(io.cdap.cdap.internal.io.FieldAccessor) Test(org.junit.Test)

Aggregations

ASMFieldAccessorFactory (io.cdap.cdap.internal.io.ASMFieldAccessorFactory)6 FieldAccessorFactory (io.cdap.cdap.internal.io.FieldAccessorFactory)4 Test (org.junit.Test)4 Service (com.google.common.util.concurrent.Service)2 MetricValues (io.cdap.cdap.api.metrics.MetricValues)2 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)2 NoOpMetricsCollectionService (io.cdap.cdap.common.metrics.NoOpMetricsCollectionService)2 ASMDatumWriterFactory (io.cdap.cdap.internal.io.ASMDatumWriterFactory)2 FieldAccessor (io.cdap.cdap.internal.io.FieldAccessor)2 ReflectionSchemaGenerator (io.cdap.cdap.internal.io.ReflectionSchemaGenerator)2 MessagingService (io.cdap.cdap.messaging.MessagingService)2 MessagingMetricsProcessorManagerService (io.cdap.cdap.metrics.process.MessagingMetricsProcessorManagerService)2 Before (org.junit.Before)2