Search in sources :

Example 1 with InmemoryTransformDataProvider

use of com.hortonworks.streamline.streams.layout.component.rule.action.transform.InmemoryTransformDataProvider 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 2 with InmemoryTransformDataProvider

use of com.hortonworks.streamline.streams.layout.component.rule.action.transform.InmemoryTransformDataProvider 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)

Aggregations

Result (com.hortonworks.streamline.streams.Result)2 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)2 StageAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.StageAction)2 EnrichmentTransform (com.hortonworks.streamline.streams.layout.component.rule.action.transform.EnrichmentTransform)2 InmemoryTransformDataProvider (com.hortonworks.streamline.streams.layout.component.rule.action.transform.InmemoryTransformDataProvider)2 ActionRuntimeContext (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2