Search in sources :

Example 6 with IntegerAction

use of org.mule.runtime.api.notification.IntegerAction in project mule by mulesoft.

the class ServerNotificationsTestCase method testCustomNotifications.

@Test
public void testCustomNotifications() throws Exception {
    final CountDownLatch latch = new CountDownLatch(2);
    getNotificationListenerRegistry().registerListener((DummyNotificationListener) notification -> {
        if (new IntegerAction(EVENT_RECEIVED).equals(notification.getAction())) {
            customNotificationCount.incrementAndGet();
            assertEquals("hello", ((EventObject) notification).getSource());
            latch.countDown();
        }
    });
    getNotificationDispatcher().dispatch(new DummyNotification("hello", EVENT_RECEIVED));
    getNotificationDispatcher().dispatch(new DummyNotification("hello", EVENT_RECEIVED));
    // Wait for the notifcation event to be fired as they are queued
    latch.await(2000, MILLISECONDS);
    assertEquals(2, customNotificationCount.get());
}
Also used : EVENT_RECEIVED(org.mule.runtime.core.api.context.notification.ServerNotificationsTestCase.DummyNotification.EVENT_RECEIVED) CustomNotificationListener(org.mule.runtime.api.notification.CustomNotificationListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) EventObject(java.util.EventObject) Mockito.doThrow(org.mockito.Mockito.doThrow) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Notification(org.mule.runtime.api.notification.Notification) MuleContext(org.mule.runtime.core.api.MuleContext) Scheduler(org.mule.runtime.api.scheduler.Scheduler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CONTEXT_STOPPED(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STOPPED) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Mockito.when(org.mockito.Mockito.when) CustomNotification(org.mule.runtime.api.notification.CustomNotification) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito.never(org.mockito.Mockito.never) IntegerAction(org.mule.runtime.api.notification.IntegerAction) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) Assert.assertFalse(org.junit.Assert.assertFalse) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) NotificationListener(org.mule.runtime.api.notification.NotificationListener) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) IntegerAction(org.mule.runtime.api.notification.IntegerAction) CountDownLatch(java.util.concurrent.CountDownLatch) EventObject(java.util.EventObject) Test(org.junit.Test)

Aggregations

IntegerAction (org.mule.runtime.api.notification.IntegerAction)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 Test (org.junit.Test)4 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)4 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 NotificationListenerRegistry (org.mule.runtime.api.notification.NotificationListenerRegistry)3 MuleContext (org.mule.runtime.core.api.MuleContext)3 AbstractMuleContextTestCase (org.mule.tck.junit4.AbstractMuleContextTestCase)3 Callable (java.util.concurrent.Callable)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 Thread.currentThread (java.lang.Thread.currentThread)1 Thread.sleep (java.lang.Thread.sleep)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Collections.synchronizedSet (java.util.Collections.synchronizedSet)1 EventObject (java.util.EventObject)1 HashSet (java.util.HashSet)1