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));
}
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);
}
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);
}
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);
}
Aggregations