Package org.mule.util.concurrent

Examples of org.mule.util.concurrent.Latch


     * SEE MULE-3974
     */
    @Test
    public void testMaxActiveThreadsEqualsOneWhenExhaustedActionWait() throws Exception
    {
        final Latch latch = new Latch();
        service.setName("testMaxActiveThreadsEqualsOne");
        ChainedThreadingProfile threadingProfile = (ChainedThreadingProfile) muleContext.getDefaultServiceThreadingProfile();
        threadingProfile.setMaxThreadsActive(1);
        threadingProfile.setThreadWaitTimeout(200);
        threadingProfile.setPoolExhaustedAction(ThreadingProfile.WHEN_EXHAUSTED_WAIT);
        service.setThreadingProfile(threadingProfile);
        final SimpleCallableJavaComponent component = new SimpleCallableJavaComponent(new Callable()
        {
            @Override
            public Object onCall(MuleEventContext eventContext) throws Exception
            {
                latch.countDown();
                return null;
            }
        });
        component.setMuleContext(muleContext);
        service.setComponent(component);
        muleContext.getRegistry().registerService(service);

        service.process(MuleTestUtils.getTestEvent("test", service, muleContext));
        assertTrue(latch.await(200, TimeUnit.MILLISECONDS));

        // This test will fail with RejectedExcecutionException if dispatch() blocks
    }
View Full Code Here


     * SEE MULE-3975
     */
    @Test
    public void testDoThreadingFalse() throws Exception
    {
        final Latch latch = new Latch();
        final String serviceName = "testDoThreadingFalse";

        service.setName(serviceName);
        ChainedThreadingProfile threadingProfile = (ChainedThreadingProfile) muleContext.getDefaultServiceThreadingProfile();
        threadingProfile.setDoThreading(false);
        service.setThreadingProfile(threadingProfile);
        final Thread mainThread = Thread.currentThread();

        final SimpleCallableJavaComponent component = new SimpleCallableJavaComponent(new Callable()
        {
            @Override
            public Object onCall(MuleEventContext eventContext) throws Exception
            {
                assertEquals(mainThread, Thread.currentThread());
                latch.countDown();
                return null;
            }
        });
        component.setMuleContext(muleContext);
        service.setComponent(component);
        muleContext.getRegistry().registerService(service);

        service.process(MuleTestUtils.getTestEvent("test",
            getTestInboundEndpoint(MessageExchangePattern.ONE_WAY), muleContext));

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

     * SEE MULE-3975
     */
    @Test
    public void testDoThreadingTrue() throws Exception
    {
        final Latch latch = new Latch();
        final String serviceName = "testDoThreadingFalse";

        service.setName(serviceName);
        ChainedThreadingProfile threadingProfile = (ChainedThreadingProfile) muleContext.getDefaultServiceThreadingProfile();
        threadingProfile.setDoThreading(true);
        service.setThreadingProfile(threadingProfile);
        final SimpleCallableJavaComponent component = new SimpleCallableJavaComponent(new Callable()
        {
            @Override
            public Object onCall(MuleEventContext eventContext) throws Exception
            {
                System.out.println(Thread.currentThread().getName());
                assertTrue(Thread.currentThread().getName().startsWith(serviceName));
                latch.countDown();
                return null;
            }
        });
        component.setMuleContext(muleContext);
        service.setComponent(component);
        muleContext.getRegistry().registerService(service);

        service.process(MuleTestUtils.getTestEvent("test",
            getTestInboundEndpoint(MessageExchangePattern.ONE_WAY), muleContext));

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

    }

    @Before
    public void setUp() throws Exception
    {
        outboundComponentLatch = new Latch();
        deadLetterQueueLatch = new Latch();
        outboundComponentReached = false;
    }
View Full Code Here

    }

    @Before
    public void setUp() throws Exception
    {
        deadLetterQueueLatch = new Latch();
        outboundComponentLatch = new Latch();
        outboundComponentReached = false;
    }
