Commits

jhouse  committed e1cbb10

QUARTZ-659: RamJobStore does not remember paused job groups

git-svn-id: http://svn.opensymphony.com/svn/quartz/trunk@81369f7d36a-ea1c-0410-88ea-9fd03e4c9665

  • Participants
  • Parent commits 54b0700

Comments (0)

Files changed (2)

File src/java/org/quartz/simpl/RAMJobStore.java

 
     protected HashSet pausedTriggerGroups = new HashSet();
 
+    protected HashSet pausedJobGroups = new HashSet();
+
     protected HashSet blockedJobs = new HashSet();
     
     protected long misfireThreshold = 5000l;
             // add to triggers by FQN map
             triggersByFQN.put(tw.key, tw);
 
-            if (pausedTriggerGroups.contains(newTrigger.getGroup())) {
+            if (pausedTriggerGroups.contains(newTrigger.getGroup())
+            		|| pausedJobGroups.contains(newTrigger.getJobGroup())) {
                 tw.state = TriggerWrapper.STATE_PAUSED;
                 if (blockedJobs.contains(tw.jobKey)) {
                     tw.state = TriggerWrapper.STATE_PAUSED_BLOCKED;
      */
     public void pauseJobGroup(SchedulingContext ctxt, String groupName) {
         synchronized (triggerLock) {
+            if (!pausedJobGroups.contains(groupName)) {
+        	    pausedJobGroups.add(groupName);
+            }
+            
             String[] jobNames = getJobNames(ctxt, groupName);
 
             for (int i = 0; i < jobNames.length; i++) {
             String[] names = getTriggerNames(ctxt, groupName);
 
             for (int i = 0; i < names.length; i++) {
+            	String key = TriggerWrapper.getTriggerNameKey(names[i], groupName);
+            	if(triggersByFQN.get(key) != null) {
+            		String jobGroup = ((TriggerWrapper) triggersByFQN.get(key)).getTrigger().getJobGroup();
+            		if(pausedJobGroups.contains(jobGroup)) {
+            			continue;
+            		}
+            	}
                 resumeTrigger(ctxt, names[i], groupName);
             }
             pausedTriggerGroups.remove(groupName);
         synchronized (triggerLock) {
             String[] jobNames = getJobNames(ctxt, groupName);
 
+            if(pausedJobGroups.contains(groupName)) {
+            	pausedJobGroups.remove(groupName);
+            }
+            
             for (int i = 0; i < jobNames.length; i++) {
                 Trigger[] triggers = getTriggersForJob(ctxt, jobNames[i],
                         groupName);
     public void resumeAll(SchedulingContext ctxt) {
 
         synchronized (triggerLock) {
+        	pausedJobGroups.clear();
             String[] names = getTriggerGroupNames(ctxt);
 
             for (int i = 0; i < names.length; i++) {

File src/test/java/org/quartz/simpl/RAMJobStoreTest.java

         assertEquals( "StoreJob doesn't replace triggers", "QQ", fJobStore.retrieveTrigger(null, trName, trGroup).getCalendarName());
     }
 
+    public void testPauseJobGroupPausesNewJob() throws Exception
+    {
+    	final String jobName1 = "PauseJobGroupPausesNewJob";
+    	final String jobName2 = "PauseJobGroupPausesNewJob2";
+    	final String jobGroup = "PauseJobGroupPausesNewJobGroup";
+    
+    	JobDetail detail = new JobDetail(jobName1, jobGroup, NoOpJob.class);
+    	detail.setDurability(true);
+    	fJobStore.storeJob(null, detail, false);
+    	fJobStore.pauseJobGroup(null, jobGroup);
+    
+    	detail = new JobDetail(jobName2, jobGroup, NoOpJob.class);
+    	detail.setDurability(true);
+    	fJobStore.storeJob(null, detail, false);
+    
+    	String trName = "PauseJobGroupPausesNewJobTrigger";
+    	String trGroup = "PauseJobGroupPausesNewJobTriggerGroup";
+    	Trigger tr = new SimpleTrigger(trName, trGroup, new Date());
+    	tr.setJobGroup(jobGroup);
+    	tr.setJobName(jobName2);
+    	fJobStore.storeTrigger(null, tr, false);
+    	assertEquals(Trigger.STATE_PAUSED, fJobStore.getTriggerState(null, tr.getName(), tr.getGroup()));
+    }
+    
     public static class SampleSignaler implements SchedulerSignaler {
         int fMisfireCount = 0;