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