Search in sources :

Example 21 with StreamlineEvent

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

the class GroovyScriptNestedExprTest method testEvaluateNestedMap.

@Test
public void testEvaluateNestedMap() throws Exception {
    groovyScript = new GroovyScript<>("x < y['b']", new GroovyScriptEngine());
    Map<String, Object> nested = new HashMap<>();
    nested.put("a", 5);
    nested.put("b", 10);
    Map<String, Object> kv = new HashMap<>();
    kv.put("x", 2);
    kv.put("y", nested);
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(kv).dataSourceId("1").build();
    Boolean result = groovyScript.evaluate(event);
    System.out.println(result);
}
Also used : GroovyScriptEngine(com.hortonworks.streamline.streams.runtime.script.engine.GroovyScriptEngine) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Test(org.junit.Test)

Example 22 with StreamlineEvent

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

the class GroovyScriptNestedExprTest method testEvaluateNestedList.

@Test
public void testEvaluateNestedList() throws Exception {
    groovyScript = new GroovyScript<>("x < y[0]", new GroovyScriptEngine());
    List<Integer> nested = new ArrayList<>();
    nested.add(5);
    nested.add(1);
    Map<String, Object> kv = new HashMap<>();
    kv.put("x", 2);
    kv.put("y", nested);
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(kv).dataSourceId("1").build();
    Boolean result = groovyScript.evaluate(event);
    System.out.println(result);
}
Also used : GroovyScriptEngine(com.hortonworks.streamline.streams.runtime.script.engine.GroovyScriptEngine) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 23 with StreamlineEvent

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

the class SplitJoinTest method runSplitJoin.

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

Example 24 with StreamlineEvent

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

the class SubstituteTransformRuntimeTest method testSubstituteNoVars.

@Test
public void testSubstituteNoVars() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", "one");
    fieldsAndValues.put("2", "two");
    fieldsAndValues.put("3", "three");
    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("two", result.get(0).get("2"));
    assertEquals("three", 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 25 with StreamlineEvent

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

the class SubstituteTransformRuntimeTest method testCyclicRef.

@Test
public void testCyclicRef() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("1", "${2} minus one");
    fieldsAndValues.put("2", "${1} plus one");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
    TransformRuntime transformRuntime = new SubstituteTransformRuntime();
    List<StreamlineEvent> result = transformRuntime.execute(event);
    System.out.println(result);
    assertEquals(1, result.size());
    assertEquals(event, result.get(0));
}
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