use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink in project streamline by hortonworks.
the class TestTopologyDagCreatingVisitorTest method visitSink_connectedFromProcessor.
@Test
public void visitSink_connectedFromProcessor() throws Exception {
StreamlineProcessor originProcessor = TopologyTestHelper.createStreamlineProcessor("1");
StreamlineSink originSink = TopologyTestHelper.createStreamlineSink("2");
TopologyDag originTopologyDag = new TopologyDag();
originTopologyDag.add(originProcessor);
originTopologyDag.add(originSink);
originTopologyDag.addEdge(new Edge("e1", originProcessor, originSink, "default", Stream.Grouping.SHUFFLE));
TestRunProcessor testProcessor = createTestRunProcessor(originProcessor);
TestRunSink testSink = createTestRunSink(originSink);
TestTopologyDagCreatingVisitor visitor = new TestTopologyDagCreatingVisitor(originTopologyDag, Collections.emptyMap(), Collections.singletonMap(originProcessor.getName(), testProcessor), Collections.emptyMap(), Collections.singletonMap(originSink.getName(), testSink));
visitor.visit(originProcessor);
visitor.visit(originSink);
TopologyDag testTopologyDag = visitor.getTestTopologyDag();
List<OutputComponent> testProcessors = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunProcessor && o.getName().equals(originProcessor.getName()))).collect(toList());
List<InputComponent> testSinks = testTopologyDag.getInputComponents().stream().filter(o -> (o instanceof TestRunSink && o.getName().equals(originSink.getName()))).collect(toList());
assertEquals(1, testProcessors.size());
assertEquals(1, testSinks.size());
TestRunProcessor testRunProcessor = (TestRunProcessor) testProcessors.get(0);
assertEquals(originProcessor.getId(), testRunProcessor.getId());
TestRunSink testRunSink = (TestRunSink) testSinks.get(0);
assertEquals(originSink.getId(), testRunSink.getId());
assertEquals(testSink.getOutputFilePath(), testRunSink.getOutputFilePath());
assertEquals(1, testTopologyDag.getEdgesFrom(testProcessor).size());
assertEquals(1, testTopologyDag.getEdgesTo(testRunSink).size());
assertTrue(testTopologyDag.getEdgesFrom(testRunProcessor).get(0) == testTopologyDag.getEdgesTo(testRunSink).get(0));
}
use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink in project streamline by hortonworks.
the class TestTopologyDagCreatingVisitorTest method createTestRunSink.
private TestRunSink createTestRunSink(StreamlineSink originSink) {
TestRunSink testRunSink = new TestRunSink("dummyFilePath");
testRunSink.setName(originSink.getName());
return testRunSink;
}
use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink in project streamline by hortonworks.
the class TestTopologyDagCreatingVisitorTest method visitSink_connectedFromSource.
@Test
public void visitSink_connectedFromSource() throws Exception {
StreamlineSource originSource = TopologyTestHelper.createStreamlineSource("1");
StreamlineSink originSink = TopologyTestHelper.createStreamlineSink("2");
TopologyDag originTopologyDag = new TopologyDag();
originTopologyDag.add(originSource);
originTopologyDag.add(originSink);
originTopologyDag.addEdge(new Edge("e1", originSource, originSink, "default", Stream.Grouping.SHUFFLE));
TestRunSource testSource = createTestRunSource(originSource);
TestRunSink testSink = createTestRunSink(originSink);
TestTopologyDagCreatingVisitor visitor = new TestTopologyDagCreatingVisitor(originTopologyDag, Collections.singletonMap(originSource.getName(), testSource), Collections.emptyMap(), Collections.emptyMap(), Collections.singletonMap(originSink.getName(), testSink));
visitor.visit(originSource);
visitor.visit(originSink);
TopologyDag testTopologyDag = visitor.getTestTopologyDag();
List<OutputComponent> testSources = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunSource && o.getName().equals(originSource.getName()))).collect(toList());
List<InputComponent> testSinks = testTopologyDag.getInputComponents().stream().filter(o -> (o instanceof TestRunSink && o.getName().equals(originSink.getName()))).collect(toList());
assertEquals(1, testSinks.size());
TestRunSource testRunSource = (TestRunSource) testSources.get(0);
TestRunSink testRunSink = (TestRunSink) testSinks.get(0);
assertEquals(originSink.getId(), testRunSink.getId());
assertEquals(testSink.getOutputFilePath(), testRunSink.getOutputFilePath());
assertEquals(1, testTopologyDag.getEdgesFrom(testRunSource).size());
assertEquals(1, testTopologyDag.getEdgesTo(testRunSink).size());
assertTrue(testTopologyDag.getEdgesFrom(testRunSource).get(0) == testTopologyDag.getEdgesTo(testRunSink).get(0));
}
use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink in project streamline by hortonworks.
the class TestTopologyDagCreatingVisitor method visit.
@Override
public void visit(StreamlineSink sink) {
String id = sink.getId();
String sinkName = sink.getName();
if (!testRunSinksForEachSink.containsKey(sinkName)) {
throw new IllegalStateException("Not all sinks have corresponding TestRunSink instance. sink name: " + sinkName);
}
Config config = new Config(sink.getConfig());
TestRunSink testRunSink = testRunSinksForEachSink.get(sinkName);
testRunSink.setId(id);
testRunSink.setName(sinkName);
testRunSink.setConfig(config);
testRunSink.setTransformationClass(TestRunSinkBoltFluxComponent.class.getName());
testTopologyDag.add(testRunSink);
sinkToReplacedTestSinkMap.put(sinkName, testRunSink);
copyEdges(sink);
}
use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink in project streamline by hortonworks.
the class TopologyTestRunnerTest method setSucceedTopologyActionsExpectations.
private void setSucceedTopologyActionsExpectations() throws Exception {
new Expectations() {
{
topologyActions.runTest(withInstanceOf(TopologyLayout.class), withInstanceOf(TopologyTestRunHistory.class), anyString, withInstanceOf(Map.class), withInstanceOf(Map.class), withInstanceOf(Map.class), withInstanceOf(Map.class), withInstanceOf(Optional.class));
result = new Delegate<Object>() {
Object delegate(TopologyLayout topology, TopologyTestRunHistory testRunHistory, String mavenArtifacts, Map<String, TestRunSource> testRunSourcesForEachSource, Map<String, TestRunProcessor> testRunProcessorsForEachProcessor, Map<String, TestRunRulesProcessor> testRunRulesProcessorsForEachProcessor, Map<String, TestRunSink> testRunSinksForEachSink, Optional<Long> durationSecs) throws Exception {
Map<String, List<Map<String, Object>>> testOutputRecords = TopologyTestHelper.createTestOutputRecords(testRunSinksForEachSink.keySet());
testRunSinksForEachSink.entrySet().forEach(entry -> {
String sinkName = entry.getKey();
TestRunSink sink = entry.getValue();
try (FileWriter fw = new FileWriter(sink.getOutputFilePath())) {
List<Map<String, Object>> outputRecords = testOutputRecords.get(sinkName);
for (Map<String, Object> record : outputRecords) {
fw.write(objectMapper.writeValueAsString(record) + "\n");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
});
return null;
}
};
}
};
}
Aggregations