use of org.apache.samza.task.MessageCollector in project samza by apache.
the class TestJoinOperator method testJoinFnInitAndClose.
@Test
public void testJoinFnInitAndClose() throws Exception {
TestJoinFunction joinFn = new TestJoinFunction();
StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), new TestJoinStreamApplication(joinFn));
assertEquals(joinFn.getNumInitCalls(), 1);
MessageCollector messageCollector = mock(MessageCollector.class);
// push messages to first stream
numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator));
// close should not be called till now
assertEquals(joinFn.getNumCloseCalls(), 0);
sot.close();
// close should be called from sot.close()
assertEquals(joinFn.getNumCloseCalls(), 1);
}
use of org.apache.samza.task.MessageCollector in project samza by apache.
the class TestJoinOperator method joinRemovesExpiredMessagesReverse.
@Test
public void joinRemovesExpiredMessagesReverse() throws Exception {
TestClock testClock = new TestClock();
StreamOperatorTask sot = createStreamOperatorTask(testClock, new TestJoinStreamApplication(new TestJoinFunction()));
List<Integer> output = new ArrayList<>();
MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage());
// push messages to second stream
numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator));
// 1 minute after ttl
testClock.advanceTime(JOIN_TTL.plus(Duration.ofMinutes(1)));
// should expire second stream messages
sot.window(messageCollector, taskCoordinator);
// push messages to first stream with same key
numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator));
assertTrue(output.isEmpty());
}
use of org.apache.samza.task.MessageCollector in project samza by apache.
the class TestJoinOperator method joinRemovesExpiredMessages.
@Test
public void joinRemovesExpiredMessages() throws Exception {
TestClock testClock = new TestClock();
StreamOperatorTask sot = createStreamOperatorTask(testClock, new TestJoinStreamApplication(new TestJoinFunction()));
List<Integer> output = new ArrayList<>();
MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage());
// push messages to first stream
numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator));
// 1 minute after ttl
testClock.advanceTime(JOIN_TTL.plus(Duration.ofMinutes(1)));
// should expire first stream messages
sot.window(messageCollector, taskCoordinator);
// push messages to second stream with same key
numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator));
assertTrue(output.isEmpty());
}
use of org.apache.samza.task.MessageCollector in project samza by apache.
the class TestJoinOperator method joinRetainsLatestMessageForKey.
@Test
public void joinRetainsLatestMessageForKey() throws Exception {
StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), new TestJoinStreamApplication(new TestJoinFunction()));
List<Integer> output = new ArrayList<>();
MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage());
// push messages to first stream
numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator));
// push messages to first stream again with same keys but different values
numbers.forEach(n -> sot.process(new FirstStreamIME(n, 2 * n), messageCollector, taskCoordinator));
// push messages to second stream with same key
numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator));
int outputSum = output.stream().reduce(0, (s, m) -> s + m);
// should use latest messages in the first stream
assertEquals(165, outputSum);
}
use of org.apache.samza.task.MessageCollector in project samza by apache.
the class TestJoinOperator method joinRetainsMatchedMessages.
@Test
public void joinRetainsMatchedMessages() throws Exception {
StreamOperatorTask sot = createStreamOperatorTask(new SystemClock(), new TestJoinStreamApplication(new TestJoinFunction()));
List<Integer> output = new ArrayList<>();
MessageCollector messageCollector = envelope -> output.add((Integer) envelope.getMessage());
// push messages to first stream
numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator));
// push messages to second stream with same key
numbers.forEach(n -> sot.process(new SecondStreamIME(n, n), messageCollector, taskCoordinator));
int outputSum = output.stream().reduce(0, (s, m) -> s + m);
assertEquals(110, outputSum);
output.clear();
// push messages to first stream with same keys once again.
numbers.forEach(n -> sot.process(new FirstStreamIME(n, n), messageCollector, taskCoordinator));
int newOutputSum = output.stream().reduce(0, (s, m) -> s + m);
// should produce the same output as before
assertEquals(110, newOutputSum);
}
Aggregations