Search in sources :

Example 1 with StreamlineEvent

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

the class NotificationBoltTest method testWithConsoleNotifier.

@Test
public void testWithConsoleNotifier() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("foo", "100");
    fieldsAndValues.put("bar", "200");
    final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("srcid").build();
    NotificationBolt consoleNotificationBolt = new NotificationBolt(new NotificationSink() {

        @Override
        public String getNotifierName() {
            return "console_notifier";
        }

        @Override
        public String getNotifierJarFileName() {
            return "console_notifier.jar";
        }

        @Override
        public String getNotifierClassName() {
            return "ConsoleNotifier";
        }

        @Override
        public Map<String, Object> getNotifierProperties() {
            return new HashMap<>();
        }

        @Override
        public Map<String, Object> getNotifierFieldValues() {
            return new HashMap<>();
        }
    });
    consoleNotificationBolt.withNotificationStoreClass("com.hortonworks.streamline.streams.notification.store.hbase.HBaseNotificationStore");
    final ConsoleNotifier consoleNotifier = new ConsoleNotifier();
    final Notification notification = new StreamlineEventAdapter(event);
    new MockUp<NotificationQueueHandler>() {

        @Mock
        public void enqueue(Notifier notifier, Notification notification1) {
            // System.out.println("Mocked enqueue");
            notifier.notify(notification);
        }
    };
    new Expectations() {

        {
            mockProxyUtil.loadClassFromJar("/tmp/console_notifier.jar", "ConsoleNotifier");
            result = consoleNotifier;
            tuple.getValueByField(anyString);
            result = event;
        }
    };
    Map<String, String> stormConf = new HashMap<>();
    stormConf.put("catalog.root.url", "http://localhost:8080/api/v1/catalog");
    stormConf.put("local.notifier.jar.path", "/tmp");
    consoleNotificationBolt.prepare(stormConf, null, collector);
    consoleNotificationBolt.execute(tuple);
    new Verifications() {

        {
            collector.ack(tuple);
            times = 1;
            hBaseNotificationStore.store(notification);
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) MockUp(mockit.MockUp) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) NotificationSink(com.hortonworks.streamline.streams.layout.component.impl.NotificationSink) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) StreamlineEventAdapter(com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter) HashMap(java.util.HashMap) Map(java.util.Map) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Test(org.junit.Test)

Example 2 with StreamlineEvent

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

the class NotificationBoltTest method testFail.

