JunitTest.java 2.7 KB

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