Search in sources :

Example 61 with StreamlineEvent

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

the class SubstituteTransformRuntimeTest method testSubstituteSpecificVars.

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

Example 62 with StreamlineEvent

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

the class FunctionsTest method getTupleNestedAndArray.

private Tuple getTupleNestedAndArray() {
    Map<String, Object> map = new HashMap<>();
    List<Person> person = Arrays.asList(new Person("a", 1), new Person("b", 2));
    Map<Integer, Integer> squares = new HashMap<>();
    squares.put(1, 1);
    squares.put(2, 4);
    squares.put(3, 9);
    map.put("person", person);
    map.put("squares", squares);
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(map).dataSourceId("dsrcid").build();
    return new TupleImpl(mockContext, new Values(event), 1, "inputstream");
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 63 with StreamlineEvent

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

the class FunctionsTest method getTuple.

private Tuple getTuple() {
    Map<String, Object> map = new HashMap<>();
    map.put("intfield", 2);
    map.put("stringfield1", "hello");
    map.put("stringfield2", "world");
    map.put("stringfield3", " space ");
    map.put("stringfield4", "aaaa");
    map.put("negativefield", -1.0);
    map.put("doublefield", 1.41);
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(map).dataSourceId("dsrcid").build();
    return new TupleImpl(mockContext, new Values(event), 1, "inputstream");
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) TupleImpl(org.apache.storm.tuple.TupleImpl)

Example 64 with StreamlineEvent

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

the class EventCorrelatingOutputCollectorTest method emitWithAnchor.

@Test
public void emitWithAnchor() throws Exception {
    setupExpectationsForTuple();
    setupExpectationsForTopologyContextEmit();
    setupExpectationsForEventCorrelationInjector();
    EventCorrelatingOutputCollector sut = new EventCorrelatingOutputCollector(mockedTopologyContext, mockedOutputCollector);
    Deencapsulation.setField(sut, "eventCorrelationInjector", mockStormEventCorrelationInjector);
    StreamlineEvent parentEvent = eventCorrelationInjector.injectCorrelationInformation(PARENT_STREAMLINE_EVENT, Collections.emptyList(), TEST_COMPONENT_NAME_FOR_STORM);
    Tuple anchor = new TupleImpl(mockedTopologyContext, new Values(parentEvent), TASK_0, Utils.DEFAULT_STREAM_ID);
    String testStreamId = "testStreamId";
    List<Integer> expectedTasks = Lists.newArrayList(TASK_1, TASK_2);
    final List<Tuple> anchors = Collections.singletonList(anchor);
    final Values tuple = new Values(INPUT_STREAMLINE_EVENT);
    // String streamId, Tuple anchor, List<Object> anchor
    new Expectations() {

        {
            mockedOutputCollector.emit(testStreamId, anchor, withAny(tuple));
            result = expectedTasks;
        }
    };
    List<Integer> tasks = sut.emit(testStreamId, anchor, tuple);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emit(testStreamId, anchor, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(1, capturedParents.size());
            assertEquals(anchor, capturedParents.get(0));
        }
    };
    // Collection<Tuple> anchors, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emit(anchors, withAny(tuple));
            result = expectedTasks;
        }
    };
    tasks = sut.emit(anchors, tuple);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emit(anchors, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(1, capturedParents.size());
            assertEquals(anchor, capturedParents.get(0));
        }
    };
    // Tuple anchor, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emit(anchor, withAny(tuple));
            result = expectedTasks;
        }
    };
    tasks = sut.emit(anchor, tuple);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emit(anchor, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(1, capturedParents.size());
            assertEquals(anchor, capturedParents.get(0));
        }
    };
    // String streamId, Collection<Tuple> anchors, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emit(testStreamId, anchors, withAny(tuple));
            result = expectedTasks;
        }
    };
    tasks = sut.emit(testStreamId, anchors, tuple);
    assertEquals(expectedTasks, tasks);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emit(testStreamId, anchors, capturedValues = withCapture());
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
            List<Tuple> capturedParents;
            mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
            assertEquals(1, capturedParents.size());
            assertEquals(anchor, capturedParents.get(0));
        }
    };
}
Also used : Expectations(mockit.Expectations) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Values(org.apache.storm.tuple.Values) Verifications(mockit.Verifications) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 65 with StreamlineEvent

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

the class StreamlineEventImplTest method testGetId.

@Test
public void testGetId() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("a", "aval");
    map.put("b", "bval");
    StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(map).build();
    assertNotNull(UUID.fromString(event.getId()));
}
Also used : HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) 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