Search in sources :

Example 1 with TestRunRulesProcessor

use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor in project streamline by hortonworks.

the class TestTopologyDagCreatingVisitor method visit.

@Override
public void visit(RulesProcessor rulesProcessor) {
    String id = rulesProcessor.getId();
    String processorName = rulesProcessor.getName();
    if (!testRunRulesProcessorsForEachProcessor.containsKey(processorName)) {
        throw new IllegalStateException("Not all processors have corresponding TestRunRulesProcessor instance. processor name: " + processorName);
    }
    Config config = new Config(rulesProcessor.getConfig());
    TestRunRulesProcessor testRunRulesProcessor = testRunRulesProcessorsForEachProcessor.get(processorName);
    testRunRulesProcessor.setId(id);
    testRunRulesProcessor.setName(processorName);
    testRunRulesProcessor.setConfig(config);
    testRunRulesProcessor.setTransformationClass(TestRunRulesProcessorBoltFluxComponent.class.getName());
    testTopologyDag.add(testRunRulesProcessor);
    processorToReplacedTestProcessorMap.put(processorName, testRunRulesProcessor);
    copyEdges(rulesProcessor);
}
Also used : TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Config(com.hortonworks.streamline.common.Config) TestRunRulesProcessorBoltFluxComponent(com.hortonworks.streamline.streams.layout.storm.TestRunRulesProcessorBoltFluxComponent)

Example 2 with TestRunRulesProcessor

use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor in project streamline by hortonworks.

the class TestTopologyDagCreatingVisitorTest method createTestRunRulesProcessor.

private TestRunRulesProcessor createTestRunRulesProcessor(RulesProcessor originProcessor) {
    TestRunRulesProcessor testRunRulesProcessor = new TestRunRulesProcessor(originProcessor, "");
    testRunRulesProcessor.setName(originProcessor.getName());
    return testRunRulesProcessor;
}
Also used : TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor)

Example 3 with TestRunRulesProcessor

use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor in project streamline by hortonworks.

the class TestTopologyDagCreatingVisitorTest method visitRulesProcessor_connectedFromSource.

@Test
public void visitRulesProcessor_connectedFromSource() throws Exception {
    StreamlineSource originSource = TopologyTestHelper.createStreamlineSource("1");
    RulesProcessor rulesProcessor = TopologyTestHelper.createRulesProcessor("2");
    TopologyDag originTopologyDag = new TopologyDag();
    originTopologyDag.add(originSource);
    originTopologyDag.add(rulesProcessor);
    originTopologyDag.addEdge(new Edge("e1", originSource, rulesProcessor, "default", Stream.Grouping.SHUFFLE));
    TestRunSource testSource = createTestRunSource(originSource);
    TestRunRulesProcessor testRulesProcessor = createTestRunRulesProcessor(rulesProcessor);
    TestTopologyDagCreatingVisitor visitor = new TestTopologyDagCreatingVisitor(originTopologyDag, Collections.singletonMap(originSource.getName(), testSource), Collections.emptyMap(), Collections.singletonMap(rulesProcessor.getName(), testRulesProcessor), Collections.emptyMap());
    visitor.visit(originSource);
    visitor.visit(rulesProcessor);
    TopologyDag testTopologyDag = visitor.getTestTopologyDag();
    List<OutputComponent> testRulesProcessors = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunRulesProcessor && o.getName().equals(rulesProcessor.getName()))).collect(toList());
    List<OutputComponent> testSources = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunSource && o.getName().equals(originSource.getName()))).collect(toList());
    TestRunRulesProcessor testRunRulesProcessor = (TestRunRulesProcessor) testRulesProcessors.get(0);
    TestRunSource testRunSource = (TestRunSource) testSources.get(0);
    assertEquals(1, testTopologyDag.getEdgesFrom(testRunSource).size());
    assertEquals(1, testTopologyDag.getEdgesTo(testRunRulesProcessor).size());
    assertTrue(testTopologyDag.getEdgesFrom(testRunSource).get(0) == testTopologyDag.getEdgesTo(testRunRulesProcessor).get(0));
}
Also used : OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HashMap(java.util.HashMap) InputComponent(com.hortonworks.streamline.streams.layout.component.InputComponent) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Assert.fail(org.junit.Assert.fail) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) Test(org.junit.Test)

Example 4 with TestRunRulesProcessor

use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor in project streamline by hortonworks.

the class TestTopologyDagCreatingVisitorTest method visitRulesProcessor_connectedFromProcessor.

