Search in sources :

Example 16 with Notification

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");
        }
    };
}
Also used : Expectations(mockit.Expectations) QueryParam(com.hortonworks.registries.common.QueryParam) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) Test(org.junit.Test)

Example 17 with Notification

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);
        }
    };
}
Also used : Expectations(mockit.Expectations) CriteriaImpl(com.hortonworks.streamline.streams.notification.store.CriteriaImpl) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) Result(org.apache.hadoop.hbase.client.Result) Bytes(org.apache.hadoop.hbase.util.Bytes) Scan(org.apache.hadoop.hbase.client.Scan) Test(org.junit.Test)

Example 18 with Notification

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

Example 19 with Notification

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

Example 20 with Notification

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);
}
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)

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