Search in sources :

Example 21 with Notification

use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.

the class HBaseNotificationStoreIntegrationTest method testGetNotification.

@Test
public void testGetNotification() throws IOException {
    Notification notification = NotificationTestObjectFactory.getOne();
    // covered by testStoreNotification()
    sut.store(notification);
    Notification fetchedNotification = sut.getNotification(notification.getId());
    assertEquals(notification, fetchedNotification);
}
Also used : Notification(com.hortonworks.streamline.streams.notification.Notification) Test(org.junit.Test) HBaseIntegrationTest(com.hortonworks.streamline.common.test.HBaseIntegrationTest)

Example 22 with Notification

use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.

the class HBaseNotificationStoreIntegrationTest method testStoreNotification.

@Test
public void testStoreNotification() throws IOException {
    Notification notification = NotificationTestObjectFactory.getOne();
    sut.store(notification);
    // rely on result of tableMutations() to avoid checking manually
    // didn't check each cell's value but comparing will be covered by testGetNotification()
    List<TableMutation> expectedMutations = notificationMapper.tableMutations(notification);
    checkMutationsReflectToHBase(expectedMutations);
}
Also used : Notification(com.hortonworks.streamline.streams.notification.Notification) TableMutation(com.hortonworks.streamline.streams.notification.store.hbase.mappers.TableMutation) Test(org.junit.Test) HBaseIntegrationTest(com.hortonworks.streamline.common.test.HBaseIntegrationTest)

Example 23 with Notification

use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.

the class HBaseNotificationStoreIntegrationTest method testUpdateNotificationStatus.

@Test
public void testUpdateNotificationStatus() throws Exception {
    Notification notification = NotificationTestObjectFactory.getOne();
    sut.store(notification);
    Notification.Status newStatus = Notification.Status.FAILED;
    Notification fetchedNotification = sut.updateNotificationStatus(notification.getId(), newStatus);
    assertEquals(fetchedNotification.getId(), notification.getId());
    assertEquals(fetchedNotification.getStatus(), newStatus);
    // rely on result of status() to avoid checking manually
    List<TableMutation> expectedMutations = notificationMapper.status(notification, newStatus);
    checkMutationsReflectToHBase(expectedMutations);
}
Also used : Notification(com.hortonworks.streamline.streams.notification.Notification) TableMutation(com.hortonworks.streamline.streams.notification.store.hbase.mappers.TableMutation) Test(org.junit.Test) HBaseIntegrationTest(com.hortonworks.streamline.common.test.HBaseIntegrationTest)

Example 24 with Notification

use of com.hortonworks.streamline.streams.notification.Notification 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 25 with Notification

use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.

the class NotificationMapperTest method testTableMutations.

@Test
public void testTableMutations() throws Exception {
    Map<String, Object> fieldAndValues = new HashMap<>();
    fieldAndValues.put("one", "A");
    Notification notification = new NotificationImpl.Builder(fieldAndValues).id("notification-id").dataSourceIds(Arrays.asList("dsrcid-1")).eventIds(Arrays.asList("eventid-1")).notifierName("test-notifier").ruleId("rule-1").build();
    List<TableMutation> tms = notificationMapper.tableMutations(notification);
    System.out.println(tms);
    assertEquals(1, tms.size());
    TableMutation tm = tms.get(0);
    assertEquals("Notification", tm.tableName());
    assertEquals(1, tm.updates().size());
    Put put = tm.updates().get(0);
    assertTrue(put.has("f".getBytes(), "one".getBytes(), new Serializer().serialize("A")));
    assertTrue(put.has("d".getBytes(), "dsrcid-1".getBytes(), "1".getBytes()));
    assertTrue(put.has("e".getBytes(), "eventid-1".getBytes(), "1".getBytes()));
    assertTrue(put.has("nn".getBytes(), "test-notifier".getBytes(), "1".getBytes()));
    assertTrue(put.has("r".getBytes(), "rule-1".getBytes(), "1".getBytes()));
    assertTrue(put.has("s".getBytes(), "qs".getBytes(), "NEW".getBytes()));
}
Also used : HashMap(java.util.HashMap) Notification(com.hortonworks.streamline.streams.notification.Notification) Put(org.apache.hadoop.hbase.client.Put) Serializer(com.hortonworks.streamline.streams.notification.store.hbase.Serializer) Test(org.junit.Test)

Aggregations

Notification (com.hortonworks.streamline.streams.notification.Notification)26 Test (org.junit.Test)18 Expectations (mockit.Expectations)9 HashMap (java.util.HashMap)7 Verifications (mockit.Verifications)6 HBaseIntegrationTest (com.hortonworks.streamline.common.test.HBaseIntegrationTest)5 Notifier (com.hortonworks.streamline.streams.notification.Notifier)5 CriteriaImpl (com.hortonworks.streamline.streams.notification.store.CriteriaImpl)5 ArrayList (java.util.ArrayList)5 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)4 ConsoleNotifier (com.hortonworks.streamline.streams.notifiers.ConsoleNotifier)4 StreamlineEventAdapter (com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter)4 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 MockUp (mockit.MockUp)3 Bytes (org.apache.hadoop.hbase.util.Bytes)3 Timed (com.codahale.metrics.annotation.Timed)2 QueryParam (com.hortonworks.registries.common.QueryParam)2 NotificationSink (com.hortonworks.streamline.streams.layout.component.impl.NotificationSink)2 NotificationContext (com.hortonworks.streamline.streams.notification.NotificationContext)2