Search in sources :

Example 46 with CollectorTestSink

use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.

the class InConditionTest method testSqlSelect.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlSelect() {
    // create operator
    SelectOperator oper = new SelectOperator();
    oper.addIndex(new ColumnIndex("b", null));
    oper.addIndex(new ColumnIndex("c", null));
    InCondition cond = new InCondition("a");
    cond.addInValue(0);
    cond.addInValue(1);
    oper.setCondition(cond);
    CollectorTestSink sink = new CollectorTestSink();
    oper.outport.setSink(sink);
    oper.setup(null);
    oper.beginWindow(1);
    HashMap<String, Object> tuple = new HashMap<String, Object>();
    tuple.put("a", 0);
    tuple.put("b", 1);
    tuple.put("c", 2);
    oper.inport.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", 1);
    tuple.put("b", 3);
    tuple.put("c", 4);
    oper.inport.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", 2);
    tuple.put("b", 5);
    tuple.put("c", 6);
    oper.inport.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", 3);
    tuple.put("b", 7);
    tuple.put("c", 8);
    oper.inport.process(tuple);
    oper.endWindow();
    oper.teardown();
    LOG.debug("{}", sink.collectedTuples);
}
Also used : SelectOperator(org.apache.apex.malhar.contrib.misc.streamquery.SelectOperator) ColumnIndex(org.apache.apex.malhar.lib.streamquery.index.ColumnIndex) HashMap(java.util.HashMap) InCondition(org.apache.apex.malhar.contrib.misc.streamquery.condition.InCondition) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Example 47 with CollectorTestSink

use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.

the class SelectCountTest method testSqlSelect.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlSelect() {
    // create operator
    SelectFunctionOperator oper = new SelectFunctionOperator();
    oper.addSqlFunction(new CountFunction("b", null));
    CollectorTestSink sink = new CollectorTestSink();
    oper.outport.setSink(sink);
    oper.setup(null);
    oper.beginWindow(1);
    HashMap<String, Object> tuple = new HashMap<String, Object>();
    tuple.put("a", 0);
    tuple.put("b", null);
    tuple.put("c", 2);
    oper.inport.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", 1);
    tuple.put("b", null);
    tuple.put("c", 4);
    oper.inport.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", 1);
    tuple.put("b", 5);
    tuple.put("c", 6);
    oper.inport.process(tuple);
    oper.endWindow();
    oper.teardown();
    LOG.debug("{}", sink.collectedTuples);
}
Also used : SelectFunctionOperator(org.apache.apex.malhar.contrib.misc.streamquery.SelectFunctionOperator) HashMap(java.util.HashMap) CountFunction(org.apache.apex.malhar.contrib.misc.streamquery.function.CountFunction) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Example 48 with CollectorTestSink

use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.

the class MongoDBInputOperatorTest method MongoDBInputOperatorTest.

@Test
public void MongoDBInputOperatorTest() {
    MyMongoDBInputOperator oper = new MyMongoDBInputOperator();
    oper.setHostName("localhost");
    oper.setDataBase("test");
    oper.setUserName("test");
    oper.setPassWord("123");
    oper.setTable("t1");
    // AttributeMap<DAGContext> attrmap = new DefaultAttributeMap<DAGContext>();
    // attrmap.attr(DAG.STRAM_APP_ID).set("myMongoDBInputOperatorAppId");
    oper.setup(mockOperatorContext(1));
    oper.beginWindow(0);
    CollectorTestSink sink = new CollectorTestSink();
    oper.outputPort.setSink(sink);
    oper.emitTuples();
    oper.endWindow();
    oper.teardown();
}
Also used : CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Example 49 with CollectorTestSink

use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.

the class CountKeyValTest method testNodeProcessing.

