Search in sources :

Example 56 with StreamlineEvent

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

the class SplitJoinTest method testStageProcessor.

@Test
public void testStageProcessor() {
    final String enrichFieldName = "foo";
    final String enrichedValue = "foo-enriched-value";
    Map<Object, Object> data = new HashMap<Object, Object>() {

        {
            put("foo-value", enrichedValue);
        }
    };
    InmemoryTransformDataProvider transformDataProvider = new InmemoryTransformDataProvider(data);
    EnrichmentTransform enrichmentTransform = new EnrichmentTransform("enricher", Collections.singletonList(enrichFieldName), transformDataProvider);
    StageAction stageAction = new StageAction(Collections.<Transform>singletonList(enrichmentTransform));
    stageAction.setOutputStreams(Collections.singleton("output-stream"));
    StageActionRuntime stageActionRuntime = new StageActionRuntime(stageAction);
    stageActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(null, stageAction));
    stageActionRuntime.initialize(Collections.<String, Object>emptyMap());
    final List<Result> results = stageActionRuntime.execute(createRootEvent());
    for (Result result : results) {
        for (StreamlineEvent event : result.events) {
            final Map enrichments = (Map) event.getAuxiliaryFieldsAndValues().get(EnrichmentTransform.ENRICHMENTS_FIELD_NAME);
            Assert.assertEquals(enrichments.get(enrichFieldName), enrichedValue);
        }
    }
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StageAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction) InmemoryTransformDataProvider(com.hortonworks.streamline.streams.layout.component.rule.action.transform.InmemoryTransformDataProvider) EnrichmentTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.EnrichmentTransform) Result(com.hortonworks.streamline.streams.Result) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 57 with StreamlineEvent

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

the class SplitJoinTest method testStageProcessorWithRules.

@Test
public void testStageProcessorWithRules() {
    final String enrichFieldName = "foo";
    final String enrichedValue = "foo-enriched-value";
    Map<Object, Object> data = new HashMap<Object, Object>() {

        {
            put("foo-value", enrichedValue);
        }
    };
    InmemoryTransformDataProvider transformDataProvider = new InmemoryTransformDataProvider(data);
    EnrichmentTransform enrichmentTransform = new EnrichmentTransform("enricher", Collections.singletonList(enrichFieldName), transformDataProvider);
    StageAction stageAction = new StageAction(Collections.<Transform>singletonList(enrichmentTransform));
    SplitJoinRule stageRule = new SplitJoinRule("stage-1", stageAction, Collections.singleton("output-stream"));
    StageActionRuntime stageActionRuntime = new StageActionRuntime(stageAction);
    stageActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(stageRule, stageAction));
    stageActionRuntime.initialize(Collections.<String, Object>emptyMap());
    final List<Result> results = stageActionRuntime.execute(createRootEvent());
    for (Result result : results) {
        for (StreamlineEvent event : result.events) {
            final Map enrichments = (Map) event.getAuxiliaryFieldsAndValues().get(EnrichmentTransform.ENRICHMENTS_FIELD_NAME);
            Assert.assertEquals(enrichments.get(enrichFieldName), enrichedValue);
        }
    }
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StageAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction) InmemoryTransformDataProvider(com.hortonworks.streamline.streams.layout.component.rule.action.transform.InmemoryTransformDataProvider) EnrichmentTransform(com.hortonworks.streamline.streams.layout.component.rule.action.transform.EnrichmentTransform) Result(com.hortonworks.streamline.streams.Result) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 58 with StreamlineEvent

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

the class SplitJoinTest method runSplitJoin.

private void runSplitJoin(SplitJoinRule splitRule, SplitJoinRule joinRule, Map<String, Object> config) {
    final SplitAction splitAction = (SplitAction) splitRule.getAction();
    SplitActionRuntime splitActionRuntime = new SplitActionRuntime(splitAction);
    splitActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(splitRule, splitAction));
    splitActionRuntime.initialize(config);
    StreamlineEvent streamlineEvent = createRootEvent();
    final List<Result> results = splitActionRuntime.execute(streamlineEvent);
    JoinAction joinAction = (JoinAction) joinRule.getAction();
    JoinActionRuntime joinActionRuntime = new JoinActionRuntime(joinAction);
    joinActionRuntime.setActionRuntimeContext(new ActionRuntimeContext(joinRule, joinAction));
    joinActionRuntime.initialize(config);
    List<Result> effectiveResult = null;
    for (Result result : results) {
        for (StreamlineEvent event : result.events) {
            List<Result> processedResult = joinActionRuntime.execute(event);
            if (processedResult != null) {
                effectiveResult = processedResult;
            }
        }
    }
    Assert.assertNotNull(effectiveResult);
}
Also used : JoinAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.JoinAction) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) SplitAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction) ActionRuntimeContext(com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext) Result(com.hortonworks.streamline.streams.Result)

Example 59 with StreamlineEvent

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

the class SubstituteTransformRuntimeTest method testSubstituteRefVars.

@Test
public void testSubstituteRefVars() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", "one");
    fieldsAndValues.put("2", "${1} plus ${1}");
    fieldsAndValues.put("3", "${1} plus ${2}");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
    TransformRuntime transformRuntime = new SubstituteTransformRuntime();
    List<StreamlineEvent> result = transformRuntime.execute(event);
    assertEquals(1, result.size());
    assertEquals(3, result.get(0).size());
    assertEquals("one", result.get(0).get("1"));
    assertEquals("one plus one", result.get(0).get("2"));
    assertEquals("one plus one plus one", result.get(0).get("3"));
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformRuntime(com.hortonworks.streamline.streams.runtime.TransformRuntime) Test(org.junit.Test)

Example 60 with StreamlineEvent

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

the class SubstituteTransformRuntimeTest method testSubstituteSimpleObj.

@Test
public void testSubstituteSimpleObj() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", 1);
    fieldsAndValues.put("2", 2);
    fieldsAndValues.put("3", "${1} plus ${2}");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
    TransformRuntime transformRuntime = new SubstituteTransformRuntime();
    List<StreamlineEvent> result = transformRuntime.execute(event);
    assertEquals(1, result.size());
    assertEquals(3, result.get(0).size());
    assertEquals(1, result.get(0).get("1"));
    assertEquals(2, result.get(0).get("2"));
    assertEquals("1 plus 2", result.get(0).get("3"));
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TransformRuntime(com.hortonworks.streamline.streams.runtime.TransformRuntime) Test(org.junit.Test)

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