Search in sources :

Example 16 with TestOutputMessageEnvelope

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());
}
Also used : StringSerde(org.apache.samza.serializers.StringSerde) TestOutputMessageEnvelope(org.apache.samza.operators.data.TestOutputMessageEnvelope) Test(org.junit.Test)

Example 17 with TestOutputMessageEnvelope

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());
}
Also used : StreamOperatorSpec(org.apache.samza.operators.spec.StreamOperatorSpec) PartitionByOperatorSpec(org.apache.samza.operators.spec.PartitionByOperatorSpec) JoinOperatorSpec(org.apache.samza.operators.spec.JoinOperatorSpec) SendToTableOperatorSpec(org.apache.samza.operators.spec.SendToTableOperatorSpec) OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) SinkOperatorSpec(org.apache.samza.operators.spec.SinkOperatorSpec) OutputOperatorSpec(org.apache.samza.operators.spec.OutputOperatorSpec) WindowOperatorSpec(org.apache.samza.operators.spec.WindowOperatorSpec) StreamTableJoinOperatorSpec(org.apache.samza.operators.spec.StreamTableJoinOperatorSpec) IntermediateMessageStreamImpl(org.apache.samza.operators.stream.IntermediateMessageStreamImpl) StreamOperatorSpec(org.apache.samza.operators.spec.StreamOperatorSpec) TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) StreamApplicationDescriptorImpl(org.apache.samza.application.descriptors.StreamApplicationDescriptorImpl) FlatMapFunction(org.apache.samza.operators.functions.FlatMapFunction) TestOutputMessageEnvelope(org.apache.samza.operators.data.TestOutputMessageEnvelope) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 18 with TestOutputMessageEnvelope

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());
}
Also used : IntermediateMessageStreamImpl(org.apache.samza.operators.stream.IntermediateMessageStreamImpl) StreamOperatorSpec(org.apache.samza.operators.spec.StreamOperatorSpec) PartitionByOperatorSpec(org.apache.samza.operators.spec.PartitionByOperatorSpec) JoinOperatorSpec(org.apache.samza.operators.spec.JoinOperatorSpec) SendToTableOperatorSpec(org.apache.samza.operators.spec.SendToTableOperatorSpec) OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) SinkOperatorSpec(org.apache.samza.operators.spec.SinkOperatorSpec) OutputOperatorSpec(org.apache.samza.operators.spec.OutputOperatorSpec) WindowOperatorSpec(org.apache.samza.operators.spec.WindowOperatorSpec) StreamTableJoinOperatorSpec(org.apache.samza.operators.spec.StreamTableJoinOperatorSpec) TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) StreamApplicationDescriptorImpl(org.apache.samza.application.descriptors.StreamApplicationDescriptorImpl) TestOutputMessageEnvelope(org.apache.samza.operators.data.TestOutputMessageEnvelope) StreamTableJoinOperatorSpec(org.apache.samza.operators.spec.StreamTableJoinOperatorSpec) Test(org.junit.Test)

Example 19 with TestOutputMessageEnvelope

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);
}
Also used : MessageCollector(org.apache.samza.task.MessageCollector) TestOutputMessageEnvelope(org.apache.samza.operators.data.TestOutputMessageEnvelope) TaskCoordinator(org.apache.samza.task.TaskCoordinator) Test(org.junit.Test)

Example 20 with TestOutputMessageEnvelope

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();
}
Also used : MessageCollector(org.apache.samza.task.MessageCollector) TestOutputMessageEnvelope(org.apache.samza.operators.data.TestOutputMessageEnvelope) TaskCoordinator(org.apache.samza.task.TaskCoordinator) Test(org.junit.Test)

Aggregations

TestOutputMessageEnvelope (org.apache.samza.operators.data.TestOutputMessageEnvelope)20 Test (org.junit.Test)19 TestMessageEnvelope (org.apache.samza.operators.data.TestMessageEnvelope)15 FlatMapFunction (org.apache.samza.operators.functions.FlatMapFunction)7 ArrayList (java.util.ArrayList)5 Config (org.apache.samza.config.Config)5 JoinFunction (org.apache.samza.operators.functions.JoinFunction)5 MapFunction (org.apache.samza.operators.functions.MapFunction)5 Serde (org.apache.samza.serializers.Serde)5 StringSerde (org.apache.samza.serializers.StringSerde)5 MessageCollector (org.apache.samza.task.MessageCollector)5 TaskContext (org.apache.samza.task.TaskContext)5 TaskCoordinator (org.apache.samza.task.TaskCoordinator)5 KV (org.apache.samza.operators.KV)4 SinkFunction (org.apache.samza.operators.functions.SinkFunction)4 OperatorSpec (org.apache.samza.operators.spec.OperatorSpec)4 SinkOperatorSpec (org.apache.samza.operators.spec.SinkOperatorSpec)4 StreamOperatorSpec (org.apache.samza.operators.spec.StreamOperatorSpec)4 WindowOperatorSpec (org.apache.samza.operators.spec.WindowOperatorSpec)4 NoOpSerde (org.apache.samza.serializers.NoOpSerde)4