@Test
public void testFail() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("foobar", "100");
    final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("srcid").build();
    final Notification notification = new StreamlineEventAdapter(event);
    new MockUp<NotificationQueueHandler>() {

        @Mock
        public void enqueue(Notifier notifier, Notification notification1) {
            notifier.notify(notification);
        }

        @Mock
        public void resubmit(String notificationId) {
            notifier.notify(notification);
        }
    };
    new Expectations() {

        {
            mockProxyUtil.loadClassFromJar(anyString, "TestClass");
            result = notifier;
            tuple.getValueByField(anyString);
            result = event;
        }
    };
    Map<String, String> stormConf = new HashMap<>();
    stormConf.put("catalog.root.url", "http://localhost:8080/api/v1/catalog");
    stormConf.put("local.notifier.jar.path", "/tmp");
    bolt.prepare(stormConf, null, collector);
    bolt.execute(tuple);
    new Verifications() {

        {
            hBaseNotificationStore.store(notification);
            times = 1;
            hBaseNotificationStore.updateNotificationStatus(notification.getId(), Notification.Status.FAILED);
            times = 1;
            collector.ack(tuple);
            times = 0;
            collector.fail(tuple);
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StreamlineEventAdapter(com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter) MockUp(mockit.MockUp) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Test(org.junit.Test)

Example 3 with StreamlineEvent

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

the class TestWindowedQueryBolt method makeStreamLineEventStream.

private static ArrayList<Tuple> makeStreamLineEventStream(String streamName, String[] fieldNames, Object[][] records) {
    MockTopologyContext mockContext = new MockTopologyContext(new String[] { StreamlineEvent.STREAMLINE_EVENT });
    ArrayList<Tuple> result = new ArrayList<>(records.length);
    // convert each record into a HashMap using fieldNames as keys
    for (Object[] record : records) {
        HashMap<String, Object> recordMap = new HashMap<>(fieldNames.length);
        for (int i = 0; i < fieldNames.length; i++) {
            recordMap.put(fieldNames[i], record[i]);
        }
        StreamlineEvent streamLineEvent = StreamlineEventImpl.builder().fieldsAndValues(recordMap).dataSourceId("multiple sources").build();
        ArrayList<Object> tupleValues = new ArrayList<>(1);
        tupleValues.add(streamLineEvent);
        TupleImpl tuple = new TupleImpl(mockContext, tupleValues, 0, streamName);
        result.add(tuple);
    }
    return result;
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) TupleImpl(org.apache.storm.tuple.TupleImpl) Tuple(org.apache.storm.tuple.Tuple)

Example 4 with StreamlineEvent

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

the class EventCorrelatingOutputCollectorTest method emitDirectWithAnchor.

@Test
public void emitDirectWithAnchor() throws Exception {
    setupExpectationsForTuple();
    setupExpectationsForTopologyContextEmit();
    setupExpectationsForEventCorrelationInjector();
    EventCorrelatingOutputCollector sut = getSystemUnderTest();
    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);
    int testTaskId = TASK_1;
    String testStreamId = "testStreamId";
    final List<Tuple> anchors = Collections.singletonList(anchor);
    final Values tuple = new Values(INPUT_STREAMLINE_EVENT);
    // int taskId, String streamId, Tuple anchor, List<Object> anchor
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(testTaskId, testStreamId, anchor, withAny(tuple));
        }
    };
    sut.emitDirect(testTaskId, testStreamId, anchor, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(testTaskId, 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));
        }
    };
    // int taskId, Collection<Tuple> anchors, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(testTaskId, anchors, withAny(tuple));
        }
    };
    sut.emitDirect(testTaskId, anchors, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(testTaskId, 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));
        }
    };
    // int taskId, Tuple anchor, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(testTaskId, anchor, withAny(tuple));
        }
    };
    sut.emitDirect(testTaskId, anchor, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(testTaskId, 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));
        }
    };
    // int taskId, String streamId, Collection<Tuple> anchors, List<Object> tuple
    new Expectations() {

        {
            mockedOutputCollector.emitDirect(testTaskId, testStreamId, anchors, withAny(tuple));
        }
    };
    sut.emitDirect(testTaskId, testStreamId, anchors, tuple);
    new Verifications() {

        {
            List<Object> capturedValues;
            mockedOutputCollector.emitDirect(testTaskId, 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 5 with StreamlineEvent

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

the class StreamlineEventLoggerTest method buildStreamlineEventLogMessage.

@Test
public void buildStreamlineEventLogMessage() {
    long timestamp = 1513300663123L;
    String timestampStr = dateFormat.format(timestamp);
    String stormComponentName = "1-Component";
    String streamlineComponent = "Component";
    int taskId = 2;
    Object messageId = "dummy";
    // test root event
    StreamlineEvent event = buildTestEvent();
    List<Object> values = Collections.singletonList(event);
    String expectMessage = String.format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", timestampStr, StreamlineEventLogger.DELIMITER, StreamlineEventLogger.MARKER_FOR_STREAMLINE_EVENT, StreamlineEventLogger.DELIMITER, streamlineComponent, StreamlineEventLogger.DELIMITER, event.getId(), StreamlineEventLogger.DELIMITER, "[]", StreamlineEventLogger.DELIMITER, "[]", StreamlineEventLogger.DELIMITER, ImmutableMap.copyOf(event), StreamlineEventLogger.DELIMITER, event.getHeader(), StreamlineEventLogger.DELIMITER, event.getAuxiliaryFieldsAndValues());
    IEventLogger.EventInfo eventInfo = new IEventLogger.EventInfo(timestamp, stormComponentName, taskId, messageId, values);
    String actualMessage = sut.buildLogMessage(eventInfo);
    Assert.assertEquals(expectMessage, actualMessage);
    // test event with event correlation information
    EventCorrelationInjector eventCorrelationInjector = new EventCorrelationInjector();
    StreamlineEvent event2 = StreamlineEventImpl.builder().from(event).build();
    StreamlineEvent event3 = StreamlineEventImpl.builder().from(event).build();
    event2 = eventCorrelationInjector.injectCorrelationInformation(event2, Collections.singletonList(event3), streamlineComponent);
    event = eventCorrelationInjector.injectCorrelationInformation(event, Collections.singletonList(event2), streamlineComponent);
    values = Collections.singletonList(event);
    expectMessage = String.format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", timestampStr, StreamlineEventLogger.DELIMITER, StreamlineEventLogger.MARKER_FOR_STREAMLINE_EVENT, StreamlineEventLogger.DELIMITER, streamlineComponent, StreamlineEventLogger.DELIMITER, event.getId(), StreamlineEventLogger.DELIMITER, "[" + event3.getId() + "]", StreamlineEventLogger.DELIMITER, "[" + event2.getId() + "]", StreamlineEventLogger.DELIMITER, ImmutableMap.copyOf(event), StreamlineEventLogger.DELIMITER, event.getHeader(), StreamlineEventLogger.DELIMITER, event.getAuxiliaryFieldsAndValues());
    eventInfo = new IEventLogger.EventInfo(timestamp, stormComponentName, taskId, messageId, values);
    actualMessage = sut.buildLogMessage(eventInfo);
    Assert.assertEquals(expectMessage, actualMessage);
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) IEventLogger(org.apache.storm.metric.IEventLogger) EventCorrelationInjector(com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector) 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