Search in sources :

Example 1 with EventCorrelationInjector

use of com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector 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)

Example 2 with EventCorrelationInjector

use of com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector in project streamline by hortonworks.

the class EventInformationBuilderTest method testBuild.

@Test
public void testBuild() throws Exception {
    long timestamp = System.currentTimeMillis();
    EventCorrelationInjector injector = new EventCorrelationInjector();
    StreamlineEvent parentEvent = copyEventWithNewID();
    // use same component name for parent and ancestor for easy testing
    // this line is covered via `testNoParent()`
    parentEvent = injector.injectCorrelationInformation(parentEvent, Collections.emptyList(), TEST_COMPONENT_NAME);
    StreamlineEvent injectedEvent = injector.injectCorrelationInformation(INPUT_STREAMLINE_EVENT, Collections.singletonList(parentEvent), TEST_COMPONENT_NAME);
    EventInformation information = sut.build(timestamp, TEST_COMPONENT_NAME, TEST_STREAM_ID, Sets.newHashSet(TEST_TARGET_COMPONENT_NAME, TEST_TARGET_COMPONENT_NAME_2), injectedEvent);
    assertEquals(timestamp, information.getTimestamp());
    assertEquals(injectedEvent.getId(), information.getEventId());
    assertEquals(EventCorrelationInjector.getRootIds(injectedEvent), information.getRootIds());
    assertEquals(EventCorrelationInjector.getParentIds(injectedEvent), information.getParentIds());
    assertEquals(EventCorrelationInjector.getSourceComponentName(injectedEvent), information.getComponentName());
    assertEquals(TEST_COMPONENT_NAME, information.getComponentName());
    assertEquals(TEST_STREAM_ID, information.getStreamId());
    assertEquals(Sets.newHashSet(TEST_TARGET_COMPONENT_NAME, TEST_TARGET_COMPONENT_NAME_2), information.getTargetComponents());
}
Also used : StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) EventCorrelationInjector(com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector) Test(org.junit.Test)

Aggregations

StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)2 EventCorrelationInjector (com.hortonworks.streamline.streams.common.event.correlation.EventCorrelationInjector)2 Test (org.junit.Test)2 IEventLogger (org.apache.storm.metric.IEventLogger)1