Search in sources :

Example 1 with Notifier

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

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

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

Example 4 with Notifier

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

the class NotificationServiceImpl method register.

@Override
public Notifier register(String notifierName, NotificationContext ctx) {
    LOG.info("Registering notifier name {}, NotificationContext {}", notifierName, ctx);
    Notifier notifier = loadNotifier(ctx.getConfig().getJarPath(), ctx.getConfig().getClassName());
    Notifier registeredNotifier = notifiers.putIfAbsent(notifierName, notifier);
    if (registeredNotifier == null) {
        LOG.info("Initializing notifier");
        notifier.open(new NotificationServiceContext(ctx, queueHandler, this));
        registeredNotifier = notifier;
    }
    LOG.info("Notifier {} registered", notifierName);
    return registeredNotifier;
}
Also used : Notifier(com.hortonworks.streamline.streams.notification.Notifier)

Example 5 with Notifier

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

the class NotificationServiceImpl method remove.

@Override
public Notifier remove(String notifierName) {
    LOG.info("De-registering notifier {}", notifierName);
    Notifier notifier = notifiers.remove(notifierName);
    if (notifier != null) {
        LOG.info("Closing notifier {}", notifierName);
        notifier.close();
    }
    return notifier;
}
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