Search in sources :

Example 1 with CriteriaImpl

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());
}
Also used : Expectations(mockit.Expectations) CriteriaImpl(com.hortonworks.streamline.streams.notification.store.CriteriaImpl) PageFilter(org.apache.hadoop.hbase.filter.PageFilter) Filter(org.apache.hadoop.hbase.filter.Filter) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) ArrayList(java.util.ArrayList) Notification(com.hortonworks.streamline.streams.notification.Notification) Test(org.junit.Test)

Example 2 with CriteriaImpl

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);
}
Also used : CriteriaImpl(com.hortonworks.streamline.streams.notification.store.CriteriaImpl) Notification(com.hortonworks.streamline.streams.notification.Notification) Test(org.junit.Test) HBaseIntegrationTest(com.hortonworks.streamline.common.test.HBaseIntegrationTest)

Example 3 with CriteriaImpl

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());
}
Also used : Expectations(mockit.Expectations) CriteriaImpl(com.hortonworks.streamline.streams.notification.store.CriteriaImpl) ArrayList(java.util.ArrayList) Notification(com.hortonworks.streamline.streams.notification.Notification) PageFilter(org.apache.hadoop.hbase.filter.PageFilter) Filter(org.apache.hadoop.hbase.filter.Filter) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) Test(org.junit.Test)

Example 4 with CriteriaImpl

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());
}
Also used : Logger(org.slf4j.Logger) ProxyUtil(com.hortonworks.streamline.common.util.ProxyUtil) QueryParam(com.hortonworks.registries.common.QueryParam) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Notification(com.hortonworks.streamline.streams.notification.Notification) HBaseNotificationStore(com.hortonworks.streamline.streams.notification.store.hbase.HBaseNotificationStore) CriteriaImpl(com.hortonworks.streamline.streams.notification.store.CriteriaImpl) List(java.util.List) Future(java.util.concurrent.Future) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Map(java.util.Map) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Optional(java.util.Optional) Collections(java.util.Collections) NotificationStore(com.hortonworks.streamline.streams.notification.store.NotificationStore) NotificationContext(com.hortonworks.streamline.streams.notification.NotificationContext) CriteriaImpl(com.hortonworks.streamline.streams.notification.store.CriteriaImpl) QueryParam(com.hortonworks.registries.common.QueryParam) Notification(com.hortonworks.streamline.streams.notification.Notification)

Aggregations

Notification (com.hortonworks.streamline.streams.notification.Notification)4 CriteriaImpl (com.hortonworks.streamline.streams.notification.store.CriteriaImpl)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Expectations (mockit.Expectations)2 Filter (org.apache.hadoop.hbase.filter.Filter)2 PageFilter (org.apache.hadoop.hbase.filter.PageFilter)2 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)2 QueryParam (com.hortonworks.registries.common.QueryParam)1 HBaseIntegrationTest (com.hortonworks.streamline.common.test.HBaseIntegrationTest)1 ProxyUtil (com.hortonworks.streamline.common.util.ProxyUtil)1 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)1 NotificationContext (com.hortonworks.streamline.streams.notification.NotificationContext)1 Notifier (com.hortonworks.streamline.streams.notification.Notifier)1 NotificationStore (com.hortonworks.streamline.streams.notification.store.NotificationStore)1 HBaseNotificationStore (com.hortonworks.streamline.streams.notification.store.hbase.HBaseNotificationStore)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1