Search in sources :

Example 1 with Notification

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

the class HBaseNotificationStoreTest method testGetNotification.

@Test
public void testGetNotification() throws Exception {
    final Map<byte[], byte[]> tsMap = new TreeMap<>(new Bytes.ByteArrayComparator());
    tsMap.put("1444042473518".getBytes(), "1".getBytes());
    new Expectations() {

        {
            mockResult.getRow();
            times = 1;
            result = "rowid".getBytes(CHARSET);
            mockResult.getValue("s".getBytes(), "qs".getBytes());
            times = 1;
            result = "DELIVERED".getBytes();
            mockResult.getFamilyMap("ts".getBytes());
            times = 1;
            result = tsMap;
        }
    };
    Notification notification = notificationStore.getNotification("n123");
    // System.out.println(notification);
    assertEquals("rowid", notification.getId());
    assertEquals(Notification.Status.DELIVERED, notification.getStatus());
    assertEquals(1444042473518L, notification.getTs());
    new Verifications() {

        {
            Get get;
            mockHTable.get(get = withCapture());
            times = 1;
        // System.out.println("get = " + get);
        }
    };
}
Also used : Expectations(mockit.Expectations) Bytes(org.apache.hadoop.hbase.util.Bytes) Get(org.apache.hadoop.hbase.client.Get) TreeMap(java.util.TreeMap) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) Test(org.junit.Test)

Example 2 with Notification

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

the class NotificationIndexMappersTest method testGetRowKeys.

@Test
public void testGetRowKeys() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Map<String, Object> fieldAndValues = new HashMap<>();
    fieldAndValues.put("one", "A");
    // 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());
        StringBuilder expectedRowKey = new StringBuilder();
        for (String indexedField : testObject.getIndexedFieldNames()) {
            Object value = null;
            try {
                value = getValue(notification, indexedField);
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                try {
                    value = getValue(notification, indexedField + "s");
                } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e2) {
                    fail("getter not found for indexed field " + indexedField + "(s)");
                }
            }
            assertNotNull(value);
            expectedRowKey.append(value);
            expectedRowKey.append(ROWKEY_SEP);
        }
        expectedRowKey.append(generateExpectedIndexSuffix(notification, testObject));
        byte[] expectedRowKeyBytes = expectedRowKey.toString().getBytes(CHARSET);
        assertArrayEquals("getRowKeys() doesn't contain expected rowkey", expectedRowKeyBytes, testObject.getRowKeys(notification).get(0));
    }
    // for exception case: TimestampNotificationMapper
    TimestampNotificationMapper testObject = new TimestampNotificationMapper();
    LOG.info("testing mapper: {}", testObject.getClass().getCanonicalName());
    assertArrayEquals("getRowKeys() doesn't contain expected rowkey", generateExpectedIndexSuffix(notification, testObject).getBytes(CHARSET), testObject.getRowKeys(notification).get(0));
}
Also used : HashMap(java.util.HashMap) Notification(com.hortonworks.streamline.streams.notification.Notification) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 3 with Notification

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

the class NotificationTestObjectFactory method getManyWithRandomTimestamp.

public static List<Notification> getManyWithRandomTimestamp(int count) {
    Random random = new Random();
    List<Notification> notifications = Lists.newArrayList();
    for (int i = 0; i < count; i++) {
        // should have same digit since it should be compared to dictionary order which we don't want
        notifications.add(getOne(System.currentTimeMillis() - random.nextInt(10000)));
    }
    return notifications;
}
Also used : Random(java.util.Random) Notification(com.hortonworks.streamline.streams.notification.Notification)

Example 4 with Notification

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

the class NotificationBoltTest method testWithConsoleNotifier.

@Test
public void testWithConsoleNotifier() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("foo", "100");
    fieldsAndValues.put("bar", "200");
    final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("srcid").build();
    NotificationBolt consoleNotificationBolt = new NotificationBolt(new NotificationSink() {

        @Override
        public String getNotifierName() {
            return "console_notifier";
        }

        @Override
        public String getNotifierJarFileName() {
            return "console_notifier.jar";
        }

        @Override
        public String getNotifierClassName() {
            return "ConsoleNotifier";
        }

        @Override
        public Map<String, Object> getNotifierProperties() {
            return new HashMap<>();
        }

        @Override
        public Map<String, Object> getNotifierFieldValues() {
            return new HashMap<>();
        }
    });
    consoleNotificationBolt.withNotificationStoreClass("com.hortonworks.streamline.streams.notification.store.hbase.HBaseNotificationStore");
    final ConsoleNotifier consoleNotifier = new ConsoleNotifier();
    final Notification notification = new StreamlineEventAdapter(event);
    new MockUp<NotificationQueueHandler>() {

        @Mock
        public void enqueue(Notifier notifier, Notification notification1) {
            // System.out.println("Mocked enqueue");
            notifier.notify(notification);
        }
    };
    new Expectations() {

        {
            mockProxyUtil.loadClassFromJar("/tmp/console_notifier.jar", "ConsoleNotifier");
            result = consoleNotifier;
            tuple.getValueByField(anyString);
            result = event;
        }
    };
    Map<String, String> stormConf = new HashMap<>();
    stormConf.put("catalog.root.url", "http://localhost:8080/api/v1/catalog");
    stormConf.put("local.notifier.jar.path", "/tmp");
    consoleNotificationBolt.prepare(stormConf, null, collector);
    consoleNotificationBolt.execute(tuple);
    new Verifications() {

        {
            collector.ack(tuple);
            times = 1;
            hBaseNotificationStore.store(notification);
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) MockUp(mockit.MockUp) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) NotificationSink(com.hortonworks.streamline.streams.layout.component.impl.NotificationSink) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) StreamlineEventAdapter(com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter) HashMap(java.util.HashMap) Map(java.util.Map) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Test(org.junit.Test)

Example 5 with Notification

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

the class NotificationBoltTest method testFail.

@Test
public void testFail() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("foobar", "100");
    final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("srcid").build();
    final Notification notification = new StreamlineEventAdapter(event);
    new MockUp<NotificationQueueHandler>() {

        @Mock
        public void enqueue(Notifier notifier, Notification notification1) {
            notifier.notify(notification);
        }

        @Mock
        public void resubmit(String notificationId) {
            notifier.notify(notification);
        }
    };
    new Expectations() {

        {
            mockProxyUtil.loadClassFromJar(anyString, "TestClass");
            result = notifier;
            tuple.getValueByField(anyString);
            result = event;
        }
    };
    Map<String, String> stormConf = new HashMap<>();
    stormConf.put("catalog.root.url", "http://localhost:8080/api/v1/catalog");
    stormConf.put("local.notifier.jar.path", "/tmp");
    bolt.prepare(stormConf, null, collector);
    bolt.execute(tuple);
    new Verifications() {

        {
            hBaseNotificationStore.store(notification);
            times = 1;
            hBaseNotificationStore.updateNotificationStatus(notification.getId(), Notification.Status.FAILED);
            times = 1;
            collector.ack(tuple);
            times = 0;
            collector.fail(tuple);
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) StreamlineEventAdapter(com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter) MockUp(mockit.MockUp) Verifications(mockit.Verifications) Notification(com.hortonworks.streamline.streams.notification.Notification) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) Notifier(com.hortonworks.streamline.streams.notification.Notifier) 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