use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class NotificationServiceImplTest method testFindNotifications.
@Test
public void testFindNotifications() throws Exception {
new Expectations() {
{
mockCtx.getConfig();
times = 3;
result = mockNotifierConfig;
mockNotifierConfig.getClassName();
times = 1;
result = "Test";
mockNotifierConfig.getJarPath();
times = 1;
result = "/tmp/test.jar";
mockProxyUtil.loadClassFromJar("/tmp/test.jar", "Test");
result = mockNotifier;
}
};
notificationService.register("test_notifier", mockCtx);
QueryParam qp1 = new QueryParam("one", "1");
QueryParam qp2 = new QueryParam("two", "2");
QueryParam qp3 = new QueryParam("numRows", "5");
notificationService.findNotifications(Arrays.asList(qp1, qp2, qp3));
new Verifications() {
{
Criteria<Notification> criteria;
mockNotificationStore.findEntities(criteria = withCapture());
// System.out.println("criteria = " + criteria);
assertEquals(criteria.clazz(), Notification.class);
assertEquals(criteria.numRows(), 5);
assertEquals(criteria.fieldRestrictions().size(), 2);
assertEquals(criteria.fieldRestrictions().get(0).getValue(), "1");
assertEquals(criteria.fieldRestrictions().get(1).getValue(), "2");
}
};
notificationService.findNotifications(Arrays.asList(qp1, qp2));
new Verifications() {
{
Criteria<Notification> criteria;
mockNotificationStore.findEntities(criteria = withCapture());
// System.out.println("criteria = " + criteria);
assertEquals(criteria.clazz(), Notification.class);
assertEquals(0, criteria.numRows());
assertEquals(criteria.fieldRestrictions().size(), 2);
assertEquals(criteria.fieldRestrictions().get(0).getValue(), "1");
assertEquals(criteria.fieldRestrictions().get(1).getValue(), "2");
}
};
}
use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class HBaseNotificationStoreTest method testFindEntities.
@Test
public void testFindEntities() throws Exception {
final List<Criteria.Field> fr = new ArrayList<>();
fr.add(new CriteriaImpl.FieldImpl("ruleId", "1"));
fr.add(new CriteriaImpl.FieldImpl("status", "NEW"));
final Map<byte[], byte[]> tsMap = new TreeMap<>(new Bytes.ByteArrayComparator());
tsMap.put("1444042473518".getBytes(), "1".getBytes());
final Map<byte[], byte[]> niMap = new TreeMap<>(new Bytes.ByteArrayComparator());
niMap.put("nid".getBytes(), "1".getBytes());
final List<Result> results = Arrays.asList(mockResult);
new Expectations() {
{
mockCriteria.clazz();
times = 1;
result = Notification.class;
mockCriteria.fieldRestrictions();
times = 1;
result = fr;
mockHTable.getScanner(withAny(new Scan()));
times = 1;
result = mockResultScanner;
mockResultScanner.iterator();
result = results.iterator();
mockResult.getFamilyMap("ni".getBytes());
times = 1;
result = niMap;
mockResult.getValue("s".getBytes(), "qs".getBytes());
times = 1;
result = "NEW".getBytes();
mockResult.getFamilyMap("ts".getBytes());
times = 1;
result = tsMap;
}
};
List<Notification> notifications = notificationStore.findEntities(mockCriteria);
System.out.println(notifications);
assertEquals("nid", notifications.get(0).getId());
assertEquals(Notification.Status.NEW, notifications.get(0).getStatus());
assertEquals(1444042473518L, notifications.get(0).getTs());
new Verifications() {
{
Scan scan;
mockHTable.getScanner(scan = withCapture());
times = 1;
System.out.println("Scan = " + scan);
}
};
}
use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class NotificationIndexMappersTest method testUpdateStatus.
@Test
public void testUpdateStatus() {
// assume test notification has one datasource and one event id
// for simplicity
Notification notification = NotificationTestObjectFactory.getOne();
assertEquals(1, notification.getDataSourceIds().size());
assertEquals(1, notification.getEventIds().size());
for (NotificationIndexMapper testObject : testObjects) {
LOG.info("testing mapper: {}", testObject.getClass().getCanonicalName());
List<byte[]> rowKeys = testObject.getRowKeys(notification);
assertEquals(1, rowKeys.size());
List<TableMutation> tableMutations = testObject.status(notification, Notification.Status.FAILED);
Notification appliedStatus = NotificationTestObjectFactory.applyStatus(notification, Notification.Status.FAILED);
List<byte[]> newRowKeys = testObject.getRowKeys(appliedStatus);
assertEquals(1, newRowKeys.size());
if (testObject instanceof NotificationStatusIndexMapper) {
assertEquals(2, tableMutations.size());
for (TableMutation tableMutation : tableMutations) {
if (!tableMutation.updates().isEmpty()) {
assertEquals(1, tableMutation.updates().size());
assertTrue(tableMutation.deletes().isEmpty());
// should add row with rowkey which reflects new status
assertArrayEquals(newRowKeys.get(0), tableMutation.updates().get(0).getRow());
} else if (!tableMutation.deletes().isEmpty()) {
assertTrue(tableMutation.updates().isEmpty());
assertEquals(1, tableMutation.deletes().size());
// should delete row with rowkey which reflects old status
assertArrayEquals(rowKeys.get(0), tableMutation.deletes().get(0).getRow());
} else {
fail("should have any updates or deletes");
}
}
} else {
assertEquals(1, tableMutations.size());
TableMutation tableMutation = tableMutations.get(0);
assertEquals(1, tableMutation.updates().size());
assertArrayEquals(newRowKeys.get(0), tableMutation.updates().get(0).getRow());
assertTrue(tableMutation.deletes().isEmpty());
}
}
}
use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class NotificationIndexMappersTest method testTableMutations.
@Test
public void testTableMutations() {
// assume test notification has one datasource and one event id
// for simplicity
Notification notification = NotificationTestObjectFactory.getOne();
assertEquals(1, notification.getDataSourceIds().size());
assertEquals(1, notification.getEventIds().size());
for (NotificationIndexMapper testObject : testObjects) {
LOG.info("testing mapper: {}", testObject.getClass().getCanonicalName());
List<byte[]> rowKeys = testObject.getRowKeys(notification);
List<TableMutation> tableMutations = testObject.tableMutations(notification);
assertEquals(rowKeys.size(), tableMutations.size());
assertEquals(1, rowKeys.size());
byte[] rowKey = rowKeys.get(0);
TableMutation tableMutation = tableMutations.get(0);
assertEquals(1, tableMutation.updates().size());
assertTrue(tableMutation.deletes().isEmpty());
assertArrayEquals(rowKey, tableMutation.updates().get(0).getRow());
}
}
use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class HBaseNotificationStoreIntegrationTest method testFindEntities.
@Test
public void testFindEntities() throws Exception {
List<Notification> notifications = NotificationTestObjectFactory.getManyWithRandomTimestamp(10);
for (Notification notification : notifications) {
sut.store(notification);
}
Collections.sort(notifications, new Comparator<Notification>() {
@Override
public int compare(Notification o1, Notification o2) {
return Long.valueOf(o1.getTs() - o2.getTs()).intValue();
}
});
CriteriaImpl<Notification> criteria = new CriteriaImpl<>(Notification.class);
criteria.setStartTs(notifications.get(2).getTs());
criteria.setEndTs(notifications.get(6).getTs());
// take less than range
criteria.setNumRows(3);
criteria.setDescending(true);
// 5, 4, 3
List<Notification> expectedList = notifications.subList(3, 6);
Collections.sort(expectedList, new Comparator<Notification>() {
@Override
public int compare(Notification o1, Notification o2) {
return Long.valueOf(o2.getTs() - o1.getTs()).intValue();
}
});
List<Notification> fetchedNotifications = sut.findEntities(criteria);
assertEquals(expectedList, fetchedNotifications);
}
Aggregations