use of com.hortonworks.streamline.streams.notification.store.CriteriaImpl in project streamline by hortonworks.
the class HBaseScanConfigBuilderTest method testGetScanConfig.
@Test
public void testGetScanConfig() throws Exception {
final List<Criteria.Field> fr = new ArrayList<>();
fr.add(new CriteriaImpl.FieldImpl("notifierName", "test_notifier"));
fr.add(new CriteriaImpl.FieldImpl("status", "NEW"));
final List<byte[]> nnList = Arrays.asList("s".getBytes(CHARSET), "qs".getBytes(CHARSET), "NEW".getBytes(CHARSET));
new Expectations() {
{
mockNotificationCriteria.clazz();
times = 1;
result = Notification.class;
mockNotificationCriteria.fieldRestrictions();
times = 1;
result = fr;
mockIndexMapper.getIndexedFieldNames();
times = 1;
result = Arrays.asList("notifierName");
mockNotificationCriteria.numRows();
times = 1;
result = 5;
mockIndexMapper.mapMemberValue("status", "NEW");
times = 1;
result = nnList;
}
};
hBaseScanConfigBuilder = new HBaseScanConfigBuilder();
hBaseScanConfigBuilder.addMappers(Notification.class, Arrays.asList(mockIndexMapper));
Criteria<Notification> eventCriteria = new CriteriaImpl<>(Notification.class);
HBaseScanConfig<Notification> notificationScanConfig = hBaseScanConfigBuilder.getScanConfig(mockNotificationCriteria);
System.out.println(notificationScanConfig);
assertEquals(mockIndexMapper, notificationScanConfig.getMapper());
assertArrayEquals("test_notifier|0".getBytes(CHARSET), notificationScanConfig.getStartRow());
assertArrayEquals(("test_notifier|" + Long.MAX_VALUE).getBytes(CHARSET), notificationScanConfig.getStopRow());
assertEquals(2, notificationScanConfig.filterList().getFilters().size());
// column filter should be first
Filter firstFilter = notificationScanConfig.filterList().getFilters().get(0);
assertEquals(SingleColumnValueFilter.class, firstFilter.getClass());
// page filter should be last
Filter secondFilter = notificationScanConfig.filterList().getFilters().get(1);
assertEquals(PageFilter.class, secondFilter.getClass());
}
use of com.hortonworks.streamline.streams.notification.store.CriteriaImpl 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);
}
use of com.hortonworks.streamline.streams.notification.store.CriteriaImpl in project streamline by hortonworks.
the class HBaseScanConfigBuilderTest method testGetScanConfigWithTs.
@Test
public void testGetScanConfigWithTs() throws Exception {
final List<Criteria.Field> fr = new ArrayList<>();
fr.add(new CriteriaImpl.FieldImpl("notifierName", "test_notifier"));
fr.add(new CriteriaImpl.FieldImpl("status", "NEW"));
final long ts = System.currentTimeMillis();
final long endts = ts + 100;
final List<byte[]> nnList = Arrays.asList("s".getBytes(CHARSET), "qs".getBytes(CHARSET), "NEW".getBytes(CHARSET));
new Expectations() {
{
mockNotificationCriteria.clazz();
times = 1;
result = Notification.class;
mockNotificationCriteria.fieldRestrictions();
times = 1;
result = fr;
mockIndexMapper.getIndexedFieldNames();
times = 1;
result = Arrays.asList("notifierName");
mockNotificationCriteria.numRows();
times = 1;
result = 5;
mockIndexMapper.mapMemberValue("status", "NEW");
times = 1;
result = nnList;
mockNotificationCriteria.startTs();
result = ts;
mockNotificationCriteria.endTs();
result = endts;
}
};
hBaseScanConfigBuilder = new HBaseScanConfigBuilder();
hBaseScanConfigBuilder.addMappers(Notification.class, Arrays.asList(mockIndexMapper));
Criteria<Notification> eventCriteria = new CriteriaImpl<>(Notification.class);
HBaseScanConfig<Notification> notificationScanConfig = hBaseScanConfigBuilder.getScanConfig(mockNotificationCriteria);
System.out.println(notificationScanConfig);
assertEquals(mockIndexMapper, notificationScanConfig.getMapper());
assertArrayEquals(("test_notifier|" + ts).getBytes(CHARSET), notificationScanConfig.getStartRow());
assertArrayEquals(("test_notifier|" + endts).getBytes(CHARSET), notificationScanConfig.getStopRow());
assertEquals(2, notificationScanConfig.filterList().getFilters().size());
// column filter should be first
Filter firstFilter = notificationScanConfig.filterList().getFilters().get(0);
assertEquals(SingleColumnValueFilter.class, firstFilter.getClass());
// page filter should be last
Filter secondFilter = notificationScanConfig.filterList().getFilters().get(1);
assertEquals(PageFilter.class, secondFilter.getClass());
}
use of com.hortonworks.streamline.streams.notification.store.CriteriaImpl in project streamline by hortonworks.
the class NotificationServiceImpl method findNotifications.
@Override
public List<Notification> findNotifications(List<QueryParam> queryParams) {
LOG.debug("findNotifications with queryParams {}", queryParams);
CriteriaImpl<Notification> criteria = new CriteriaImpl<>(Notification.class);
for (QueryParam qp : queryParams) {
if (qp.name.equalsIgnoreCase(QUERY_PARAM_NUM_ROWS)) {
criteria.setNumRows(Integer.parseInt(qp.value));
} else if (qp.name.equals(QUERY_PARAM_START_TS)) {
criteria.setStartTs(Long.parseLong(qp.value));
} else if (qp.name.equals((QUERY_PARAM_END_TS))) {
criteria.setEndTs(Long.parseLong(qp.value));
} else if (qp.name.equals((QUERY_PARAM_DESC))) {
criteria.setDescending(true);
} else {
criteria.addFieldRestriction(qp.name, qp.value);
}
}
LOG.debug("Finding entities from notification store with criteria {}", criteria);
return notificationStore.map(s -> s.findEntities(criteria)).orElse(Collections.emptyList());
}
Aggregations