View Full Code Here

    public void testTakePut() throws Exception
    {
        final QueueManager mgr = createQueueManager();
        mgr.start();

        final Latch latch = new Latch();

        Thread t = new Thread()
        {
            @Override
            public void run()
            {
                try
                {
                    latch.countDown();
                    Thread.sleep(200);
                    QueueSession s = mgr.getQueueSession();
                    Queue q = s.getQueue("queue1");
                    assertEquals("Queue size", 0, q.size());
                    q.put("String1");
                }
                catch (Exception e)
                {
                    // ignore, let test fail
                }
            }
        };
        t.start();
        latch.await();
        long t0 = System.currentTimeMillis();
        QueueSession s = mgr.getQueueSession();
        Queue q = s.getQueue("queue1");
        assertEquals("Queue size", 0, q.size());
        Object o = q.take();
View Full Code Here

    public void testPutTakeUntake() throws Exception
    {
        final QueueManager mgr = createQueueManager();
        mgr.start();

        final Latch latch = new Latch();

        Thread t = new Thread()
        {
            @Override
            public void run()
            {
                try
                {
                    latch.countDown();
                    Thread.sleep(200);
                    QueueSession s = mgr.getQueueSession();
                    Queue q = s.getQueue("queue1");
                    assertEquals("Queue size", 0, q.size());
                    q.put("String1");
                    q.put("String2");
                }
                catch (Exception e)
                {
                    // ignore, let test fail
                }
            }
        };
        t.start();
        latch.await();
        long t0 = System.currentTimeMillis();
        QueueSession s = mgr.getQueueSession();
        Queue q = s.getQueue("queue1");
        assertEquals("Queue size", 0, q.size());
        Serializable o = q.take();
View Full Code Here

    public void testTakePutRollbackPut() throws Exception
    {
        final QueueManager mgr = createQueueManager();
        mgr.start();

        final Latch latch = new Latch();

        Thread t = new Thread()
        {
            @Override
            public void run()
            {
                try
                {
                    latch.countDown();
                    Thread.sleep(200);
                    QueueSession s = mgr.getQueueSession();
                    Queue q = s.getQueue("queue1");
                    assertEquals("Queue size", 0, q.size());
                    s.begin();
                    q.put("String1");
                    s.rollback();
                    s.begin();
                    q.put("String2");
                    s.commit();
                }
                catch (Exception e)
                {
                    // ignore, let test fail
                }
            }
        };
        t.start();
        latch.await();
        long t0 = System.currentTimeMillis();
        QueueSession s = mgr.getQueueSession();
        Queue q = s.getQueue("queue1");
        assertEquals("Queue size", 0, q.size());
        Object o = q.take();
View Full Code Here

    public void testPutTakeUntakeRollbackUntake() throws Exception
    {
        final QueueManager mgr = createQueueManager();
        mgr.start();

        final Latch latch = new Latch();

        final Serializable object1 = "string1";
        final Serializable object2 = "string2";

        Thread t = new Thread()
        {
            @Override
            public void run()
            {
                try
                {
                    latch.countDown();
                    Thread.sleep(200);
                    QueueSession s = mgr.getQueueSession();
                    Queue q = s.getQueue("queue1");
                    assertEquals("Queue size", 0, q.size());

                    s.begin();
                    q.untake(object1);
                    s.commit();

                    s.begin();
                    q.untake(object2);
                    s.rollback();
                }
                catch (Exception e)
                {
                    // ignore, let test fail
                }
            }
        };
        t.start();
        latch.await();
        long t0 = System.currentTimeMillis();
        QueueSession s = mgr.getQueueSession();
        Queue q = s.getQueue("queue1");
        assertEquals("Queue size", 0, q.size());
        Object o = q.take();
View Full Code Here

    {
        final QueueManager mgr = createQueueManager();
        mgr.start();
        mgr.setDefaultQueueConfiguration(new DefaultQueueConfiguration(2, false));

        final Latch latch = new Latch();

        Thread t = new Thread()
        {
            @Override
            public void run()
            {
                try
                {
                    latch.await();
                    Thread.sleep(200);
                    QueueSession s = mgr.getQueueSession();
                    Queue q = s.getQueue("queue1");
                    Object o = q.take();
                    assertEquals("Queue content", "String1", o);
                }
                catch (Exception e)
                {
                    // ignore, let test fail
                }
            }
        };
        t.start();

        QueueSession s = mgr.getQueueSession();
        Queue q = s.getQueue("queue1");
        assertEquals("Queue size", 0, q.size());
        q.put("String1");
        q.put("String2");

        latch.countDown();

        long t0 = System.currentTimeMillis();
        q.put("String3");
        long t1 = System.currentTimeMillis();
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.