@Test
public void visitRulesProcessor_connectedFromProcessor() throws Exception {
    StreamlineProcessor originProcessor = TopologyTestHelper.createStreamlineProcessor("1");
    RulesProcessor rulesProcessor = TopologyTestHelper.createRulesProcessor("2");
    TopologyDag originTopologyDag = new TopologyDag();
    originTopologyDag.add(originProcessor);
    originTopologyDag.add(rulesProcessor);
    originTopologyDag.addEdge(new Edge("e1", originProcessor, rulesProcessor, "default", Stream.Grouping.SHUFFLE));
    TestRunProcessor testProcessor = createTestRunProcessor(originProcessor);
    TestRunRulesProcessor testRulesProcessor = createTestRunRulesProcessor(rulesProcessor);
    TestTopologyDagCreatingVisitor visitor = new TestTopologyDagCreatingVisitor(originTopologyDag, Collections.emptyMap(), Collections.singletonMap(originProcessor.getName(), testProcessor), Collections.singletonMap(rulesProcessor.getName(), testRulesProcessor), Collections.emptyMap());
    visitor.visit(originProcessor);
    visitor.visit(rulesProcessor);
    TopologyDag testTopologyDag = visitor.getTestTopologyDag();
    List<OutputComponent> testProcessors = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunProcessor)).collect(toList());
    List<OutputComponent> testRulesProcessors = testTopologyDag.getOutputComponents().stream().filter(o -> (o instanceof TestRunRulesProcessor)).collect(toList());
    Optional<OutputComponent> testRunProcessorOptional = testProcessors.stream().filter(o -> o.getName().equals(originProcessor.getName())).findAny();
    Optional<OutputComponent> testRunRuleProcessorOptional = testRulesProcessors.stream().filter(o -> o.getName().equals(rulesProcessor.getName())).findAny();
    assertTrue(testRunProcessorOptional.isPresent());
    assertTrue(testRunRuleProcessorOptional.isPresent());
    TestRunProcessor testRunProcessor = (TestRunProcessor) testRunProcessorOptional.get();
    TestRunRulesProcessor testRunRuleProcessor = (TestRunRulesProcessor) testRunRuleProcessorOptional.get();
    assertEquals(1, testTopologyDag.getEdgesFrom(testRunProcessor).size());
    assertEquals(1, testTopologyDag.getEdgesTo(testRunRuleProcessor).size());
    assertTrue(testTopologyDag.getEdgesFrom(testRunProcessor).get(0) == testTopologyDag.getEdgesTo(testRunRuleProcessor).get(0));
}
Also used : OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) HashMap(java.util.HashMap) InputComponent(com.hortonworks.streamline.streams.layout.component.InputComponent) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Assert.fail(org.junit.Assert.fail) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) OutputComponent(com.hortonworks.streamline.streams.layout.component.OutputComponent) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) Test(org.junit.Test)

Example 5 with TestRunRulesProcessor

use of com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor 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;
                }
            };
        }
    };
}
Also used : Expectations(mockit.Expectations) Topology(com.hortonworks.streamline.streams.catalog.Topology) BeforeClass(org.junit.BeforeClass) Expectations(mockit.Expectations) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) VerificationsInOrder(mockit.VerificationsInOrder) Collectors.toMap(java.util.stream.Collectors.toMap) Files(com.google.common.io.Files) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) JMockit(mockit.integration.junit4.JMockit) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Before(org.junit.Before) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Assert.assertTrue(org.junit.Assert.assertTrue) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Delegate(mockit.Delegate) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) File(java.io.File) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) Assert.assertFalse(org.junit.Assert.assertFalse) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) Injectable(mockit.Injectable) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Optional(java.util.Optional) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) FileWriter(java.io.FileWriter) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) IOException(java.io.IOException) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) List(java.util.List) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Aggregations

TestRunRulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor)6 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)4 StreamlineSink (com.hortonworks.streamline.streams.layout.component.StreamlineSink)4 StreamlineSource (com.hortonworks.streamline.streams.layout.component.StreamlineSource)4 TestRunProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor)4 TestRunSink (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink)4 TestRunSource (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 TopologyTestHelper (com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper)3 Edge (com.hortonworks.streamline.streams.layout.component.Edge)3 Stream (com.hortonworks.streamline.streams.layout.component.Stream)3 TopologyDag (com.hortonworks.streamline.streams.layout.component.TopologyDag)3 RulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)3 Collections (java.util.Collections)3 Collectors.toList (java.util.stream.Collectors.toList)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertTrue (org.junit.Assert.assertTrue)3