use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class EventCorrelationInjectorTest method eventArgsTestWithTwoParentsWhichOneIsRootEventAndAnotherOneIsNonRootEvent.
@Test
public void eventArgsTestWithTwoParentsWhichOneIsRootEventAndAnotherOneIsNonRootEvent() throws Exception {
StreamlineEvent parentEvent1 = copyEventWithNewID();
// this line is covered via `testNoParent()`
parentEvent1 = sut.injectCorrelationInformation(parentEvent1, Collections.emptyList(), TEST_COMPONENT_NAME);
StreamlineEvent parentOfParentEvent2 = copyEventWithNewID();
// this line is covered via `testNoParent()`
parentOfParentEvent2 = sut.injectCorrelationInformation(parentOfParentEvent2, Collections.emptyList(), TEST_COMPONENT_NAME);
StreamlineEvent parentEvent2 = copyEventWithNewID();
// this line is covered via `testWithAParentWhichIsRootEvent()`
parentEvent2 = sut.injectCorrelationInformation(parentEvent2, Collections.singletonList(parentOfParentEvent2), TEST_COMPONENT_NAME);
StreamlineEvent injectedEvent = sut.injectCorrelationInformation(INPUT_STREAMLINE_EVENT, Lists.newArrayList(parentEvent1, parentEvent2), TEST_COMPONENT_NAME);
StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
// added headers
assertEquals(Sets.newHashSet(parentEvent1.getId(), parentOfParentEvent2.getId()), EventCorrelationInjector.getRootIds(injectedEvent));
assertEquals(Sets.newHashSet(parentEvent1.getId(), parentEvent2.getId()), EventCorrelationInjector.getParentIds(injectedEvent));
assertEquals(TEST_COMPONENT_NAME, EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class EventCorrelationInjectorTest method eventArgsTestNoParent.
@Test
public void eventArgsTestNoParent() throws Exception {
StreamlineEvent injectedEvent = sut.injectCorrelationInformation(INPUT_STREAMLINE_EVENT, Collections.emptyList(), TEST_COMPONENT_NAME);
StreamlineEventTestUtil.assertEventIsProperlyCopied(injectedEvent, INPUT_STREAMLINE_EVENT);
// added headers
// if rootIds is empty itself is the root event
assertEquals(Collections.emptySet(), EventCorrelationInjector.getRootIds(injectedEvent));
assertEquals(Collections.emptySet(), EventCorrelationInjector.getParentIds(injectedEvent));
assertEquals(TEST_COMPONENT_NAME, EventCorrelationInjector.getSourceComponentName(injectedEvent));
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class NotificationsTestBolt method process.
@Override
protected void process(Tuple input) {
StreamlineEvent event = (StreamlineEvent) input.getValueByField(StreamlineEvent.STREAMLINE_EVENT);
List<String> eventIds = Arrays.asList(event.getId());
List<String> dataSourceIds = Arrays.asList(event.getDataSourceId());
if (!consoleNotificationStream.isEmpty()) {
// Create a dummy Notification object
Map<String, Object> fieldsMap = new HashMap<>();
fieldsMap.put("temperature", "100");
fieldsMap.put("humidity", "100");
Map<String, Object> header = new HashMap<>();
header.put(AddHeaderTransformRuntime.HEADER_FIELD_EVENT_IDS, eventIds);
header.put(AddHeaderTransformRuntime.HEADER_FIELD_DATASOURCE_IDS, dataSourceIds);
header.put(AddHeaderTransformRuntime.HEADER_FIELD_NOTIFIER_NAME, "console_notifier");
header.put(AddHeaderTransformRuntime.HEADER_FIELD_RULE_ID, 1L);
header.put(AddHeaderTransformRuntime.HEADER_FIELD_TIMESTAMP, System.currentTimeMillis());
StreamlineEvent streamlineEvent = StreamlineEventImpl.builder().fieldsAndValues(fieldsMap).dataSourceId("notificationsTestBolt").header(header).build();
collector.emit(consoleNotificationStream, new Values(streamlineEvent));
}
// Send an email every EMAIL_NOTIFICATION_INTERVAL
if (++count % EMAIL_NOTIFICATION_INTERVAL == 0) {
if (!emailNotificationStream.isEmpty()) {
Map<String, Object> fieldsMap = new HashMap<>();
fieldsMap.put("body", "Too many notifications, count so far is " + count);
Map<String, Object> header = new HashMap<>();
header.put(AddHeaderTransformRuntime.HEADER_FIELD_EVENT_IDS, eventIds);
header.put(AddHeaderTransformRuntime.HEADER_FIELD_DATASOURCE_IDS, dataSourceIds);
header.put(AddHeaderTransformRuntime.HEADER_FIELD_NOTIFIER_NAME, "email_notifier");
header.put(AddHeaderTransformRuntime.HEADER_FIELD_RULE_ID, 1L);
header.put(AddHeaderTransformRuntime.HEADER_FIELD_TIMESTAMP, System.currentTimeMillis());
StreamlineEvent streamlineEvent = StreamlineEventImpl.builder().fieldsAndValues(fieldsMap).dataSourceId("notificationsTestBolt").header(header).build();
collector.emit(emailNotificationStream, new Values(streamlineEvent));
}
}
collector.ack(input);
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class NotificationBoltTest method testAck.
@Test
public void testAck() throws Exception {
Map<String, Object> fieldsAndValues = new HashMap<>();
fieldsAndValues.put("temperature", "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);
}
};
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.DELIVERED);
times = 1;
collector.ack(tuple);
times = 1;
collector.fail(tuple);
times = 0;
}
};
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class SqlBasicExprScriptTest method testBasicAggregation.
@Test
public void testBasicAggregation() throws Exception {
// SELECT STREAM DEPTID, EMPID, MIN(SALARY) FROM FOO where ID > 0 GROUP BY DEPTID, EMPID
Expression min_salary = new AggregateFunctionExpression("MIN", ImmutableList.of(new FieldExpression(Schema.Field.of("salary", Schema.Type.INTEGER))));
Expression deptid = new FieldExpression(Schema.Field.of("deptid", Schema.Type.INTEGER));
Expression empid = new FieldExpression(Schema.Field.of("empid", Schema.Type.INTEGER));
GroupBy groupBy = new GroupBy(ImmutableList.of(deptid, empid));
Expression id = new FieldExpression(Schema.Field.of("id", Schema.Type.INTEGER));
Expression id_gt_0 = new BinaryExpression(Operator.GREATER_THAN, id, new Literal("0"));
Condition condition = new Condition();
condition.setExpression(id_gt_0);
Projection projection = new Projection();
projection.setExpressions(ImmutableList.<Expression>of(deptid, empid, min_salary));
sqlScript = new SqlScript(new StormSqlExpression(condition, projection, groupBy, null), new SqlEngine(), new SqlScript.CorrelatedValuesToStreamlineEventConverter(Lists.newArrayList("deptid", "empid", "MIN")));
// (100, 100), 10
Map<String, Object> kv1 = new HashMap<>();
kv1.put("id", 1);
kv1.put("deptid", 100);
kv1.put("empid", 100);
kv1.put("salary", 10);
// (100, 100), 5
Map<String, Object> kv2 = new HashMap<>();
kv2.put("id", 2);
kv2.put("deptid", 100);
kv2.put("empid", 100);
kv2.put("salary", 5);
// (101, 101), 10
Map<String, Object> kv3 = new HashMap<>();
kv3.put("id", 3);
kv3.put("deptid", 101);
kv3.put("empid", 101);
kv3.put("salary", 10);
// (102, 102), 5
Map<String, Object> kv4 = new HashMap<>();
kv4.put("id", 4);
kv4.put("deptid", 102);
kv4.put("empid", 102);
kv4.put("salary", 5);
StreamlineEvent group1Event1 = StreamlineEventImpl.builder().fieldsAndValues(kv1).dataSourceId("1").build();
StreamlineEvent group1Event2 = StreamlineEventImpl.builder().fieldsAndValues(kv2).dataSourceId("1").build();
StreamlineEvent group2Event1 = StreamlineEventImpl.builder().fieldsAndValues(kv3).dataSourceId("1").build();
StreamlineEvent group3Event1 = StreamlineEventImpl.builder().fieldsAndValues(kv4).dataSourceId("1").build();
sqlScript.evaluate(group1Event1);
sqlScript.evaluate(group1Event2);
sqlScript.evaluate(group2Event1);
sqlScript.evaluate(group3Event1);
Collection<StreamlineEvent> result = sqlScript.evaluate(StreamlineEventImpl.GROUP_BY_TRIGGER_EVENT);
Assert.assertEquals(3, result.size());
Map<List<Integer>, Pair<Integer, Set<String>>> expectedGroupValueToMinAndParentIds;
expectedGroupValueToMinAndParentIds = new HashMap<>();
expectedGroupValueToMinAndParentIds.put(Lists.newArrayList(100, 100), new ImmutablePair<>(5, Sets.newHashSet(group1Event1.getId(), group1Event2.getId())));
expectedGroupValueToMinAndParentIds.put(Lists.newArrayList(101, 101), new ImmutablePair<>(10, Sets.newHashSet(group2Event1.getId())));
expectedGroupValueToMinAndParentIds.put(Lists.newArrayList(102, 102), new ImmutablePair<>(5, Sets.newHashSet(group3Event1.getId())));
result.iterator().forEachRemaining(res -> {
List<Integer> groupValue = Lists.newArrayList((Integer) res.get("deptid"), (Integer) res.get("empid"));
Assert.assertTrue(expectedGroupValueToMinAndParentIds.containsKey(groupValue));
Pair<Integer, Set<String>> minAndPairIds = expectedGroupValueToMinAndParentIds.get(groupValue);
Integer minValue = (Integer) res.get("MIN");
Assert.assertEquals(minValue, minAndPairIds.getLeft());
Assert.assertTrue(EventCorrelationInjector.containsParentIds(res));
Assert.assertEquals(minAndPairIds.getRight(), EventCorrelationInjector.getParentIds(res));
// avoid matching multiple times
expectedGroupValueToMinAndParentIds.remove(groupValue);
});
}
Aggregations