Search in sources :

Example 6 with Notifier

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

use of com.hortonworks.streamline.streams.notification.Notifier 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)

Example 8 with Notifier

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

the class NotificationServiceImplTest method testDuplicateRegister.

@Test
public void testDuplicateRegister() 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);
    new Expectations() {

        {
            mockCtx.getConfig();
            times = 2;
            result = mockNotifierConfig;
            mockNotifierConfig.getClassName();
            times = 1;
            result = "Test";
            mockNotifierConfig.getJarPath();
            times = 1;
            result = "/tmp/test.jar";
            mockProxyUtil.loadClassFromJar("/tmp/test.jar", "Test");
            result = mockNotifier;
        }
    };
    Notifier result = notificationService.register("test_notifier", mockCtx);
    assertEquals(mockNotifier, result);
    new Verifications() {

        {
            mockNotifier.open(mockCtx);
            times = 0;
        }
    };
}
Also used : Expectations(mockit.Expectations) Verifications(mockit.Verifications) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Test(org.junit.Test)

Example 9 with Notifier

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

the class NotificationServiceImplTest method testRemove.

@Test
public void testRemove() 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);
    Notifier result = notificationService.remove("test_notifier");
    assertEquals(mockNotifier, result);
    new Verifications() {

        {
            mockNotifier.close();
            times = 1;
        }
    };
    // removing again should return null
    result = notificationService.remove("test_notifier");
    assertEquals(null, result);
}
Also used : Expectations(mockit.Expectations) Verifications(mockit.Verifications) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Test(org.junit.Test)

Example 10 with Notifier

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

the class NotificationServiceImpl method notify.

@Override
public Future<?> notify(String notifierName, Notification notification) {
    LOG.debug("Notify notifierName {}, notification {}", notifierName, notification);
    notificationStore.ifPresent(s -> s.store(notification));
    Notifier notifier = notifiers.get(notifierName);
    if (notifier == null) {
        throw new NoSuchNotifierException("Notifier not found for id " + notification.getNotifierName());
    }
    return queueHandler.enqueue(notifier, notification);
}
Also used : Notifier(com.hortonworks.streamline.streams.notification.Notifier)

Aggregations

Notifier (com.hortonworks.streamline.streams.notification.Notifier)10 Expectations (mockit.Expectations)6 Verifications (mockit.Verifications)6 Test (org.junit.Test)6 Notification (com.hortonworks.streamline.streams.notification.Notification)4 ConsoleNotifier (com.hortonworks.streamline.streams.notifiers.ConsoleNotifier)4 HashMap (java.util.HashMap)4 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)3 StreamlineEventAdapter (com.hortonworks.streamline.streams.runtime.notification.StreamlineEventAdapter)3 MockUp (mockit.MockUp)3 NotificationSink (com.hortonworks.streamline.streams.layout.component.impl.NotificationSink)2 NotificationContext (com.hortonworks.streamline.streams.notification.NotificationContext)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Before (org.junit.Before)1