JunitTest.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package quartz;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.util.Set;
  4. import java.util.concurrent.TimeUnit;
  5. import org.junit.Test;
  6. import org.junit.runner.RunWith;
  7. import org.quartz.JobKey;
  8. import org.quartz.SchedulerException;
  9. import org.springframework.test.context.ContextConfiguration;
  10. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  11. import com.xxl.quartz.DynamicSchedulerUtil;
  12. import com.xxl.service.job.TestDynamicJob;
  13. @RunWith(SpringJUnit4ClassRunner.class)
  14. @ContextConfiguration(locations = "classpath*:applicationcontext-*.xml")
  15. public class JunitTest {
  16. @Test
  17. public void getJobKeys() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException {
  18. Set<JobKey> list = DynamicSchedulerUtil.getJobKeys();
  19. System.out.println(list);
  20. TimeUnit.SECONDS.sleep(30);
  21. }
  22. @Test
  23. public void addJob() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException {
  24. boolean ret = DynamicSchedulerUtil.addJob("demo-job02", "0/2 * * * * ?", TestDynamicJob.class, null);
  25. System.out.println(ret);
  26. TimeUnit.SECONDS.sleep(30);
  27. }
  28. @Test
  29. public void removeJob() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException {
  30. boolean ret = DynamicSchedulerUtil.removeJob("demo-job02");
  31. System.out.println(ret);
  32. TimeUnit.SECONDS.sleep(30);
  33. }
  34. @Test
  35. public void rescheduleJob() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException {
  36. boolean ret = DynamicSchedulerUtil.rescheduleJob("demo-job02", "0/3 * * * * ?");
  37. System.out.println(ret);
  38. TimeUnit.SECONDS.sleep(30);
  39. }
  40. @Test
  41. public void pauseJob() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException {
  42. boolean ret = DynamicSchedulerUtil.pauseJob("demo-job02");
  43. System.out.println(ret);
  44. TimeUnit.SECONDS.sleep(30);
  45. }
  46. @Test
  47. public void resumeTrigger() throws SchedulerException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InterruptedException {
  48. boolean ret = DynamicSchedulerUtil.resumeTrigger("demo-job02");
  49. System.out.println(ret);
  50. TimeUnit.SECONDS.sleep(30);
  51. }
  52. }