use of org.apache.samza.operators.spec.OperatorSpec 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.spec.OperatorSpec in project samza by apache.
the class TestMessageStreamImpl method testFlatMap.
@Test
public void testFlatMap() {
StreamApplicationDescriptorImpl mockGraph = mock(StreamApplicationDescriptorImpl.class);
OperatorSpec mockOpSpec = mock(OperatorSpec.class);
MessageStreamImpl<TestMessageEnvelope> inputStream = new MessageStreamImpl<>(mockGraph, mockOpSpec);
inputStream.flatMap(mock(FlatMapFunction.class));
ArgumentCaptor<OperatorSpec> registeredOpCaptor = ArgumentCaptor.forClass(OperatorSpec.class);
verify(mockOpSpec).registerNextOperatorSpec(registeredOpCaptor.capture());
OperatorSpec<?, TestMessageEnvelope> registeredOpSpec = registeredOpCaptor.getValue();
assertTrue(registeredOpSpec instanceof StreamOperatorSpec);
assertNotNull(((StreamOperatorSpec) registeredOpSpec).getTransformFn());
assertEquals(OpCode.FLAT_MAP, registeredOpSpec.getOpCode());
}
use of org.apache.samza.operators.spec.OperatorSpec 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());
}
use of org.apache.samza.operators.spec.OperatorSpec in project samza by apache.
the class TestOperatorSpecGraph method setUp.
@Before
public void setUp() {
this.mockAppDesc = mock(StreamApplicationDescriptorImpl.class);
/**
* Setup two linear transformation pipelines:
* 1) input1 --> filter --> sendTo
* 2) input2 --> map --> sink
*/
String inputStreamId1 = "test-input-1";
String outputStreamId = "test-output-1";
InputOperatorSpec testInput = new InputOperatorSpec(inputStreamId1, new NoOpSerde(), new NoOpSerde(), null, true, inputStreamId1);
StreamOperatorSpec filterOp = OperatorSpecs.createFilterOperatorSpec(m -> true, "test-filter-2");
OutputStreamImpl outputStream1 = new OutputStreamImpl(outputStreamId, null, null, true);
OutputOperatorSpec outputSpec = OperatorSpecs.createSendToOperatorSpec(outputStream1, "test-output-3");
testInput.registerNextOperatorSpec(filterOp);
filterOp.registerNextOperatorSpec(outputSpec);
String streamId2 = "test-input-2";
InputOperatorSpec testInput2 = new InputOperatorSpec(streamId2, new NoOpSerde(), new NoOpSerde(), null, true, "test-input-4");
StreamOperatorSpec testMap = OperatorSpecs.createMapOperatorSpec(m -> m, "test-map-5");
SinkOperatorSpec testSink = OperatorSpecs.createSinkOperatorSpec((m, mc, tc) -> {
}, "test-sink-6");
testInput2.registerNextOperatorSpec(testMap);
testMap.registerNextOperatorSpec(testSink);
this.inputOpSpecMap = new LinkedHashMap<>();
inputOpSpecMap.put(inputStreamId1, testInput);
inputOpSpecMap.put(streamId2, testInput2);
this.outputStrmMap = new LinkedHashMap<>();
outputStrmMap.put(outputStreamId, outputStream1);
when(mockAppDesc.getInputOperators()).thenReturn(Collections.unmodifiableMap(inputOpSpecMap));
when(mockAppDesc.getOutputStreams()).thenReturn(Collections.unmodifiableMap(outputStrmMap));
this.allOpSpecs = new HashSet<OperatorSpec>() {
{
this.add(testInput);
this.add(filterOp);
this.add(outputSpec);
this.add(testInput2);
this.add(testMap);
this.add(testSink);
}
};
}
use of org.apache.samza.operators.spec.OperatorSpec in project samza by apache.
the class OperatorImplGraph method computeOutputToInput.
private static void computeOutputToInput(SystemStream input, OperatorSpec opSpec, Multimap<SystemStream, SystemStream> outputToInputStreams, StreamConfig streamConfig) {
if (opSpec instanceof PartitionByOperatorSpec) {
PartitionByOperatorSpec spec = (PartitionByOperatorSpec) opSpec;
SystemStream systemStream = streamConfig.streamIdToSystemStream(spec.getOutputStream().getStreamId());
outputToInputStreams.put(systemStream, input);
} else if (opSpec instanceof BroadcastOperatorSpec) {
BroadcastOperatorSpec spec = (BroadcastOperatorSpec) opSpec;
SystemStream systemStream = streamConfig.streamIdToSystemStream(spec.getOutputStream().getStreamId());
outputToInputStreams.put(systemStream, input);
} else {
Collection<OperatorSpec> nextOperators = opSpec.getRegisteredOperatorSpecs();
nextOperators.forEach(spec -> computeOutputToInput(input, spec, outputToInputStreams, streamConfig));
}
}
Aggregations