Search in sources :

Example 6 with PortContext

use of com.datatorrent.stram.engine.PortContext in project apex-malhar by apache.

the class FilterTest method prepareFilterOperator.

public void prepareFilterOperator(Class<?> inClass, String condition) {
    filter.truePort.setSink(trueSink);
    filter.falsePort.setSink(falseSink);
    filter.error.setSink(errorSink);
    filter.setup(null);
    Attribute.AttributeMap in = new Attribute.AttributeMap.DefaultAttributeMap();
    in.put(Context.PortContext.TUPLE_CLASS, inClass);
    filter.input.setup(new PortContext(in, null));
    filter.setCondition(condition);
    filter.activate(null);
}
Also used : Attribute(com.datatorrent.api.Attribute) PortContext(com.datatorrent.stram.engine.PortContext)

Example 7 with PortContext

use of com.datatorrent.stram.engine.PortContext in project apex-malhar by apache.

the class POJOInnerJoinOperatorTest method testInnerJoinOperator.

@Test
public void testInnerJoinOperator() throws IOException, InterruptedException {
    POJOInnerJoinOperator oper = new POJOInnerJoinOperator();
    oper.setIncludeFieldStr("ID,Name;OID,Amount");
    oper.setLeftKeyExpression("ID");
    oper.setRightKeyExpression("CID");
    oper.setExpiryTime(10000L);
    oper.setup(context);
    attributes.put(DAG.InputPortMeta.TUPLE_CLASS, CustOrder.class);
    oper.outputPort.setup(new PortContext(attributes, context));
    attributes.put(DAG.InputPortMeta.TUPLE_CLASS, Customer.class);
    oper.input1.setup(new PortContext(attributes, context));
    attributes.put(DAG.InputPortMeta.TUPLE_CLASS, Order.class);
    oper.input2.setup(new PortContext(attributes, context));
    oper.activate(context);
    CollectorTestSink<CustOrder> sink = new CollectorTestSink<>();
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectorTestSink<Object> tmp = (CollectorTestSink) sink;
    oper.outputPort.setSink(tmp);
    oper.beginWindow(0);
    Customer tuple = new Customer(1, "Anil");
    oper.input1.process(tuple);
    Order order = new Order(102, 1, 300);
    oper.input2.process(order);
    Order order2 = new Order(103, 3, 300);
    oper.input2.process(order2);
    Order order3 = new Order(104, 7, 300);
    oper.input2.process(order3);
    oper.endWindow();
    /* Number of tuple, emitted */
    Assert.assertEquals("Number of tuple emitted ", 1, sink.collectedTuples.size());
    CustOrder emitted = sink.collectedTuples.iterator().next();
    Assert.assertEquals("value of ID :", tuple.ID, emitted.ID);
    Assert.assertEquals("value of Name :", tuple.Name, emitted.Name);
    Assert.assertEquals("value of OID: ", order.OID, emitted.OID);
    Assert.assertEquals("value of Amount: ", order.Amount, emitted.Amount);
    oper.teardown();
}
Also used : CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) PortContext(com.datatorrent.stram.engine.PortContext) Test(org.junit.Test)

Example 8 with PortContext

use of com.datatorrent.stram.engine.PortContext in project apex-malhar by apache.

the class POJOInnerJoinOperatorTest method testEmitMultipleTuplesFromStream2.

