Search in sources :

Example 16 with TestPortContext

use of org.apache.apex.malhar.lib.helper.TestPortContext in project apex-malhar by apache.

the class JdbcPojoOperatorTest method testJdbcPojoInsertOutputOperatorNullName.

/**
 * This test will assume direct mapping for POJO fields to DB columns Nullable
 * DB field missing in POJO name1 field, which is nullable in DB is missing
 * from POJO POJO(id, name) -> DB(id, name1)
 */
@Test
public void testJdbcPojoInsertOutputOperatorNullName() {
    JdbcTransactionalStore transactionalStore = new JdbcTransactionalStore();
    transactionalStore.setDatabaseDriver(DB_DRIVER);
    transactionalStore.setDatabaseUrl(URL);
    com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap attributeMap = new com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap();
    attributeMap.put(DAG.APPLICATION_ID, APP_ID);
    OperatorContext context = mockOperatorContext(OPERATOR_ID, attributeMap);
    TestPOJOOutputOperator outputOperator = new TestPOJOOutputOperator();
    outputOperator.setBatchSize(3);
    outputOperator.setTablename(TABLE_POJO_NAME_NAME_DIFF);
    outputOperator.setStore(transactionalStore);
    outputOperator.setup(context);
    Attribute.AttributeMap.DefaultAttributeMap portAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
    portAttributes.put(Context.PortContext.TUPLE_CLASS, TestPOJOEvent.class);
    TestPortContext tpc = new TestPortContext(portAttributes);
    outputOperator.input.setup(tpc);
    outputOperator.activate(context);
    List<TestPOJOEvent> events = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
        events.add(new TestPOJOEvent(i, "test" + i));
    }
    outputOperator.beginWindow(0);
    for (TestPOJOEvent event : events) {
        outputOperator.input.process(event);
    }
    outputOperator.endWindow();
    Assert.assertEquals("rows in db", 10, outputOperator.getNumOfEventsInStore(TABLE_POJO_NAME_NAME_DIFF));
    Assert.assertEquals("null name rows in db", 10, outputOperator.getNumOfNullEventsInStore(TABLE_POJO_NAME_NAME_DIFF));
}
Also used : Attribute(com.datatorrent.api.Attribute) TestPortContext(org.apache.apex.malhar.lib.helper.TestPortContext) OperatorContextTestHelper.mockOperatorContext(org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext) OperatorContext(com.datatorrent.api.Context.OperatorContext) Test(org.junit.Test)

Example 17 with TestPortContext

use of org.apache.apex.malhar.lib.helper.TestPortContext in project apex-malhar by apache.

the class CassandraOperatorTest method setupForTest.

@Before
public void setupForTest() {
    AttributeMap.DefaultAttributeMap attributeMap = new AttributeMap.DefaultAttributeMap();
    attributeMap.put(DAG.APPLICATION_ID, APP_ID);
    context = mockOperatorContext(OPERATOR_ID, attributeMap);
    Attribute.AttributeMap.DefaultAttributeMap portAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
    portAttributes.put(Context.PortContext.TUPLE_CLASS, TestPojo.class);
    tpc = new TestPortContext(portAttributes);
}
Also used : AttributeMap(com.datatorrent.api.Attribute.AttributeMap) Attribute(com.datatorrent.api.Attribute) TestPortContext(org.apache.apex.malhar.lib.helper.TestPortContext) Before(org.junit.Before)

Example 18 with TestPortContext

use of org.apache.apex.malhar.lib.helper.TestPortContext in project apex-malhar by apache.

the class AbstractUpsertOutputOperatorCodecsTest method setupApexContexts.

