Search in sources :

Example 1 with NotificationContext

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

the class NotificationServiceImplTest method testRegister.

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

        {
            NotificationContext ctx;
            mockNotifier.open(ctx = withCapture());
            times = 1;
            assertEquals(NotificationServiceContext.class, ctx.getClass());
        }
    };
}
Also used : Expectations(mockit.Expectations) NotificationContext(com.hortonworks.streamline.streams.notification.NotificationContext) Verifications(mockit.Verifications) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Test(org.junit.Test)

Example 2 with NotificationContext

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

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