Search in sources :

Example 6 with SplitAction

use of com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction in project streamline by hortonworks.

the class SplitJoinTest method testCustomSplitJoin.

@Test
public void testCustomSplitJoin() {
    String[] outputStreams = { "stream-1", "stream-2", "stream-3" };
    final SplitAction splitAction = new SplitAction(MySplitter.class.getName());
    splitAction.setOutputStreams(Sets.newHashSet(outputStreams));
    final JoinAction joinAction = new JoinAction(MyJoiner.class.getName());
    joinAction.setOutputStreams(Collections.singleton("output-stream"));
    resetCounters();
    runSplitJoin(splitAction, joinAction);
    Assert.assertTrue(MySplitter.invocationCount == 1);
    Assert.assertTrue(MyJoiner.invocationCount == 1);
}
Also used : JoinAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.JoinAction) SplitAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction) Test(org.junit.Test)

Example 7 with SplitAction

use of com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction 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 8 with SplitAction

use of com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction in project streamline by hortonworks.

the class TopologyComponentFactory method splitProcessorProvider.

private Map.Entry<String, Provider<StreamlineProcessor>> splitProcessorProvider() {
    Provider<StreamlineProcessor> provider = new Provider<StreamlineProcessor>() {

        @Override
        public StreamlineProcessor create(TopologyComponent component) {
            Object splitConfig = component.getConfig().getAny(SplitProcessor.CONFIG_KEY_SPLIT);
            ObjectMapper objectMapper = new ObjectMapper();
            SplitAction splitAction = objectMapper.convertValue(splitConfig, SplitAction.class);
            SplitProcessor splitProcessor = new SplitProcessor();
            if (component instanceof TopologyOutputComponent) {
                splitProcessor.addOutputStreams(createOutputStreams((TopologyOutputComponent) component));
            } else {
                throw new IllegalArgumentException("Component " + component + " must be an instance of TopologyOutputComponent");
            }
            splitProcessor.setSplitAction(splitAction);
            return splitProcessor;
        }
    };
    return new SimpleImmutableEntry<>(SPLIT, provider);
}
Also used : TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) TopologyOutputComponent(com.hortonworks.streamline.streams.catalog.TopologyOutputComponent) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) SplitAction(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction) SplitProcessor(com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitProcessor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

SplitAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitAction)8 JoinAction (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.JoinAction)6 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Result (com.hortonworks.streamline.streams.Result)1 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)1 TopologyComponent (com.hortonworks.streamline.streams.catalog.TopologyComponent)1 TopologyOutputComponent (com.hortonworks.streamline.streams.catalog.TopologyOutputComponent)1 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)1 SplitProcessor (com.hortonworks.streamline.streams.layout.component.impl.splitjoin.SplitProcessor)1 ActionRuntimeContext (com.hortonworks.streamline.streams.runtime.rule.action.ActionRuntimeContext)1 RulesBolt (com.hortonworks.streamline.streams.runtime.storm.bolt.rules.RulesBolt)1 Path (java.nio.file.Path)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 HashMap (java.util.HashMap)1 Expectations (mockit.Expectations)1