@Before
public void setupApexContexts() throws Exception {
    Attribute.AttributeMap.DefaultAttributeMap attributeMap = new Attribute.AttributeMap.DefaultAttributeMap();
    attributeMap.put(DAG.APPLICATION_ID, APP_ID);
    contextForUserUpsertOperator = mockOperatorContext(OPERATOR_ID_FOR_USER_UPSERTS, attributeMap);
    userUpsertOperator = new UserUpsertOperator();
    Attribute.AttributeMap.DefaultAttributeMap portAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
    portAttributes.put(Context.PortContext.TUPLE_CLASS, User.class);
    testPortContextForUserUpserts = new TestPortContext(portAttributes);
    userUpsertOperator.setup(contextForUserUpsertOperator);
    userUpsertOperator.activate(contextForUserUpsertOperator);
    userUpsertOperator.input.setup(testPortContextForUserUpserts);
}
Also used : Attribute(com.datatorrent.api.Attribute) TestPortContext(org.apache.apex.malhar.lib.helper.TestPortContext) Before(org.junit.Before)

Example 19 with TestPortContext

use of org.apache.apex.malhar.lib.helper.TestPortContext in project apex-malhar by apache.

the class KuduInputOperatorCommons method initOperatorState.

public void initOperatorState() throws Exception {
    Attribute.AttributeMap.DefaultAttributeMap attributeMapForInputOperator = new Attribute.AttributeMap.DefaultAttributeMap();
    attributeMapForInputOperator.put(DAG.APPLICATION_ID, APP_ID);
    operatorContext = mockOperatorContext(OPERATOR_ID_FOR_ONE_TO_ONE_PARTITIONER, attributeMapForInputOperator);
    Attribute.AttributeMap.DefaultAttributeMap portAttributesForInputOperator = new Attribute.AttributeMap.DefaultAttributeMap();
    portAttributesForInputOperator.put(Context.PortContext.TUPLE_CLASS, UnitTestTablePojo.class);
    testPortContext = new TestPortContext(portAttributesForInputOperator);
    unitTestStepwiseScanInputOperator = new UnitTestStepwiseScanInputOperator(getConnectionConfigForTable(), UnitTestTablePojo.class);
    unitTestStepwiseScanInputOperator.setNumberOfPartitions(numberOfKuduInputOperatorPartitions);
    unitTestStepwiseScanInputOperator.setPartitionScanStrategy(partitonScanStrategy);
    unitTestStepwiseScanInputOperator.setScanOrderStrategy(scanOrderStrategy);
    initCommonConfigsForAllTypesOfTests();
    partitions = unitTestStepwiseScanInputOperator.definePartitions(new ArrayList(), partitioningContext);
    Iterator<Partitioner.Partition<AbstractKuduInputOperator>> iteratorForMeta = partitions.iterator();
    UnitTestStepwiseScanInputOperator actualOperator = (UnitTestStepwiseScanInputOperator) iteratorForMeta.next().getPartitionedInstance();
    // Adjust the bindings as if apex has completed the partioning.The runtime of the framework does this in reality
    unitTestStepwiseScanInputOperator = actualOperator;
    unitTestStepwiseScanInputOperator.setup(operatorContext);
    unitTestStepwiseScanInputOperator.activate(operatorContext);
    // rewire parent operator to enable proper unit testing method calls
    unitTestStepwiseScanInputOperator.getPartitioner().setPrototypeKuduInputOperator(unitTestStepwiseScanInputOperator);
    unitTestStepwiseScanInputOperator.getScanner().setParentOperator(unitTestStepwiseScanInputOperator);
}
Also used : Attribute(com.datatorrent.api.Attribute) TestPortContext(org.apache.apex.malhar.lib.helper.TestPortContext) ArrayList(java.util.ArrayList)

Aggregations

Attribute (com.datatorrent.api.Attribute)19 TestPortContext (org.apache.apex.malhar.lib.helper.TestPortContext)19 Test (org.junit.Test)13 OperatorContext (com.datatorrent.api.Context.OperatorContext)12 OperatorContextTestHelper.mockOperatorContext (org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext)12 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)8 FieldInfo (org.apache.apex.malhar.lib.util.FieldInfo)6 Before (org.junit.Before)5 Partitioner (com.datatorrent.api.Partitioner)4 Date (java.sql.Date)3 AttributeMap (com.datatorrent.api.Attribute.AttributeMap)2 ArrayList (java.util.ArrayList)2 KuduClusterTestContext (org.apache.apex.malhar.kudu.test.KuduClusterTestContext)2 Operator (com.datatorrent.api.Operator)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1