use of org.apache.samza.operators.functions.FlatMapFunction in project samza by apache.
the class TestMessageStreamImpl method testFilter.
@Test
public void testFilter() {
StreamApplicationDescriptorImpl mockGraph = mock(StreamApplicationDescriptorImpl.class);
OperatorSpec mockOpSpec = mock(OperatorSpec.class);
MessageStreamImpl<TestMessageEnvelope> inputStream = new MessageStreamImpl<>(mockGraph, mockOpSpec);
FilterFunction<Object> mockFilterFn = mock(FilterFunction.class);
inputStream.filter(mockFilterFn);
ArgumentCaptor<OperatorSpec> registeredOpCaptor = ArgumentCaptor.forClass(OperatorSpec.class);
verify(mockOpSpec).registerNextOperatorSpec(registeredOpCaptor.capture());
OperatorSpec<?, TestMessageEnvelope> registeredOpSpec = registeredOpCaptor.getValue();
assertTrue(registeredOpSpec instanceof StreamOperatorSpec);
FlatMapFunction transformFn = ((StreamOperatorSpec) registeredOpSpec).getTransformFn();
assertNotNull(transformFn);
assertEquals(OpCode.FILTER, registeredOpSpec.getOpCode());
Object mockInput = new Object();
when(mockFilterFn.apply(anyObject())).thenReturn(true);
assertTrue(transformFn.apply(mockInput).contains(mockInput));
when(mockFilterFn.apply(anyObject())).thenReturn(false);
assertTrue(transformFn.apply(mockInput).isEmpty());
}
Aggregations