/**
 * Test operator logic emits correct results.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testNodeProcessing() {
    CountKeyVal<String, Double> oper = new CountKeyVal<String, Double>();
    CollectorTestSink countSink = new CollectorTestSink();
    oper.count.setSink(countSink);
    // 
    oper.beginWindow(0);
    oper.data.process(new KeyValPair("a", 2.0));
    oper.data.process(new KeyValPair("b", 20.0));
    oper.data.process(new KeyValPair("c", 1000.0));
    oper.data.process(new KeyValPair("a", 1.0));
    oper.data.process(new KeyValPair("a", 10.0));
    oper.data.process(new KeyValPair("b", 5.0));
    oper.data.process(new KeyValPair("d", 55.0));
    oper.data.process(new KeyValPair("b", 12.0));
    oper.data.process(new KeyValPair("d", 22.0));
    oper.data.process(new KeyValPair("d", 14.2));
    oper.data.process(new KeyValPair("d", 46.0));
    oper.data.process(new KeyValPair("e", 2.0));
    oper.data.process(new KeyValPair("a", 23.0));
    oper.data.process(new KeyValPair("d", 4.0));
    // 
    oper.endWindow();
    // payload should be 1 bag of tuples with keys "a", "b", "c", "d", "e"
    Assert.assertEquals("number emitted tuples", 5, countSink.collectedTuples.size());
    for (Object o : countSink.collectedTuples) {
        KeyValPair<String, Integer> e = (KeyValPair<String, Integer>) o;
        Integer val = (Integer) e.getValue();
        if (e.getKey().equals("a")) {
            Assert.assertEquals("emitted value for 'a' was ", 4, val.intValue());
        } else if (e.getKey().equals("b")) {
            Assert.assertEquals("emitted tuple for 'b' was ", 3, val.intValue());
        } else if (e.getKey().equals("c")) {
            Assert.assertEquals("emitted tuple for 'c' was ", 1, val.intValue());
        } else if (e.getKey().equals("d")) {
            Assert.assertEquals("emitted tuple for 'd' was ", 5, val.intValue());
        } else if (e.getKey().equals("e")) {
            Assert.assertEquals("emitted tuple for 'e' was ", 1, val.intValue());
        }
    }
}
Also used : KeyValPair(org.apache.apex.malhar.lib.util.KeyValPair) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Example 50 with CollectorTestSink

use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.

the class LeftOuterJoinOperatorTest method testSqlSelect.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlSelect() {
    // create operator
    OuterJoinOperator oper = new OuterJoinOperator();
    CollectorTestSink sink = new CollectorTestSink();
    oper.outport.setSink(sink);
    // set column join condition
    Condition cond = new JoinColumnEqualCondition("a", "a");
    oper.setJoinCondition(cond);
    // add columns
    oper.selectTable1Column(new ColumnIndex("b", null));
    oper.selectTable2Column(new ColumnIndex("c", null));
    oper.setup(null);
    oper.beginWindow(1);
    HashMap<String, Object> tuple = new HashMap<String, Object>();
    tuple.put("a", 0);
    tuple.put("b", 1);
    tuple.put("c", 2);
    oper.inport1.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", 1);
    tuple.put("b", 3);
    tuple.put("c", 4);
    oper.inport1.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", 2);
    tuple.put("b", 11);
    tuple.put("c", 12);
    oper.inport1.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", 0);
    tuple.put("b", 7);
    tuple.put("c", 8);
    oper.inport2.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", 1);
    tuple.put("b", 5);
    tuple.put("c", 6);
    oper.inport2.process(tuple);
    oper.endWindow();
    oper.teardown();
    LOG.debug("{}", sink.collectedTuples);
}
Also used : Condition(org.apache.apex.malhar.lib.streamquery.condition.Condition) JoinColumnEqualCondition(org.apache.apex.malhar.lib.streamquery.condition.JoinColumnEqualCondition) ColumnIndex(org.apache.apex.malhar.lib.streamquery.index.ColumnIndex) HashMap(java.util.HashMap) JoinColumnEqualCondition(org.apache.apex.malhar.lib.streamquery.condition.JoinColumnEqualCondition) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Aggregations

CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)162 Test (org.junit.Test)133 HashMap (java.util.HashMap)56 Map (java.util.Map)33 File (java.io.File)21 ArrayList (java.util.ArrayList)21 OperatorContext (com.datatorrent.api.Context.OperatorContext)19 OperatorContextTestHelper.mockOperatorContext (org.apache.apex.malhar.lib.helper.OperatorContextTestHelper.mockOperatorContext)18 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)15 Path (org.apache.hadoop.fs.Path)15 Attribute (com.datatorrent.api.Attribute)14 ColumnIndex (org.apache.apex.malhar.lib.streamquery.index.ColumnIndex)13 LineByLineFileInputOperator (org.apache.apex.malhar.lib.fs.LineByLineFileInputOperator)12 Kryo (com.esotericsoftware.kryo.Kryo)10 Date (java.util.Date)8 TestPortContext (org.apache.apex.malhar.lib.helper.TestPortContext)8 PortContext (com.datatorrent.stram.engine.PortContext)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 SelectOperator (org.apache.apex.malhar.contrib.misc.streamquery.SelectOperator)6