use of org.apache.apex.malhar.lib.testbench.CountAndLastTupleTestSink in project apex-malhar by apache.
the class CompareExceptCountMapTest method testNodeProcessingSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(CompareExceptCountMap oper) {
CountAndLastTupleTestSink countSink = new CountAndLastTupleTestSink();
CountAndLastTupleTestSink exceptSink = new CountAndLastTupleTestSink();
oper.count.setSink(countSink);
oper.except.setSink(exceptSink);
oper.setKey("a");
oper.setValue(3.0);
oper.setTypeEQ();
oper.beginWindow(0);
HashMap<String, Number> input = new HashMap<String, Number>();
input.put("a", 2);
input.put("b", 20);
input.put("c", 1000);
oper.data.process(input);
input.clear();
input.put("a", 3);
oper.data.process(input);
input.clear();
input.put("a", 5);
oper.data.process(input);
oper.endWindow();
// One for each key
Assert.assertEquals("number emitted tuples", 1, exceptSink.count);
Assert.assertEquals("number emitted tuples", 1, countSink.count);
Assert.assertEquals("number emitted tuples", "2", exceptSink.tuple.toString());
Assert.assertEquals("number emitted tuples", "1", countSink.tuple.toString());
}
use of org.apache.apex.malhar.lib.testbench.CountAndLastTupleTestSink in project apex-malhar by apache.
the class MatchAnyMapTest method testNodeProcessingSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(MatchAnyMap oper) {
CountAndLastTupleTestSink matchSink = new CountAndLastTupleTestSink();
oper.any.setSink(matchSink);
oper.setKey("a");
oper.setValue(3.0);
oper.setTypeEQ();
oper.beginWindow(0);
HashMap<String, Number> input = new HashMap<String, Number>();
input.put("a", 3);
input.put("b", 20);
input.put("c", 1000);
oper.data.process(input);
input.clear();
input.put("a", 2);
oper.data.process(input);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, matchSink.count);
Boolean result = (Boolean) matchSink.tuple;
Assert.assertEquals("result was false", true, result);
matchSink.clear();
oper.beginWindow(0);
input.clear();
input.put("a", 2);
input.put("b", 20);
input.put("c", 1000);
oper.data.process(input);
input.clear();
input.put("a", 5);
oper.data.process(input);
oper.endWindow();
// There should be no emit as all tuples do not match
Assert.assertEquals("number emitted tuples", 0, matchSink.count);
matchSink.clear();
}
use of org.apache.apex.malhar.lib.testbench.CountAndLastTupleTestSink in project apex-malhar by apache.
the class MarginTest method testNodeProcessingSchema.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(Margin oper) {
CountAndLastTupleTestSink marginSink = new CountAndLastTupleTestSink();
oper.margin.setSink(marginSink);
oper.setPercent(true);
oper.beginWindow(0);
oper.numerator.process(2);
oper.numerator.process(20);
oper.numerator.process(100);
oper.denominator.process(200);
oper.denominator.process(22);
oper.denominator.process(22);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, marginSink.count);
Assert.assertEquals("margin was ", 50, ((Number) marginSink.tuple).intValue());
marginSink.clear();
oper.beginWindow(0);
oper.numerator.process(2);
oper.numerator.process(20);
oper.numerator.process(100);
oper.denominator.process(17);
oper.denominator.process(22);
oper.denominator.process(22);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, marginSink.count);
Assert.assertEquals("margin was ", -100, ((Number) marginSink.tuple).intValue());
marginSink.clear();
oper.beginWindow(0);
oper.numerator.process(2);
oper.numerator.process(20);
oper.numerator.process(100);
oper.denominator.process(17);
oper.denominator.process(22);
oper.denominator.process(-39);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 0, marginSink.count);
}
use of org.apache.apex.malhar.lib.testbench.CountAndLastTupleTestSink in project apex-malhar by apache.
the class UniqueCounterTest method testNodeProcessing.
/**
* Test node logic emits correct results
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testNodeProcessing() throws Exception {
UniqueCounter<String> oper = new UniqueCounter<String>();
CountAndLastTupleTestSink sink = new CountAndLastTupleTestSink<HashMap<String, Integer>>();
oper.count.setSink(sink);
String atuple = "a";
String btuple = "b";
String ctuple = "c";
String dtuple = "d";
int numTuples = 10000;
oper.beginWindow(0);
for (int i = 0; i < numTuples; i++) {
oper.data.process(atuple);
if (i % 2 == 0) {
oper.data.process(btuple);
}
if (i % 5 == 0) {
oper.data.process(ctuple);
}
}
oper.endWindow();
oper.beginWindow(1);
for (int i = 0; i < numTuples; i++) {
oper.data.process(atuple);
}
oper.endWindow();
HashMap<String, Integer> tuple = (HashMap<String, Integer>) sink.tuple;
int acount = tuple.get("a");
Assert.assertEquals("number emitted tuples", numTuples, acount);
oper.beginWindow(2);
for (int i = 0; i < numTuples; i++) {
if (i % 2 == 0) {
oper.data.process(btuple);
}
oper.data.process(btuple);
if (i % 10 == 0) {
oper.data.process(dtuple);
}
}
oper.endWindow();
tuple = (HashMap<String, Integer>) sink.tuple;
int bcount = tuple.get("b");
int dcount = tuple.get("d");
Assert.assertEquals("number emitted tuples", 3, sink.count);
Assert.assertEquals("number emitted tuples", numTuples + (numTuples / 2), bcount);
Assert.assertEquals("number emitted tuples", numTuples / 10, dcount);
}
use of org.apache.apex.malhar.lib.testbench.CountAndLastTupleTestSink in project apex-malhar by apache.
the class MaxKeyValTest method testSchemaNodeProcessing.
/**
* Test operator logic emits correct results for each schema.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testSchemaNodeProcessing(MaxKeyVal oper, String type) {
CountAndLastTupleTestSink maxSink = new CountAndLastTupleTestSink();
oper.max.setSink(maxSink);
oper.beginWindow(0);
int numtuples = 10000;
if (type.equals("integer")) {
for (int i = 0; i < numtuples; i++) {
oper.data.process(new KeyValPair("a", i));
}
} else if (type.equals("double")) {
for (int i = 0; i < numtuples; i++) {
oper.data.process(new KeyValPair("a", (double) i));
}
} else if (type.equals("long")) {
for (int i = 0; i < numtuples; i++) {
oper.data.process(new KeyValPair("a", (long) i));
}
} else if (type.equals("short")) {
// cannot cross 64K
int count = numtuples / 1000;
for (short j = 0; j < count; j++) {
oper.data.process(new KeyValPair("a", j));
}
} else if (type.equals("float")) {
for (int i = 0; i < numtuples; i++) {
oper.data.process(new KeyValPair("a", (float) i));
}
}
oper.endWindow();
Assert.assertEquals("number emitted tuples", 1, maxSink.count);
Number val = ((KeyValPair<String, Number>) maxSink.tuple).getValue().intValue();
if (type.equals("short")) {
Assert.assertEquals("emitted max value was ", (new Double(numtuples / 1000 - 1)).intValue(), val);
} else {
Assert.assertEquals("emitted max value was ", (new Double(numtuples - 1)).intValue(), val);
}
}
Aggregations