Search in sources :

Example 31 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class RulesBoltConditionTest method testSimpleRuleStringLiteral.

@Test
public void testSimpleRuleStringLiteral() throws Exception {
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(ImmutableMap.<String, Object>of("foo", "Normal", "bar", "abc", "baz", 200)).dataSourceId("dsrcid").build();
    Tuple tuple = new TupleImpl(mockContext, new Values(event), 1, "inputstream");
    doTest(readFile("/simple-rule-string-literal.json"), tuple);
    new Verifications() {

        {
            String streamId;
            Tuple anchor;
            List<List<Object>> tuples = new ArrayList<>();
            mockCollector.emit(streamId = withCapture(), anchor = withCapture(), withCapture(tuples));
            times = 0;
        }
    };
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Verifications(mockit.Verifications) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 32 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class StormEventCorrelationInjectorTest method tupleArgsTestWithTwoParentsWhichOneIsRootEventAndAnotherOneIsNonRootEvent.

@Test
public void tupleArgsTestWithTwoParentsWhichOneIsRootEventAndAnotherOneIsNonRootEvent() throws Exception {
    int parent1TaskId = 1;
    String parent1ComponentName = "1-parentComponent";
    int parent2TaskId = 2;
    String parent2ComponentName = "2-parentComponent2";
    new Expectations() {

        {
            mockedTopologyContext.getComponentId(parent1TaskId);
            result = parent1ComponentName;
            mockedTopologyContext.getComponentId(parent2TaskId);
            result = parent2ComponentName;
            mockedTopologyContext.getComponentOutputFields(parent1ComponentName, INPUT_STREAMLINE_EVENT.getSourceStream());
            result = new Fields(StreamlineEvent.STREAMLINE_EVENT);
            mockedTopologyContext.getComponentOutputFields(parent2ComponentName, INPUT_STREAMLINE_EVENT.getSourceStream());
            result = new Fields(StreamlineEvent.STREAMLINE_EVENT);
        }
    };
    StreamlineEvent parentEvent1 = copyEventWithNewID();
    parentEvent1 = eventCorrelationInjector.injectCorrelationInformation(parentEvent1, Collections.emptyList(), TEST_COMPONENT_NAME);
    Tuple parentTuple1 = new TupleImpl(mockedTopologyContext, new Values(parentEvent1), parent1TaskId, INPUT_STREAMLINE_EVENT.getSourceStream());
    StreamlineEvent parentOfParentEvent2 = copyEventWithNewID();
    parentOfParentEvent2 = eventCorrelationInjector.injectCorrelationInformation(parentOfParentEvent2, Collections.emptyList(), TEST_COMPONENT_NAME);
    StreamlineEvent parentEvent2 = copyEventWithNewID();
    parentEvent2 = eventCorrelationInjector.injectCorrelationInformation(parentEvent2, Collections.singletonList(parentOfParentEvent2), TEST_COMPONENT_NAME);
    Tuple parentTuple2 = new TupleImpl(mockedTopologyContext, new Values(parentEvent2), parent2TaskId, INPUT_STREAMLINE_EVENT.getSourceStream());
    StreamlineEvent injectedEvent = sut.injectCorrelationInformation(new Values(INPUT_STREAMLINE_EVENT), Lists.newArrayList(parentTuple1, parentTuple2), TEST_COMPONENT_NAME);
    StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
    // added headers
    assertEquals(Sets.newHashSet(parentEvent1.getId(), parentOfParentEvent2.getId()), EventCorrelationInjector.getRootIds(injectedEvent));
    assertEquals(Sets.newHashSet(parentEvent1.getId(), parentEvent2.getId()), EventCorrelationInjector.getParentIds(injectedEvent));
    assertEquals(StormTopologyUtil.extractStreamlineComponentName(TEST_COMPONENT_NAME), EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
Also used : Expectations(mockit.Expectations) Fields(org.apache.storm.tuple.Fields) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 33 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class StormEventCorrelationInjectorTest method tupleArgsTestNoParent.

@Test
public void tupleArgsTestNoParent() throws Exception {
    StreamlineEvent injectedEvent = sut.injectCorrelationInformation(new Values(INPUT_STREAMLINE_EVENT), Collections.emptyList(), TEST_COMPONENT_NAME);
    StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
    // added headers
    assertEquals(Collections.emptySet(), EventCorrelationInjector.getRootIds(injectedEvent));
    assertEquals(Collections.emptySet(), EventCorrelationInjector.getParentIds(injectedEvent));
    assertEquals(StormTopologyUtil.extractStreamlineComponentName(TEST_COMPONENT_NAME), EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) Test(org.junit.Test)

Example 34 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class HdfsTextOutputFormat method format.

@Override
public byte[] format(Tuple tuple) {
    if (fields == null || fields.size() == 0) {
        throw new IllegalArgumentException("Output field names not specified. Set them using withFields().");
    }
    StreamlineEvent event = ((StreamlineEvent) tuple.getValueByField(StreamlineEvent.STREAMLINE_EVENT));
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < fields.size(); i++) {
        Object value = event.get(fields.get(i));
        if (value != null) {
            sb.append(value);
        }
        if (i != fields.size() - 1) {
            sb.append(this.fieldDelimiter);
        }
    }
    sb.append(this.recordDelimiter);
    return sb.toString().getBytes();
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent)

Example 35 with StreamlineEvent

use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.

the class OutputCollectorStreamlineEventLogger method logEvent.

private void logEvent(String streamId, List<Integer> taskIds, List<Object> tuple) {
    long now = System.currentTimeMillis();
    StreamlineEvent streamlineEvent = (StreamlineEvent) tuple.get(0);
    // will be more efficient if we split this to two streams, but it shouldn't be a big deal anyway
    Set<String> targetComponentIds = taskIds.stream().map(topologyContext::getComponentId).map(StormTopologyUtil::extractStreamlineComponentName).collect(Collectors.toSet());
    eventLogger.writeEvent(now, componentName, streamId, targetComponentIds, streamlineEvent);
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent)

Aggregations

StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)97 Test (org.junit.Test)47 HashMap (java.util.HashMap)41 Values (org.apache.storm.tuple.Values)25 ArrayList (java.util.ArrayList)19 Tuple (org.apache.storm.tuple.Tuple)14 Result (com.hortonworks.streamline.streams.Result)13 Expectations (mockit.Expectations)9 TupleImpl (org.apache.storm.tuple.TupleImpl)9 Map (java.util.Map)8 Verifications (mockit.Verifications)8 TransformRuntime (com.hortonworks.streamline.streams.runtime.TransformRuntime)7 ProcessingException (com.hortonworks.streamline.streams.exception.ProcessingException)6 StormSqlExpression (com.hortonworks.streamline.streams.runtime.rule.condition.expression.StormSqlExpression)6 List (java.util.List)5 IdPreservedStreamlineEvent (com.hortonworks.streamline.streams.common.IdPreservedStreamlineEvent)4 StreamlineEventImpl (com.hortonworks.streamline.streams.common.StreamlineEventImpl)4 Fields (org.apache.storm.tuple.Fields)4 EventCorrelationInjector (com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector)3 MergeTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.MergeTransform)3