@Override protected Integer doExecute() throws Exception { final Map<String, Scheduler> schedulerMap = (Map<String, Scheduler>) appCtx.getBean("schedulerMap"); System.out.println( ansi() .render( "@|negative_on %3s|%-20s|%-15s|%-3s|%-3s|%-3s|%-25s|@", "№", "Name/Tenant", "Instance ID", "Cur", "Job", "Trg", "Store")); int i = 0; for (Entry<String, Scheduler> entry : schedulerMap.entrySet()) { // final String tenantId = entry.getKey(); final Scheduler scheduler = entry.getValue(); final Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.anyJobGroup()); final List<JobExecutionContext> executingJobs = scheduler.getCurrentlyExecutingJobs(); final Set<TriggerKey> triggerKeys = scheduler.getTriggerKeys(GroupMatcher.anyTriggerGroup()); final String startedAnsi = scheduler.isStarted() ? "@|bold,green ▶|@" : "@|bold,red ◼|@"; System.out.println( ansi() .render( "@|bold,black %3d||@" + startedAnsi + "%-19s@|bold,black ||@%-15s@|bold,black ||@%3d@|bold,black ||@%3d@|bold,black ||@%3d@|bold,black ||@%-25s", ++i, scheduler.getSchedulerName(), scheduler.getSchedulerInstanceId(), executingJobs.size(), jobKeys.size(), triggerKeys.size(), scheduler.getMetaData().getJobStoreClass().getSimpleName())); } System.out.println(ansi().render("@|bold,yellow %d|@ Schedulers", schedulerMap.size())); return schedulerMap.size(); }
@Test public void testBasicStorageFunctions() throws Exception { Scheduler sched = createScheduler("testBasicStorageFunctions", 2); // test basic storage functions of scheduler... JobDetail job = newJob().ofType(TestJob.class).withIdentity("j1").storeDurably().build(); assertFalse("Unexpected existence of job named 'j1'.", sched.checkExists(jobKey("j1"))); sched.addJob(job, false); assertTrue( "Expected existence of job named 'j1' but checkExists return false.", sched.checkExists(jobKey("j1"))); job = sched.getJobDetail(jobKey("j1")); assertNotNull("Stored job not found!", job); sched.deleteJob(jobKey("j1")); Trigger trigger = newTrigger() .withIdentity("t1") .forJob(job) .startNow() .withSchedule(simpleSchedule().repeatForever().withIntervalInSeconds(5)) .build(); assertFalse("Unexpected existence of trigger named 't1'.", sched.checkExists(triggerKey("t1"))); sched.scheduleJob(job, trigger); assertTrue( "Expected existence of trigger named 't1' but checkExists return false.", sched.checkExists(triggerKey("t1"))); job = sched.getJobDetail(jobKey("j1")); assertNotNull("Stored job not found!", job); trigger = sched.getTrigger(triggerKey("t1")); assertNotNull("Stored trigger not found!", trigger); job = newJob().ofType(TestJob.class).withIdentity("j2", "g1").build(); trigger = newTrigger() .withIdentity("t2", "g1") .forJob(job) .startNow() .withSchedule(simpleSchedule().repeatForever().withIntervalInSeconds(5)) .build(); sched.scheduleJob(job, trigger); job = newJob().ofType(TestJob.class).withIdentity("j3", "g1").build(); trigger = newTrigger() .withIdentity("t3", "g1") .forJob(job) .startNow() .withSchedule(simpleSchedule().repeatForever().withIntervalInSeconds(5)) .build(); sched.scheduleJob(job, trigger); List<String> jobGroups = sched.getJobGroupNames(); List<String> triggerGroups = sched.getTriggerGroupNames(); assertTrue("Job group list size expected to be = 2 ", jobGroups.size() == 2); assertTrue("Trigger group list size expected to be = 2 ", triggerGroups.size() == 2); Set<JobKey> jobKeys = sched.getJobKeys(GroupMatcher.jobGroupEquals(JobKey.DEFAULT_GROUP)); Set<TriggerKey> triggerKeys = sched.getTriggerKeys(GroupMatcher.triggerGroupEquals(TriggerKey.DEFAULT_GROUP)); assertTrue("Number of jobs expected in default group was 1 ", jobKeys.size() == 1); assertTrue("Number of triggers expected in default group was 1 ", triggerKeys.size() == 1); jobKeys = sched.getJobKeys(GroupMatcher.jobGroupEquals("g1")); triggerKeys = sched.getTriggerKeys(GroupMatcher.triggerGroupEquals("g1")); assertTrue("Number of jobs expected in 'g1' group was 2 ", jobKeys.size() == 2); assertTrue("Number of triggers expected in 'g1' group was 2 ", triggerKeys.size() == 2); TriggerState s = sched.getTriggerState(triggerKey("t2", "g1")); assertTrue("State of trigger t2 expected to be NORMAL ", s.equals(TriggerState.NORMAL)); sched.pauseTrigger(triggerKey("t2", "g1")); s = sched.getTriggerState(triggerKey("t2", "g1")); assertTrue("State of trigger t2 expected to be PAUSED ", s.equals(TriggerState.PAUSED)); sched.resumeTrigger(triggerKey("t2", "g1")); s = sched.getTriggerState(triggerKey("t2", "g1")); assertTrue("State of trigger t2 expected to be NORMAL ", s.equals(TriggerState.NORMAL)); Set<String> pausedGroups = sched.getPausedTriggerGroups(); assertTrue("Size of paused trigger groups list expected to be 0 ", pausedGroups.size() == 0); sched.pauseTriggers(GroupMatcher.triggerGroupEquals("g1")); // test that adding a trigger to a paused group causes the new trigger to be paused also... job = newJob().ofType(TestJob.class).withIdentity("j4", "g1").build(); trigger = newTrigger() .withIdentity("t4", "g1") .forJob(job) .startNow() .withSchedule(simpleSchedule().repeatForever().withIntervalInSeconds(5)) .build(); sched.scheduleJob(job, trigger); // TODO: nexus hack: JobStoreImpl DOES NOT "remember" paused groups sched.pauseJob(jobKey("j4", "g1")); pausedGroups = sched.getPausedTriggerGroups(); assertTrue( "Size of paused trigger groups list expected to be 1: " + pausedGroups, pausedGroups.size() == 1); s = sched.getTriggerState(triggerKey("t2", "g1")); assertTrue("State of trigger t2 expected to be PAUSED ", s.equals(TriggerState.PAUSED)); s = sched.getTriggerState(triggerKey("t4", "g1")); assertTrue("State of trigger t4 expected to be PAUSED ", s.equals(TriggerState.PAUSED)); sched.resumeTriggers(GroupMatcher.triggerGroupEquals("g1")); s = sched.getTriggerState(triggerKey("t2", "g1")); assertTrue("State of trigger t2 expected to be NORMAL ", s.equals(TriggerState.NORMAL)); s = sched.getTriggerState(triggerKey("t4", "g1")); assertTrue("State of trigger t4 expected to be NORMAL ", s.equals(TriggerState.NORMAL)); pausedGroups = sched.getPausedTriggerGroups(); assertTrue("Size of paused trigger groups list expected to be 0 ", pausedGroups.size() == 0); assertFalse( "Scheduler should have returned 'false' from attempt to unschedule non-existing trigger. ", sched.unscheduleJob(triggerKey("foasldfksajdflk"))); assertTrue( "Scheduler should have returned 'true' from attempt to unschedule existing trigger. ", sched.unscheduleJob(triggerKey("t3", "g1"))); jobKeys = sched.getJobKeys(GroupMatcher.jobGroupEquals("g1")); triggerKeys = sched.getTriggerKeys(GroupMatcher.triggerGroupEquals("g1")); assertTrue( "Number of jobs expected in 'g1' group was 1 ", jobKeys.size() == 2); // job should have been deleted also, because it is non-durable assertTrue("Number of triggers expected in 'g1' group was 1 ", triggerKeys.size() == 2); assertTrue( "Scheduler should have returned 'true' from attempt to unschedule existing trigger. ", sched.unscheduleJob(triggerKey("t1"))); jobKeys = sched.getJobKeys(GroupMatcher.jobGroupEquals(JobKey.DEFAULT_GROUP)); triggerKeys = sched.getTriggerKeys(GroupMatcher.triggerGroupEquals(TriggerKey.DEFAULT_GROUP)); assertTrue( "Number of jobs expected in default group was 1 ", jobKeys.size() == 1); // job should have been left in place, because it is non-durable assertTrue("Number of triggers expected in default group was 0 ", triggerKeys.size() == 0); sched.shutdown(true); }