View Javadoc

1   /*
2    * $Id: QuartzCustomJobTestCase.java 22498 2011-07-21 13:01:39Z justin.calleja $
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 static org.junit.Assert.assertTrue;
14  
15  import java.util.Arrays;
16  import java.util.Collection;
17  import java.util.concurrent.CountDownLatch;
18  import java.util.concurrent.TimeUnit;
19  
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  import org.mule.tck.AbstractServiceAndFlowTestCase;
23  import org.quartz.Job;
24  import org.quartz.JobExecutionContext;
25  import org.quartz.JobExecutionException;
26  
27  public class QuartzCustomJobTestCase extends AbstractServiceAndFlowTestCase
28  {
29  
30      public QuartzCustomJobTestCase(ConfigVariant variant, String configResources)
31      {
32          super(variant, configResources);
33      }
34  
35      @Parameters
36      public static Collection<Object[]> parameters()
37      {
38          return Arrays.asList(new Object[][]{
39              {ConfigVariant.SERVICE, "quartz-custom-job-service.xml"},
40              {ConfigVariant.FLOW, "quartz-custom-job-flow.xml"}
41          });
42      }
43  
44      @Test
45      public void testCustomJob() throws Exception
46      {
47          CountDownLatch eventLatch = (CountDownLatch) muleContext.getRegistry().lookupObject("latch");
48  
49          // we wait up to 60 seconds here which is WAY too long for one tick but it seems that 
50          // "sometimes" it takes a very long time for Quartz go kick in. Once it starts 
51          // ticking everything is fine.
52          assertTrue(eventLatch.await(60000, TimeUnit.MILLISECONDS));
53      }
54      
55      public static class MockJob implements Job
56      {
57          private CountDownLatch eventLatch;
58  
59          public MockJob(CountDownLatch latch)
60          {
61              eventLatch = latch;
62          }
63          
64          public void execute(JobExecutionContext context) throws JobExecutionException
65          {
66              eventLatch.countDown();
67          }
68      }
69  }
70  
71