View Javadoc

1   /*
2    * $Id: QuartzCustomJobTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.quartz;
12  
13  import org.mule.tck.FunctionalTestCase;
14  
15  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
16  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
17  
18  import org.quartz.Job;
19  import org.quartz.JobExecutionContext;
20  import org.quartz.JobExecutionException;
21  
22  public class QuartzCustomJobTestCase extends FunctionalTestCase
23  {
24      @Override
25      protected String getConfigResources()
26      {
27          return "quartz-custom-job.xml";
28      }
29  
30      public void testCustomJob() throws Exception
31      {
32          CountDownLatch eventLatch = (CountDownLatch) muleContext.getRegistry().lookupObject("latch");
33  
34          // we wait up to 60 seconds here which is WAY too long for one tick but it seems that 
35          // "sometimes" it takes a very long time for Quartz go kick in. Once it starts 
36          // ticking everything is fine.
37          assertTrue(eventLatch.await(60000, TimeUnit.MILLISECONDS));
38      }
39      
40      public static class MockJob implements Job
41      {
42          private CountDownLatch eventLatch;
43  
44          public MockJob(CountDownLatch latch)
45          {
46              eventLatch = latch;
47          }
48          
49          public void execute(JobExecutionContext context) throws JobExecutionException
50          {
51              eventLatch.countDown();
52          }
53      }
54  }
55  
56