Search in sources :

Example 71 with CollectorTestSink

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

the class SelectOperatorTest 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));
    EqualValueCondition condition = new EqualValueCondition();
    condition.addEqualValue("a", 1);
    oper.setCondition(condition);
    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", 1);
    tuple.put("b", 5);
    tuple.put("c", 6);
    oper.inport.process(tuple);
    oper.endWindow();
    oper.teardown();
    LOG.debug("{}", sink.collectedTuples);
}
Also used : ColumnIndex(org.apache.apex.malhar.lib.streamquery.index.ColumnIndex) EqualValueCondition(org.apache.apex.malhar.contrib.misc.streamquery.condition.EqualValueCondition) HashMap(java.util.HashMap) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Example 72 with CollectorTestSink

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

the class UpdateOperatorTest method testSqlSelect.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSqlSelect() {
    // create operator
    UpdateOperator oper = new UpdateOperator();
    EqualValueCondition condition = new EqualValueCondition();
    condition.addEqualValue("a", 1);
    oper.setCondition(condition);
    oper.addUpdate("c", 100);
    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", 1);
    tuple.put("b", 5);
    tuple.put("c", 6);
    oper.inport.process(tuple);
    oper.endWindow();
    oper.teardown();
    LOG.debug("{}", sink.collectedTuples);
}
Also used : EqualValueCondition(org.apache.apex.malhar.contrib.misc.streamquery.condition.EqualValueCondition) HashMap(java.util.HashMap) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Example 73 with CollectorTestSink

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

the class CompoundConditionTest 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));
    EqualValueCondition left = new EqualValueCondition();
    left.addEqualValue("a", 1);
    EqualValueCondition right = new EqualValueCondition();
    right.addEqualValue("b", 1);
    oper.setCondition(new CompoundCondition(left, right));
    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", 1);
    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) EqualValueCondition(org.apache.apex.malhar.contrib.misc.streamquery.condition.EqualValueCondition) HashMap(java.util.HashMap) CompoundCondition(org.apache.apex.malhar.contrib.misc.streamquery.condition.CompoundCondition) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Example 74 with CollectorTestSink

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

the class LikeConditionTest 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));
    LikeCondition condition = new LikeCondition("a", "test*");
    oper.setCondition(condition);
    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", "testing");
    tuple.put("b", 1);
    tuple.put("c", 2);
    oper.inport.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", "null");
    tuple.put("b", 3);
    tuple.put("c", 4);
    oper.inport.process(tuple);
    tuple = new HashMap<String, Object>();
    tuple.put("a", "testall");
    tuple.put("b", 5);
    tuple.put("c", 6);
    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) LikeCondition(org.apache.apex.malhar.contrib.misc.streamquery.condition.LikeCondition) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink) Test(org.junit.Test)

Example 75 with CollectorTestSink

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

the class ChangeAlertTest method testNodeProcessingSchema.

@SuppressWarnings({ "rawtypes", "unchecked" })
public <V extends Number> void testNodeProcessingSchema(ChangeAlert<V> oper) {
    CollectorTestSink alertSink = new CollectorTestSink();
    oper.alert.setSink(alertSink);
    oper.setPercentThreshold(5);
    oper.beginWindow(0);
    oper.data.process(oper.getValue(10));
    // alert
    oper.data.process(oper.getValue(12));
    oper.data.process(oper.getValue(12));
    // alert
    oper.data.process(oper.getValue(18));
    // alert
    oper.data.process(oper.getValue(0));
    // this will not alert
    oper.data.process(oper.getValue(20));
    // alert
    oper.data.process(oper.getValue(30));
    oper.endWindow();
    // One for a, Two for b
    Assert.assertEquals("number emitted tuples", 4, alertSink.collectedTuples.size());
    double aval = 0;
    log.debug("\nLogging tuples");
    for (Object o : alertSink.collectedTuples) {
        KeyValPair<Number, Double> map = (KeyValPair<Number, Double>) o;
        log.debug(o.toString());
        aval += map.getValue().doubleValue();
    }
    Assert.assertEquals("change in a", 220.0, aval, 0);
}
Also used : KeyValPair(org.apache.apex.malhar.lib.util.KeyValPair) CollectorTestSink(org.apache.apex.malhar.lib.testbench.CollectorTestSink)

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