Search in sources :

Example 21 with Stream

use of com.hortonworks.streamline.streams.layout.component.Stream in project streamline by hortonworks.

the class TopologyTestHelper method createStreamlineSource.

public static StreamlineSource createStreamlineSource(String id) {
    Stream stream = createDefaultStream();
    StreamlineSource source = new StreamlineSource(Sets.newHashSet(stream));
    source.setId(id);
    source.setName("testSource_" + id);
    source.setConfig(new Config());
    source.setTransformationClass("dummyTransformation");
    return source;
}
Also used : Config(com.hortonworks.streamline.common.Config) Stream(com.hortonworks.streamline.streams.layout.component.Stream) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource)

Example 22 with Stream

use of com.hortonworks.streamline.streams.layout.component.Stream in project streamline by hortonworks.

the class RuleParserTest method testParseUDF1.

@Test
public void testParseUDF1() throws Exception {
    final UDF myFunc = new UDF();
    myFunc.setClassName("foo.class.name");
    myFunc.setDescription("My function");
    myFunc.setId(Math.abs(new Random().nextLong()));
    myFunc.setJarStoragePath("/udfstorage/");
    myFunc.setName("myFunc");
    myFunc.setType(Udf.Type.FUNCTION);
    new Expectations() {

        {
            mockCatalogService.listStreamInfos(withAny(new ArrayList<QueryParam>()));
            result = mockTopologyStream;
            mockCatalogService.listUDFs();
            result = Collections.singleton(myFunc);
            mockTopologyStream.getStreamId();
            result = "teststream";
            mockTopologyStream.getFields();
            result = Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG));
        }
    };
    TopologyRule topologyRule = new TopologyRule();
    topologyRule.setId(1L);
    topologyRule.setName("Test");
    topologyRule.setDescription("test rule");
    topologyRule.setTopologyId(1L);
    topologyRule.setVersionId(1L);
    topologyRule.setSql("select myFunc(temperature) from teststream");
    RuleParser ruleParser = new RuleParser(mockCatalogService, topologyRule.getSql(), topologyRule.getTopologyId(), topologyRule.getVersionId());
    ruleParser.parse();
    LOG.info("Projection: [{}]", ruleParser.getProjection());
    assertNotNull(ruleParser.getProjection());
    assertEquals(1, ruleParser.getStreams().size());
    assertEquals(new Stream("teststream", Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG))), ruleParser.getStreams().get(0));
    assertNull(ruleParser.getGroupBy());
    assertNull(ruleParser.getHaving());
}
Also used : Expectations(mockit.Expectations) Random(java.util.Random) UDF(com.hortonworks.streamline.streams.catalog.UDF) ArrayList(java.util.ArrayList) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) Test(org.junit.Test)

Example 23 with Stream

use of com.hortonworks.streamline.streams.layout.component.Stream in project streamline by hortonworks.

the class RuleParserTest method testParseAsExpressionWithCase.

@Test
public void testParseAsExpressionWithCase() throws Exception {
    new Expectations() {

        {
            mockCatalogService.listStreamInfos(withAny(new ArrayList<QueryParam>()));
            result = mockTopologyStream;
            mockTopologyStream.getStreamId();
            result = "teststream";
            mockTopologyStream.getFields();
            result = Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG));
        }
    };
    TopologyRule topologyRule = new TopologyRule();
    topologyRule.setId(1L);
    topologyRule.setName("Test");
    topologyRule.setDescription("test rule");
    topologyRule.setTopologyId(1L);
    topologyRule.setVersionId(1L);
    topologyRule.setSql("select temperature as \"temp_TEST\" from teststream where humidity > 80");
    RuleParser ruleParser = new RuleParser(mockCatalogService, topologyRule.getSql(), topologyRule.getTopologyId(), topologyRule.getVersionId());
    ruleParser.parse();
    assertEquals(new Condition(new BinaryExpression(Operator.GREATER_THAN, new FieldExpression(Schema.Field.of("humidity", Schema.Type.LONG)), new Literal("80"))), ruleParser.getCondition());
    assertEquals(new Projection(Arrays.asList(new AsExpression(new FieldExpression(Schema.Field.of("temperature", Schema.Type.LONG)), "temp_TEST"))), ruleParser.getProjection());
    assertEquals(1, ruleParser.getStreams().size());
    assertEquals(new Stream("teststream", Arrays.asList(Schema.Field.of("temperature", Schema.Type.LONG), Schema.Field.of("humidity", Schema.Type.LONG))), ruleParser.getStreams().get(0));
    assertNull(ruleParser.getGroupBy());
    assertNull(ruleParser.getHaving());
}
Also used : Expectations(mockit.Expectations) Condition(com.hortonworks.streamline.streams.layout.component.rule.expression.Condition) BinaryExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression) Literal(com.hortonworks.streamline.streams.layout.component.rule.expression.Literal) ArrayList(java.util.ArrayList) Projection(com.hortonworks.streamline.streams.layout.component.rule.expression.Projection) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) AsExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.AsExpression) FieldExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FieldExpression) Test(org.junit.Test)

