use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class DivisionTest method testNodeProcessing.
/**
* Test operator logic emits correct results.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testNodeProcessing() {
Division oper = new Division();
CollectorTestSink lqSink = new CollectorTestSink();
CollectorTestSink iqSink = new CollectorTestSink();
CollectorTestSink dqSink = new CollectorTestSink();
CollectorTestSink fqSink = new CollectorTestSink();
CollectorTestSink lrSink = new CollectorTestSink();
CollectorTestSink irSink = new CollectorTestSink();
CollectorTestSink drSink = new CollectorTestSink();
CollectorTestSink frSink = new CollectorTestSink();
CollectorTestSink eSink = new CollectorTestSink();
oper.longQuotient.setSink(lqSink);
oper.integerQuotient.setSink(iqSink);
oper.doubleQuotient.setSink(dqSink);
oper.floatQuotient.setSink(fqSink);
oper.longRemainder.setSink(lrSink);
oper.doubleRemainder.setSink(drSink);
oper.floatRemainder.setSink(frSink);
oper.integerRemainder.setSink(irSink);
oper.errordata.setSink(eSink);
//
oper.beginWindow(0);
oper.denominator.process(5);
oper.numerator.process(11);
oper.denominator.process(0);
//
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, lqSink.collectedTuples.size());
Assert.assertEquals("number emitted tuples", 1, iqSink.collectedTuples.size());
Assert.assertEquals("number emitted tuples", 1, dqSink.collectedTuples.size());
Assert.assertEquals("number emitted tuples", 1, fqSink.collectedTuples.size());
Assert.assertEquals("number emitted tuples", 1, lrSink.collectedTuples.size());
Assert.assertEquals("number emitted tuples", 1, irSink.collectedTuples.size());
Assert.assertEquals("number emitted tuples", 1, drSink.collectedTuples.size());
Assert.assertEquals("number emitted tuples", 1, frSink.collectedTuples.size());
Assert.assertEquals("number emitted tuples", 1, eSink.collectedTuples.size());
Assert.assertEquals("quotient is", new Long(2), lqSink.collectedTuples.get(0));
Assert.assertEquals("quotient is", 2, iqSink.collectedTuples.get(0));
Assert.assertEquals("quotient is", 2.2, dqSink.collectedTuples.get(0));
Assert.assertEquals("quotient is", new Float(2.2), fqSink.collectedTuples.get(0));
Assert.assertEquals("quotient is", new Long(1), lrSink.collectedTuples.get(0));
Assert.assertEquals("quotient is", 1, irSink.collectedTuples.get(0));
Assert.assertEquals("quotient is", 1.0, drSink.collectedTuples.get(0));
Assert.assertEquals("quotient is", new Float(1.0), frSink.collectedTuples.get(0));
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class LogicalCompareToConstantTest method testNodeProcessing.
/**
* Test operator logic emits correct results.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testNodeProcessing() {
LogicalCompareToConstant<Integer> oper = new LogicalCompareToConstant<Integer>() {
};
CollectorTestSink eSink = new CollectorTestSink();
CollectorTestSink neSink = new CollectorTestSink();
CollectorTestSink gtSink = new CollectorTestSink();
CollectorTestSink gteSink = new CollectorTestSink();
CollectorTestSink ltSink = new CollectorTestSink();
CollectorTestSink lteSink = new CollectorTestSink();
oper.equalTo.setSink(eSink);
oper.notEqualTo.setSink(neSink);
oper.greaterThan.setSink(gtSink);
oper.greaterThanOrEqualTo.setSink(gteSink);
oper.lessThan.setSink(ltSink);
oper.lessThanOrEqualTo.setSink(lteSink);
oper.setConstant(2);
//
oper.beginWindow(0);
oper.input.process(1);
oper.input.process(2);
oper.input.process(3);
//
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, eSink.collectedTuples.size());
Assert.assertEquals("tuples were", eSink.collectedTuples.get(0).equals(2), true);
Assert.assertEquals("number emitted tuples", 2, neSink.collectedTuples.size());
Assert.assertEquals("tuples were", neSink.collectedTuples.get(0).equals(1), true);
Assert.assertEquals("tuples were", neSink.collectedTuples.get(1).equals(3), true);
Assert.assertEquals("number emitted tuples", 1, gtSink.collectedTuples.size());
Assert.assertEquals("tuples were", gtSink.collectedTuples.get(0).equals(1), true);
Assert.assertEquals("number emitted tuples", 2, gteSink.collectedTuples.size());
Assert.assertEquals("tuples were", gteSink.collectedTuples.get(0).equals(1), true);
Assert.assertEquals("tuples were", gteSink.collectedTuples.get(1).equals(2), true);
Assert.assertEquals("number emitted tuples", 1, ltSink.collectedTuples.size());
Assert.assertEquals("tuples were", ltSink.collectedTuples.get(0).equals(3), true);
Assert.assertEquals("number emitted tuples", 2, lteSink.collectedTuples.size());
Assert.assertEquals("tuples were", lteSink.collectedTuples.get(0).equals(2), true);
Assert.assertEquals("tuples were", lteSink.collectedTuples.get(1).equals(3), true);
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class SlidingWindowTest method testNodeProcessing.
/**
* Test functional logic
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testNodeProcessing() throws InterruptedException {
TestSlidingWindow oper = new TestSlidingWindow();
CollectorTestSink swinSink = new CollectorTestSink();
oper.out.setSink(swinSink);
oper.setWindowSize(3);
oper.setup(null);
oper.beginWindow(0);
oper.data.process("a0");
oper.data.process("b0");
oper.endWindow();
oper.beginWindow(1);
oper.data.process("a1");
oper.data.process("b1");
oper.endWindow();
oper.beginWindow(2);
oper.data.process("a2");
oper.data.process("b2");
oper.endWindow();
oper.beginWindow(3);
oper.data.process("a3");
oper.data.process("b3");
oper.endWindow();
Assert.assertEquals("number emitted tuples", 4, swinSink.collectedTuples.size());
Assert.assertEquals("Invalid second stream window state.", oper.getStreamingWindowState(1), Lists.newArrayList("a2", "b2"));
Assert.assertEquals("Invalid expired stream window state.", oper.lastExpiredWindowState, Lists.newArrayList("a0", "b0"));
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class POJOInnerJoinOperatorTest method testUpdateStream1Values.
@Test
public void testUpdateStream1Values() 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);
oper.endWindow();
oper.beginWindow(1);
Customer tuple2 = new Customer(1, "Join");
oper.input1.process(tuple2);
Order order = new Order(102, 1, 300);
oper.input2.process(order);
Order order2 = new Order(103, 3, 300);
oper.input2.process(order2);
oper.endWindow();
/* Number of tuple, emitted */
Assert.assertEquals("Number of tuple emitted ", 1, sink.collectedTuples.size());
CustOrder emitted = sink.collectedTuples.get(0);
Assert.assertEquals("value of ID :", tuple2.ID, emitted.ID);
Assert.assertEquals("value of Name :", tuple2.Name, emitted.Name);
Assert.assertEquals("value of OID: ", order.OID, emitted.OID);
Assert.assertEquals("value of Amount: ", order.Amount, emitted.Amount);
oper.teardown();
}
use of org.apache.apex.malhar.lib.testbench.CollectorTestSink in project apex-malhar by apache.
the class POJOTimeBasedJoinOperatorTest method testFullOuterJoinOperator.
@Test
public void testFullOuterJoinOperator() throws IOException, InterruptedException {
Kryo kryo = new Kryo();
POJOJoinOperator oper = new POJOJoinOperator();
JoinStore store = new InMemoryStore(200, 200);
oper.setLeftStore(kryo.copy(store));
oper.setRightStore(kryo.copy(store));
oper.setIncludeFields("ID,Name;OID,Amount");
oper.setKeyFields("ID,CID");
oper.outputClass = CustOrder.class;
oper.setStrategy("outer_join");
oper.setup(MapTimeBasedJoinOperator.context);
CollectorTestSink<List<CustOrder>> sink = new CollectorTestSink<List<CustOrder>>();
@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);
CountDownLatch latch = new CountDownLatch(1);
Order order = new Order(102, 3, 300);
oper.input2.process(order);
Order order2 = new Order(103, 7, 300);
oper.input2.process(order2);
oper.endWindow();
latch.await(500, TimeUnit.MILLISECONDS);
oper.beginWindow(1);
Order order3 = new Order(104, 5, 300);
oper.input2.process(order3);
Customer tuple2 = new Customer(5, "DT");
oper.input1.process(tuple2);
latch.await(500, TimeUnit.MILLISECONDS);
oper.endWindow();
latch.await(500, TimeUnit.MILLISECONDS);
oper.beginWindow(2);
oper.endWindow();
latch.await(5000, TimeUnit.MILLISECONDS);
/* Number of tuple, emitted */
Assert.assertEquals("Number of tuple emitted ", 3, sink.collectedTuples.size());
Iterator<List<CustOrder>> ite = sink.collectedTuples.iterator();
List<CustOrder> emittedList = ite.next();
CustOrder emitted = emittedList.get(0);
Assert.assertEquals("value of ID :", tuple2.ID, emitted.ID);
Assert.assertEquals("value of Name :", tuple2.Name, emitted.Name);
Assert.assertEquals("value of OID: ", order3.OID, emitted.OID);
Assert.assertEquals("value of Amount: ", order3.Amount, emitted.Amount);
emittedList = ite.next();
Assert.assertEquals("Joined Tuple ", "{ID=1, Name='Anil', OID=0, Amount=0}", emittedList.get(0).toString());
emittedList = ite.next();
Assert.assertEquals("Joined Tuple ", "{ID=0, Name='null', OID=102, Amount=300}", emittedList.get(0).toString());
Assert.assertEquals("Joined Tuple ", "{ID=0, Name='null', OID=103, Amount=300}", emittedList.get(1).toString());
}
Aggregations