Package org.mule.util.concurrent

Examples of org.mule.util.concurrent.Latch


public class SecureHttpPollingFunctionalTestCase extends FunctionalTestCase
{

    public void testPollingHttpConnectorSentCredentials() throws Exception
    {
        final Latch latch = new Latch();
        muleContext.registerListener(new SecurityNotificationListener<SecurityNotification>()
        {
            public void onNotification(SecurityNotification notification)
            {
                latch.countDown();
            }
        });
        MuleClient client = new MuleClient(muleContext);
        MuleMessage result = client.request("vm://toclient", 5000);
        assertNotNull(result);
        assertEquals("foo", result.getPayloadAsString());

        result = client.request("vm://toclient2", 1000);
        //This seems a little odd that we forward the exception to the outbound endpoint, but I guess users
        // can just add a filter
        assertNotNull(result);
        final int status = result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0);
        assertEquals(401, status);
        assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));

    }
View Full Code Here


        return "org/mule/test/integration/transformer/auto-transformer-test.xml";
    }

    public void testInboundAutoTransform() throws Exception
    {
        latch = new Latch();
        MuleClient client = new MuleClient(muleContext);
        client.dispatch("vm://in", new FruitBowl(new Apple(), new Banana()), null);

        assertTrue(latch.await(3000, TimeUnit.MILLISECONDS));
    }
View Full Code Here

        this.workManager = workManager;
        this.delegate = delegate;
        this.startLatch = startLatch;
        if (this.startLatch == null)
        {
            this.startLatch = new Latch();
            this.startLatch.countDown();
        }
    }
View Full Code Here

        assertNotNull(subscriptionBean);
        MuleEventMulticaster multicaster = (MuleEventMulticaster) muleContext.getRegistry().lookupObject(
            AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME);
        assertNotNull(multicaster);

        Latch whenFinished = new Latch();
        subscriptionBean.setEventCallback(new CountingEventCallback(eventCounter1, 1, whenFinished));

        multicaster.removeApplicationListener(subscriptionBean);
        MuleClient client = new MuleClient(muleContext);
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);

        assertEquals(0, eventCounter1.get());

        multicaster.addApplicationListener(subscriptionBean);
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);

        assertTrue(whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS));
        assertEquals(1, eventCounter1.get());
        eventCounter1.set(0);

        multicaster.removeAllListeners();
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);
View Full Code Here

        TestMuleEventBean bean = (TestMuleEventBean) muleContext.getRegistry().lookupObject(
            "testNonSubscribingMuleEventBean");
        assertNotNull(bean);

        // register a callback
        Latch whenFinished = new Latch();
        bean.setEventCallback(new CountingEventCallback(eventCounter1, 1, whenFinished));

        MuleClient client = new MuleClient(muleContext);
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(1, eventCounter1.get());
    }
View Full Code Here

    {
        TestApplicationEventBean bean = (TestApplicationEventBean) muleContext.getRegistry().lookupObject(
            "testEventSpringBean");
        assertNotNull(bean);

        final Latch whenFinished = new Latch();
        EventCallback callback = new EventCallback()
        {
            public void eventReceived(MuleEventContext context, Object o) throws Exception
            {
                assertNull(context);
                if (o instanceof TestApplicationEvent)
                {
                    if (eventCounter1.incrementAndGet() == 1)
                    {
                        whenFinished.countDown();
                    }
                }
            }
        };

        bean.setEventCallback(callback);

        ApplicationContext context = ((MuleEventMulticaster) muleContext.getRegistry().lookupObject(
            "applicationEventMulticaster")).applicationContext;
        context.publishEvent(new TestApplicationEvent(context));

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(1, eventCounter1.get());
    }
View Full Code Here

    public void testReceivingAllEvents() throws Exception
    {
        TestAllEventBean bean = (TestAllEventBean) muleContext.getRegistry().lookupObject("testAllEventBean");
        assertNotNull(bean);

        Latch whenFinished = new Latch();
        bean.setEventCallback(new CountingEventCallback(eventCounter1, 2, whenFinished));

        MuleClient client = new MuleClient(muleContext);
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);
        ApplicationContext context = ((MuleEventMulticaster) muleContext.getRegistry().lookupObject(
            "applicationEventMulticaster")).applicationContext;
        context.publishEvent(new TestApplicationEvent(context));

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(2, eventCounter1.get());
    }
View Full Code Here

    {
        TestSubscriptionEventBean subscriptionBean = (TestSubscriptionEventBean) muleContext.getRegistry()
            .lookupObject("testSubscribingEventBean1");
        assertNotNull(subscriptionBean);

        Latch whenFinished = new Latch();
        subscriptionBean.setEventCallback(new CountingEventCallback(eventCounter1, 1, whenFinished));

        MuleClient client = new MuleClient(muleContext);
        client.send("vm://event.multicaster", "Test Spring MuleEvent", null);

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(1, eventCounter1.get());
    }
View Full Code Here

    {
        TestSubscriptionEventBean bean1 = (TestSubscriptionEventBean) muleContext.getRegistry().lookupObject(
            "testSubscribingEventBean1");
        assertNotNull(bean1);

        final Latch whenFinished1 = new Latch();
        EventCallback callback = new EventCallback()
        {
            public void eventReceived(MuleEventContext context, Object o) throws Exception
            {
                MuleApplicationEvent returnEvent = new MuleApplicationEvent("MuleEvent from a spring bean",
                    "vm://testBean2");
                MuleApplicationEvent e = (MuleApplicationEvent) o;
                e.getApplicationContext().publishEvent(returnEvent);
                if (eventCounter1.incrementAndGet() == NUMBER_OF_MESSAGES)
                {
                    whenFinished1.countDown();
                }
            }
        };
        bean1.setEventCallback(callback);

        TestSubscriptionEventBean bean2 = (TestSubscriptionEventBean) muleContext.getRegistry().lookupObject(
            "testSubscribingEventBean2");
        assertNotNull(bean2);

        Latch whenFinished2 = new Latch();
        bean2.setEventCallback(new CountingEventCallback(eventCounter2, NUMBER_OF_MESSAGES, whenFinished2));

        // send asynchronously
        this.doSend("vm://event.multicaster", "Test Spring MuleEvent", NUMBER_OF_MESSAGES);

        whenFinished1.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        whenFinished2.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(NUMBER_OF_MESSAGES, eventCounter1.get());
        assertEquals(NUMBER_OF_MESSAGES, eventCounter2.get());
    }
View Full Code Here

        TestSubscriptionEventBean bean2 = (TestSubscriptionEventBean) muleContext.getRegistry().lookupObject(
            "testSubscribingEventBean2");
        assertNotNull(bean2);

        Latch whenFinished = new Latch();
        bean2.setEventCallback(new CountingEventCallback(eventCounter1, NUMBER_OF_MESSAGES, whenFinished));

        // publish asynchronously
        this.doPublish(event, NUMBER_OF_MESSAGES);

        whenFinished.await(DEFAULT_LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
        assertEquals(NUMBER_OF_MESSAGES, eventCounter1.get());
    }
View Full Code Here

TOP

Related Classes of org.mule.util.concurrent.Latch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.