use of edu.snu.mist.core.MistWatermarkEvent in project mist by snuspl.
the class ConditionalBranchOperatorTest method testConditionalBranchOperator.
/**
* Test conditional branch operation.
* It classifies the input string according to it's length.
*/
@Test
public void testConditionalBranchOperator() throws InjectionException {
// input stream events
final MistDataEvent d1 = new MistDataEvent("1", 1L);
final MistDataEvent d2 = new MistDataEvent("22", 2L);
final MistDataEvent d3 = new MistDataEvent("333", 3L);
final MistDataEvent d4 = new MistDataEvent("4444", 4L);
final MistDataEvent d5 = new MistDataEvent("55555", 5L);
final MistWatermarkEvent w1 = new MistWatermarkEvent(6L);
// classify the string according to it's length
final List<MISTPredicate<String>> predicates = new ArrayList<>();
// "1" will be passed with index 1
predicates.add((input) -> input.length() < 2);
// "22" will be passed with index 2
predicates.add((input) -> input.length() < 3);
// "333", "4444" will be passed with index 3
predicates.add((input) -> input.length() < 5);
// "55555" will not be passed
final List<Tuple<MistEvent, Integer>> result = new LinkedList<>();
final ConditionalBranchOperator<String> conditionalBranchOperator = new ConditionalBranchOperator<>(predicates);
conditionalBranchOperator.setOutputEmitter(new IndexOutputEmitter(result));
conditionalBranchOperator.processLeftData(d1);
conditionalBranchOperator.processLeftData(d2);
conditionalBranchOperator.processLeftData(d3);
conditionalBranchOperator.processLeftData(d4);
conditionalBranchOperator.processLeftData(d5);
conditionalBranchOperator.processLeftWatermark(w1);
Assert.assertEquals(5, result.size());
Assert.assertEquals(new Tuple<>(d1, 1), result.get(0));
Assert.assertEquals(new Tuple<>(d2, 2), result.get(1));
Assert.assertEquals(new Tuple<>(d3, 3), result.get(2));
Assert.assertEquals(new Tuple<>(d4, 3), result.get(3));
Assert.assertEquals(new Tuple<>(w1, 0), result.get(4));
}
Aggregations