Search in sources :

Example 11 with Notification

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

the class HBaseNotificationStoreIntegrationTest method testGetNotifications.

@Test
public void testGetNotifications() throws Exception {
    List<Notification> notifications = NotificationTestObjectFactory.getMany(10);
    for (Notification notification : notifications) {
        sut.store(notification);
    }
    List<Notification> fetchedNotifications = sut.getNotifications(Lists.transform(notifications, new Function<Notification, String>() {

        @Nullable
        @Override
        public String apply(@Nullable Notification notification) {
            return notification.getId();
        }
    }));
    assertEquals(notifications, fetchedNotifications);
}
Also used : Function(com.google.common.base.Function) Notification(com.hortonworks.streamline.streams.notification.Notification) Nullable(javax.annotation.Nullable) Test(org.junit.Test) HBaseIntegrationTest(com.hortonworks.streamline.common.test.HBaseIntegrationTest)

Example 12 with Notification

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

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

the class NotificationMapperTest method testEntity.

@Test
public void testEntity() 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 = "nid-1".getBytes();
            mockResult.getValue("s".getBytes(), "qs".getBytes());
            times = 1;
            result = "DELIVERED".getBytes();
            mockResult.getFamilyMap("ts".getBytes());
            times = 1;
            result = tsMap;
        }
    };
    Notification notification = notificationMapper.entity(mockResult);
    // System.out.println(notification);
    assertEquals(notification.getId(), "nid-1");
    assertEquals(notification.getStatus(), Notification.Status.DELIVERED);
    assertEquals(notification.getTs(), 1444042473518L);
}
Also used : Expectations(mockit.Expectations) Bytes(org.apache.hadoop.hbase.util.Bytes) TreeMap(java.util.TreeMap) Notification(com.hortonworks.streamline.streams.notification.Notification) Test(org.junit.Test)

Example 14 with Notification

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

the class NotificationBoltTest method testAck.

@Test
public void testAck() throws Exception {
    Map<String, Object> fieldsAndValues = new HashMap<>();
    fieldsAndValues.put("temperature", "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);
        }
    };
    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.DELIVERED);
            times = 1;
            collector.ack(tuple);
            times = 1;
            collector.fail(tuple);
            times = 0;
        }
    };
}
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)

Example 15 with Notification

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

the class NotificationBoltTest method setUp.

@Before
public void setUp() throws Exception {
    bolt = new NotificationBolt(new NotificationSink() {

        @Override
        public String getNotifierName() {
            return NOTIFIER_NAME;
        }

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

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

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

        @Override
        public Map<String, Object> getNotifierFieldValues() {
            return new HashMap<>();
        }
    });
    bolt.withNotificationStoreClass("com.hortonworks.streamline.streams.notification.store.hbase.HBaseNotificationStore");
    notifier = new Notifier() {

        private NotificationContext myCtx;

        @Override
        public void open(NotificationContext ctx) {
            System.out.println("Notifier open called with ctx " + ctx);
            Assert.assertEquals(ctx.getConfig().getProperties(), NOTIFIER_PROPS);
            Assert.assertEquals(ctx.getConfig().getDefaultFieldValues(), NOTIFIER_KV);
            myCtx = ctx;
        }

        @Override
        public void notify(Notification notification) {
            System.out.println("Notifier notify called with notification " + notification);
            String temp = (String) notification.getFieldsAndValues().get("temperature");
            if (temp == null) {
                myCtx.fail(notification.getId());
            } else {
                myCtx.ack(notification.getId());
            }
        }

        @Override
        public void close() {
            System.out.println("Notifier Close called");
        }

        @Override
        public boolean isPull() {
            return false;
        }

        @Override
        public List<String> getFields() {
            return new ArrayList<>();
        }

        @Override
        public NotificationContext getContext() {
            return myCtx;
        }
    };
}
Also used : NotificationContext(com.hortonworks.streamline.streams.notification.NotificationContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Notification(com.hortonworks.streamline.streams.notification.Notification) NotificationSink(com.hortonworks.streamline.streams.layout.component.impl.NotificationSink) ConsoleNotifier(com.hortonworks.streamline.streams.notifiers.ConsoleNotifier) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Before(org.junit.Before)

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