Search in sources :

Example 1 with NotificationSink

use of com.hortonworks.streamline.streams.layout.component.impl.NotificationSink 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 2 with NotificationSink

use of com.hortonworks.streamline.streams.layout.component.impl.NotificationSink 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

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