Example 24 with Stream

use of com.hortonworks.streamline.streams.layout.component.Stream in project streamline by hortonworks.

the class RuleParser method parseStreams.

private List<Stream> parseStreams(SqlSelect sqlSelect) throws Exception {
    List<Stream> streams = new ArrayList<>();
    SqlNode sqlFrom = sqlSelect.getFrom();
    LOG.debug("from = {}", sqlFrom);
    if (sqlFrom instanceof SqlJoin) {
        throw new IllegalArgumentException("Sql join is not yet supported");
    } else if (sqlFrom instanceof SqlIdentifier) {
        streams.add(getStream(((SqlIdentifier) sqlFrom).getSimple()));
    }
    LOG.debug("Streams {}", streams);
    return streams;
}
Also used : SqlJoin(org.apache.calcite.sql.SqlJoin) ArrayList(java.util.ArrayList) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) Stream(com.hortonworks.streamline.streams.layout.component.Stream) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 25 with Stream

use of com.hortonworks.streamline.streams.layout.component.Stream in project streamline by hortonworks.

the class TopologyTestRunnerTest method runTest_topologyActionsTestRunFails.

@Test
public void runTest_topologyActionsTestRunFails() throws Exception {
    Topology topology = createSimpleDAGInjectedTestTopology();
    Long topologyId = topology.getId();
    Long testCaseId = 1L;
    TopologyTestRunCase testCase = new TopologyTestRunCase();
    testCase.setId(testCaseId);
    testCase.setTopologyId(topology.getId());
    testCase.setName("testcase1");
    testCase.setTimestamp(System.currentTimeMillis());
    setTopologyCurrentVersionExpectation(topology);
    setTopologyTestRunCaseExpectations(topology, testCase);
    setTopologyTestRunCaseSinkNotFoundExpectations(topology, testCase);
    setTopologyTestRunHistoryExpectations();
    setTopologyActionsThrowingExceptionExpectations();
    long sourceCount = topology.getTopologyDag().getOutputComponents().stream().filter(c -> c instanceof StreamlineSource).count();
    long sinkCount = topology.getTopologyDag().getInputComponents().stream().filter(c -> c instanceof StreamlineSink).count();
    TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
    assertNotNull(resultHistory);
    waitForTopologyTestRunToFinish(resultHistory);
    new VerificationsInOrder() {

        {
            catalogService.getTopologyTestRunCaseSourceBySourceId(testCaseId, anyLong);
            times = (int) sourceCount;
            catalogService.getTopologyTestRunCaseSinkBySinkId(testCaseId, anyLong);
            times = (int) sinkCount;
            TopologyTestRunHistory runHistory;
            // some fields are already modified after calling the method, so don't need to capture it
            catalogService.addTopologyTestRunHistory(withInstanceOf(TopologyTestRunHistory.class));
            times = 1;
            catalogService.addOrUpdateTopologyTestRunHistory(anyLong, runHistory = withCapture());
            times = 1;
            assertEquals(topology.getId(), runHistory.getTopologyId());
            assertEquals(topology.getVersionId(), runHistory.getVersionId());
            assertTrue(runHistory.getFinished());
            assertFalse(runHistory.getSuccess());
            assertNotNull(runHistory.getStartTime());
            assertNotNull(runHistory.getFinishTime());
            assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
            assertTrue(isEmptyJson(runHistory.getExpectedOutputRecords()));
            assertNull(runHistory.getActualOutputRecords());
            assertFalse(runHistory.getMatched());
        }
    };
}
Also used : 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) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Topology(com.hortonworks.streamline.streams.catalog.Topology) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Aggregations

Stream (com.hortonworks.streamline.streams.layout.component.Stream)27 HashMap (java.util.HashMap)16 List (java.util.List)14 Map (java.util.Map)14 Test (org.junit.Test)13 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)12 Collections (java.util.Collections)12 Edge (com.hortonworks.streamline.streams.layout.component.Edge)11 StreamlineSource (com.hortonworks.streamline.streams.layout.component.StreamlineSource)11 TopologyDag (com.hortonworks.streamline.streams.layout.component.TopologyDag)11 StreamlineSink (com.hortonworks.streamline.streams.layout.component.StreamlineSink)10 RulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)10 TestRunSource (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource)10 Optional (java.util.Optional)10 TopologyTestHelper (com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper)9 TopologyStream (com.hortonworks.streamline.streams.catalog.TopologyStream)9 InputComponent (com.hortonworks.streamline.streams.layout.component.InputComponent)8 OutputComponent (com.hortonworks.streamline.streams.layout.component.OutputComponent)8 ArrayList (java.util.ArrayList)8 TestRunProcessor (com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor)7