use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestOperatorSpec method testBroadcastOperatorSpec.
@Test
public void testBroadcastOperatorSpec() {
OutputStreamImpl<TestOutputMessageEnvelope> outputStream = new OutputStreamImpl<>("output-0", new StringSerde("UTF-8"), new JsonSerdeV2<TestOutputMessageEnvelope>(), true);
BroadcastOperatorSpec<TestOutputMessageEnvelope> broadcastOpSpec = new BroadcastOperatorSpec<>(outputStream, "broadcast-1");
BroadcastOperatorSpec<TestOutputMessageEnvelope> broadcastOpCopy = (BroadcastOperatorSpec<TestOutputMessageEnvelope>) OperatorSpecTestUtils.copyOpSpec(broadcastOpSpec);
assertNotEquals(broadcastOpCopy, broadcastOpSpec);
assertEquals(broadcastOpCopy.getOpId(), broadcastOpSpec.getOpId());
assertTrue(broadcastOpCopy.getOutputStream() != broadcastOpSpec.getOutputStream());
assertEquals(broadcastOpCopy.getOutputStream().getStreamId(), broadcastOpSpec.getOutputStream().getStreamId());
assertEquals(broadcastOpCopy.getOutputStream().isKeyed(), broadcastOpSpec.getOutputStream().isKeyed());
}
use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestMessageStreamImpl method testMap.
@Test
public void testMap() {
StreamApplicationDescriptorImpl mockGraph = mock(StreamApplicationDescriptorImpl.class);
OperatorSpec mockOpSpec = mock(OperatorSpec.class);
MessageStreamImpl<TestMessageEnvelope> inputStream = new MessageStreamImpl<>(mockGraph, mockOpSpec);
MapFunction<TestMessageEnvelope, TestOutputMessageEnvelope> mockMapFn = mock(MapFunction.class);
inputStream.map(mockMapFn);
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.MAP, registeredOpSpec.getOpCode());
TestOutputMessageEnvelope mockOutput = mock(TestOutputMessageEnvelope.class);
when(mockMapFn.apply(anyObject())).thenReturn(mockOutput);
assertTrue(transformFn.apply(new Object()).contains(mockOutput));
when(mockMapFn.apply(anyObject())).thenReturn(null);
assertTrue(transformFn.apply(null).isEmpty());
}
use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestMessageStreamImpl method testStreamTableJoin.
@Test
public void testStreamTableJoin() {
StreamApplicationDescriptorImpl mockGraph = mock(StreamApplicationDescriptorImpl.class);
OperatorSpec leftInputOpSpec = mock(OperatorSpec.class);
MessageStreamImpl<KV<String, TestMessageEnvelope>> source1 = new MessageStreamImpl<>(mockGraph, leftInputOpSpec);
OperatorSpec rightInputOpSpec = mock(OperatorSpec.class);
MessageStreamImpl<TestMessageEnvelope> source2 = new MessageStreamImpl<>(mockGraph, rightInputOpSpec);
TableImpl table = new TableImpl("t1");
source2.sendTo(table);
StreamTableJoinFunction<String, KV<String, TestMessageEnvelope>, KV<String, TestMessageEnvelope>, TestOutputMessageEnvelope> mockJoinFn = mock(StreamTableJoinFunction.class);
source1.join(table, mockJoinFn);
ArgumentCaptor<OperatorSpec> leftRegisteredOpCaptor = ArgumentCaptor.forClass(OperatorSpec.class);
verify(leftInputOpSpec).registerNextOperatorSpec(leftRegisteredOpCaptor.capture());
OperatorSpec<?, TestMessageEnvelope> leftRegisteredOpSpec = leftRegisteredOpCaptor.getValue();
assertTrue(leftRegisteredOpSpec instanceof StreamTableJoinOperatorSpec);
StreamTableJoinOperatorSpec joinOpSpec = (StreamTableJoinOperatorSpec) leftRegisteredOpSpec;
assertEquals(OpCode.JOIN, joinOpSpec.getOpCode());
assertEquals(mockJoinFn, joinOpSpec.getJoinFn());
assertEquals(table.getTableId(), joinOpSpec.getTableId());
}
use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestSinkOperatorImpl method testSinkOperatorSinkFunction.
@Test
public void testSinkOperatorSinkFunction() {
SinkFunction<TestOutputMessageEnvelope> sinkFn = mock(SinkFunction.class);
SinkOperatorImpl<TestOutputMessageEnvelope> sinkImpl = createSinkOperator(sinkFn);
TestOutputMessageEnvelope mockMsg = mock(TestOutputMessageEnvelope.class);
MessageCollector mockCollector = mock(MessageCollector.class);
TaskCoordinator mockCoordinator = mock(TaskCoordinator.class);
sinkImpl.handleMessage(mockMsg, mockCollector, mockCoordinator);
verify(sinkFn, times(1)).apply(mockMsg, mockCollector, mockCoordinator);
}
use of org.apache.samza.operators.data.TestOutputMessageEnvelope in project samza by apache.
the class TestSinkOperatorImpl method testSinkOperatorClose.
@Test
public void testSinkOperatorClose() {
TestOutputMessageEnvelope mockMsg = mock(TestOutputMessageEnvelope.class);
MessageCollector mockCollector = mock(MessageCollector.class);
TaskCoordinator mockCoordinator = mock(TaskCoordinator.class);
SinkFunction<TestOutputMessageEnvelope> sinkFn = mock(SinkFunction.class);
SinkOperatorImpl<TestOutputMessageEnvelope> sinkImpl = createSinkOperator(sinkFn);
sinkImpl.handleMessage(mockMsg, mockCollector, mockCoordinator);
verify(sinkFn, times(1)).apply(mockMsg, mockCollector, mockCoordinator);
// ensure that close is not called yet
verify(sinkFn, times(0)).close();
sinkImpl.handleClose();
// ensure that close is called once from handleClose()
verify(sinkFn, times(1)).close();
}
Aggregations