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.JobExecutionContext;
15  import org.quartz.JobExecutionException;
16  import org.quartz.StatefulJob;
17  
18  import static org.junit.Assert.assertTrue;
19  
20  public class QuartzCustomStatefulJobTestCase extends FunctionalTestCase
21  {
22      @Override
23      protected String getConfigResources()
24      {
25          return "quartz-custom-stateful-job.xml";
26      }
27      
28      @Test
29      public void testCustomStatefulJob() 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 MyStatefulJob implements StatefulJob
40      {
41          private CountDownLatch latch;
42  
43          public MyStatefulJob(CountDownLatch latch)
44          {
45              super();
46              this.latch = latch;
47          }
48          
49          public void execute(JobExecutionContext context) throws JobExecutionException
50          {
51              assertTrue(context.getJobDetail().isStateful());
52              latch.countDown();
53          }
54      }
55  }