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;
}
};
}
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;
}
};
}
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;
}
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));
}
};
}
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);
}
Aggregations