@Test
public void testEmitMultipleTuplesFromStream2() throws IOException, InterruptedException {
    POJOInnerJoinOperator oper = new POJOInnerJoinOperator();
    oper.setIncludeFieldStr("ID,Name;OID,Amount");
    oper.setLeftKeyExpression("ID");
    oper.setRightKeyExpression("CID");
    oper.setLeftKeyPrimary(true);
    oper.setExpiryTime(10000L);
    oper.setup(context);
    attributes.put(DAG.InputPortMeta.TUPLE_CLASS, CustOrder.class);
    oper.outputPort.setup(new PortContext(attributes, context));
    attributes.put(DAG.InputPortMeta.TUPLE_CLASS, Customer.class);
    oper.input1.setup(new PortContext(attributes, context));
    attributes.put(DAG.InputPortMeta.TUPLE_CLASS, Order.class);
    oper.input2.setup(new PortContext(attributes, context));
    oper.activate(context);
    CollectorTestSink<CustOrder> sink = new CollectorTestSink<>();
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectorTestSink<Object> tmp = (CollectorTestSink) sink;
    oper.outputPort.setSink(tmp);
    oper.beginWindow(0);
    Customer tuple1 = new Customer(1, "Anil");
    oper.input1.process(tuple1);
    Order order = new Order(102, 1, 300);
    oper.input2.process(order);
    Order order2 = new Order(103, 1, 300);
    oper.input2.process(order2);
    oper.endWindow();
    /* Number of tuple, emitted */
    Assert.assertEquals("Number of tuple emitted ", 2, sink.collectedTuples.size());
    CustOrder emitted = sink.collectedTuples.get(0);
    Assert.assertEquals("value of ID :", tuple1.ID, emitted.ID);
    Assert.assertEquals("value of Name :", tuple1.Name, emitted.Name);
    Assert.assertEquals("value of OID: ", order.OID, emitted.OID);
    Assert.assertEquals("value of Amount: ", order.Amount, emitted.Amount);
    emitted = sink.collectedTuples.get(1);
    Assert.assertEquals("value of ID :", tuple1.ID, emitted.ID);
    Assert.assertEquals("value of Name :", tuple1.Name, emitted.Name);
    Assert.assertEquals("value of OID: ", order2.OID, emitted.OID);
    Assert.assertEquals("value of Amount: ", order2.Amount, emitted.Amount);
    oper.teardown();
}
Also used : CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) PortContext(com.datatorrent.stram.engine.PortContext) Test(org.junit.Test)

Example 9 with PortContext

use of com.datatorrent.stram.engine.PortContext in project apex-malhar by apache.

the class POJOInnerJoinOperatorTest method testMultipleValues.

@Test
public void testMultipleValues() throws IOException, InterruptedException {
    POJOInnerJoinOperator oper = new POJOInnerJoinOperator();
    oper.setIncludeFieldStr("ID,Name;OID,Amount");
    oper.setLeftKeyExpression("ID");
    oper.setRightKeyExpression("CID");
    oper.setExpiryTime(10000L);
    oper.setup(context);
    attributes.put(DAG.InputPortMeta.TUPLE_CLASS, CustOrder.class);
    oper.outputPort.setup(new PortContext(attributes, context));
    attributes.put(DAG.InputPortMeta.TUPLE_CLASS, Customer.class);
    oper.input1.setup(new PortContext(attributes, context));
    attributes.put(DAG.InputPortMeta.TUPLE_CLASS, Order.class);
    oper.input2.setup(new PortContext(attributes, context));
    oper.activate(context);
    CollectorTestSink<CustOrder> sink = new CollectorTestSink<>();
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectorTestSink<Object> tmp = (CollectorTestSink) sink;
    oper.outputPort.setSink(tmp);
    oper.beginWindow(0);
    Order order = new Order(102, 1, 300);
    oper.input2.process(order);
    Order order2 = new Order(103, 3, 300);
    oper.input2.process(order2);
    oper.endWindow();
    oper.beginWindow(1);
    Order order3 = new Order(104, 1, 300);
    oper.input2.process(order3);
    Customer tuple = new Customer(1, "Anil");
    oper.input1.process(tuple);
    oper.endWindow();
    /* Number of tuple, emitted */
    Assert.assertEquals("Number of tuple emitted ", 2, sink.collectedTuples.size());
    CustOrder emitted = sink.collectedTuples.get(0);
    Assert.assertEquals("value of ID :", tuple.ID, emitted.ID);
    Assert.assertEquals("value of Name :", tuple.Name, emitted.Name);
    Assert.assertEquals("value of OID: ", order.OID, emitted.OID);
    Assert.assertEquals("value of Amount: ", order.Amount, emitted.Amount);
    emitted = sink.collectedTuples.get(1);
    Assert.assertEquals("value of ID :", tuple.ID, emitted.ID);
    Assert.assertEquals("value of Name :", tuple.Name, emitted.Name);
    Assert.assertEquals("value of OID: ", order3.OID, emitted.OID);
    Assert.assertEquals("value of Amount: ", order3.Amount, emitted.Amount);
    oper.teardown();
}
Also used : CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) PortContext(com.datatorrent.stram.engine.PortContext) Test(org.junit.Test)

Aggregations

PortContext (com.datatorrent.stram.engine.PortContext)9 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)7 Test (org.junit.Test)7 OperatorContext (com.datatorrent.api.Context.OperatorContext)3 Date (java.util.Date)3 OperatorContextTestHelper.mockOperatorContext (org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext)3 Attribute (com.datatorrent.api.Attribute)1 Context (com.datatorrent.api.Context)1 BaseContext (com.datatorrent.stram.api.BaseContext)1 Field (java.lang.reflect.Field)1 Random (java.util.Random)1