use of org.apache.samza.system.descriptors.GenericSystemDescriptor in project samza by apache.
the class TestOperatorImplGraph method testMergeChain.
@Test
public void testMergeChain() {
String inputStreamId = "input";
String inputSystem = "input-system";
StreamApplicationDescriptorImpl graphSpec = new StreamApplicationDescriptorImpl(appDesc -> {
GenericSystemDescriptor sd = new GenericSystemDescriptor(inputSystem, "mockFactoryClass");
GenericInputDescriptor inputDescriptor = sd.getInputDescriptor(inputStreamId, mock(Serde.class));
MessageStream<Object> inputStream = appDesc.getInputStream(inputDescriptor);
MessageStream<Object> stream1 = inputStream.filter(mock(FilterFunction.class));
MessageStream<Object> stream2 = inputStream.map(mock(MapFunction.class));
stream1.merge(Collections.singleton(stream2)).map(new TestMapFunction<Object, Object>("test-map-1", (Function & Serializable) m -> m));
}, getConfig());
TaskName mockTaskName = mock(TaskName.class);
TaskModel taskModel = mock(TaskModel.class);
when(taskModel.getTaskName()).thenReturn(mockTaskName);
when(this.context.getTaskContext().getTaskModel()).thenReturn(taskModel);
OperatorImplGraph opImplGraph = new OperatorImplGraph(graphSpec.getOperatorSpecGraph(), this.context, mock(Clock.class));
Set<OperatorImpl> opSet = opImplGraph.getAllInputOperators().stream().collect(HashSet::new, (s, op) -> addOperatorRecursively(s, op), HashSet::addAll);
Object[] mergeOps = opSet.stream().filter(op -> op.getOperatorSpec().getOpCode() == OpCode.MERGE).toArray();
assertEquals(1, mergeOps.length);
assertEquals(1, ((OperatorImpl) mergeOps[0]).registeredOperators.size());
OperatorImpl mapOp = (OperatorImpl) ((OperatorImpl) mergeOps[0]).registeredOperators.iterator().next();
assertEquals(mapOp.getOperatorSpec().getOpCode(), OpCode.MAP);
// verify that the DAG after merge is only traversed & initialized once
assertEquals(TestMapFunction.getInstanceByTaskName(mockTaskName, "test-map-1").numInitCalled, 1);
}
use of org.apache.samza.system.descriptors.GenericSystemDescriptor in project samza by apache.
the class TestJoinOperator method getTestJoinStreamGraph.
private StreamApplicationDescriptorImpl getTestJoinStreamGraph(TestJoinFunction joinFn) throws IOException {
Map<String, String> mapConfig = new HashMap<>();
mapConfig.put("job.name", "jobName");
mapConfig.put("job.id", "jobId");
StreamTestUtils.addStreamConfigs(mapConfig, "inStream", "insystem", "instream");
StreamTestUtils.addStreamConfigs(mapConfig, "inStream2", "insystem", "instream2");
Config config = new MapConfig(mapConfig);
return new StreamApplicationDescriptorImpl(appDesc -> {
IntegerSerde integerSerde = new IntegerSerde();
KVSerde<Integer, Integer> kvSerde = KVSerde.of(integerSerde, integerSerde);
GenericSystemDescriptor sd = new GenericSystemDescriptor("insystem", "mockFactoryClassName");
GenericInputDescriptor<KV<Integer, Integer>> inputDescriptor1 = sd.getInputDescriptor("inStream", kvSerde);
GenericInputDescriptor<KV<Integer, Integer>> inputDescriptor2 = sd.getInputDescriptor("inStream2", kvSerde);
MessageStream<KV<Integer, Integer>> inStream = appDesc.getInputStream(inputDescriptor1);
MessageStream<KV<Integer, Integer>> inStream2 = appDesc.getInputStream(inputDescriptor2);
inStream.join(inStream2, joinFn, integerSerde, kvSerde, kvSerde, JOIN_TTL, "j1").sink((message, messageCollector, taskCoordinator) -> {
SystemStream outputSystemStream = new SystemStream("outputSystem", "outputStream");
messageCollector.send(new OutgoingMessageEnvelope(outputSystemStream, message));
});
}, config);
}
use of org.apache.samza.system.descriptors.GenericSystemDescriptor in project samza by apache.
the class TestStreamApplicationDescriptorImpl method testGetInputStreamWithExpandingSystem.
@Test
public void testGetInputStreamWithExpandingSystem() {
String streamId = "test-stream-1";
String expandedStreamId = "expanded-stream";
AtomicInteger expandCallCount = new AtomicInteger();
StreamExpander expander = (sg, isd) -> {
expandCallCount.incrementAndGet();
InputDescriptor expandedISD = new GenericSystemDescriptor("expanded-system", "mockFactoryClass").getInputDescriptor(expandedStreamId, new IntegerSerde());
return sg.getInputStream(expandedISD);
};
MockExpandingSystemDescriptor sd = new MockExpandingSystemDescriptor("mock-system", expander);
MockInputDescriptor isd = sd.getInputDescriptor(streamId, new IntegerSerde());
StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> {
appDesc.getInputStream(isd);
}, getConfig());
InputOperatorSpec inputOpSpec = streamAppDesc.getInputOperators().get(expandedStreamId);
assertEquals(OpCode.INPUT, inputOpSpec.getOpCode());
assertEquals(1, expandCallCount.get());
assertFalse(streamAppDesc.getInputOperators().containsKey(streamId));
assertFalse(streamAppDesc.getInputDescriptors().containsKey(streamId));
assertTrue(streamAppDesc.getInputDescriptors().containsKey(expandedStreamId));
assertEquals(expandedStreamId, inputOpSpec.getStreamId());
}
use of org.apache.samza.system.descriptors.GenericSystemDescriptor in project samza by apache.
the class SystemConsumerWithSamzaBench method start.
public void start() throws IOException, InterruptedException {
super.start();
MessageConsumer consumeFn = new MessageConsumer();
StreamApplication app = appDesc -> {
String systemFactoryName = new SystemConfig(config).getSystemFactory(systemName).get();
GenericSystemDescriptor sd = new GenericSystemDescriptor(systemName, systemFactoryName);
GenericInputDescriptor<Object> isd = sd.getInputDescriptor(streamId, new NoOpSerde<>());
MessageStream<Object> stream = appDesc.getInputStream(isd);
stream.map(consumeFn);
};
ApplicationRunner runner = ApplicationRunners.getApplicationRunner(app, new MapConfig());
runner.run();
while (consumeFn.getEventsConsumed() < totalEvents) {
Thread.sleep(10);
}
Instant endTime = Instant.now();
runner.kill();
System.out.println("\n*******************");
System.out.println(String.format("Started at %s Ending at %s ", consumeFn.startTime, endTime));
System.out.println(String.format("Event Rate is %s Messages/Sec ", consumeFn.getEventsConsumed() * 1000 / Duration.between(consumeFn.startTime, Instant.now()).toMillis()));
System.out.println("Event Rate is " + consumeFn.getEventsConsumed() * 1000 / Duration.between(consumeFn.startTime, endTime).toMillis());
System.out.println("*******************\n");
System.exit(0);
}
use of org.apache.samza.system.descriptors.GenericSystemDescriptor in project samza by apache.
the class TestStreamApplicationDescriptorImpl method testSetDefaultSystemDescriptorAfterGettingInputStream.
@Test(expected = IllegalStateException.class)
public void testSetDefaultSystemDescriptorAfterGettingInputStream() {
String streamId = "test-stream-1";
GenericSystemDescriptor sd = new GenericSystemDescriptor("mockSystem", "mockSystemFactoryClass");
GenericInputDescriptor isd = sd.getInputDescriptor(streamId, mock(Serde.class));
new StreamApplicationDescriptorImpl(appDesc -> {
appDesc.getInputStream(isd);
// should throw exception
appDesc.withDefaultSystem(sd);
}, getConfig());
}
Aggregations