Anonymous avatar Anonymous committed c4c2f38

Applying the patch from QUARTZ-606 based on Marko's suggested change in Quartz.NET

git-svn-id: http://svn.opensymphony.com/svn/quartz/branches/quartz_1-6@722 69f7d36a-ea1c-0410-88ea-9fd03e4c9665

Comments (0)

Files changed (2)

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

                 throw new ObjectAlreadyExistsException(newTrigger);
             }
 
-            removeTrigger(ctxt, newTrigger.getName(), newTrigger.getGroup());
+            removeTrigger(ctxt, newTrigger.getName(), newTrigger.getGroup(), false);
         }
 
         if (retrieveJob(ctxt, newTrigger.getJobName(), newTrigger.getJobGroup()) == null) {
      */
     public boolean removeTrigger(SchedulingContext ctxt, String triggerName,
             String groupName) {
+        return removeTrigger(ctxt, triggerName, groupName, true);
+    }
+    private boolean removeTrigger(SchedulingContext ctxt, String triggerName,
+            String groupName, boolean removeOrphanedJob) {
         String key = TriggerWrapper.getTriggerNameKey(triggerName, groupName);
 
         boolean found = false;
                 }
                 timeTriggers.remove(tw);
 
-                JobWrapper jw = (JobWrapper) jobsByFQN.get(JobWrapper
-                        .getJobNameKey(tw.trigger.getJobName(), tw.trigger
-                                .getJobGroup()));
-                Trigger[] trigs = getTriggersForJob(ctxt, tw.trigger
-                        .getJobName(), tw.trigger.getJobGroup());
-                if ((trigs == null || trigs.length == 0) && !jw.jobDetail.isDurable()) {
-                    removeJob(ctxt, tw.trigger.getJobName(), tw.trigger
-                            .getJobGroup());
+                if (removeOrphanedJob) {
+                    JobWrapper jw = (JobWrapper) jobsByFQN.get(JobWrapper
+                            .getJobNameKey(tw.trigger.getJobName(), tw.trigger
+                                    .getJobGroup()));
+                    Trigger[] trigs = getTriggersForJob(ctxt, tw.trigger
+                            .getJobName(), tw.trigger.getJobGroup());
+                    if ((trigs == null || trigs.length == 0) && !jw.jobDetail.isDurable()) {
+                        removeJob(ctxt, tw.trigger.getJobName(), tw.trigger
+                                .getJobGroup());
+                    }
                 }
             }
         }

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

 import junit.framework.TestCase;
 
 import org.quartz.JobDetail;
+import org.quartz.ObjectAlreadyExistsException;
 import org.quartz.SimpleTrigger;
 import org.quartz.Trigger;
 import org.quartz.jobs.NoOpJob;
                 new Date(trigger.getNextFireTime().getTime()).getTime() + 10000));
     }
 
+    // See: http://jira.opensymphony.com/browse/QUARTZ-606
+    public void testStoreTriggerReplacesTrigger() throws Exception {
+
+        String jobName = "StoreTriggerReplacesTrigger";
+        String jobGroup = "StoreTriggerReplacesTriggerGroup";
+        JobDetail detail = new JobDetail(jobName, jobGroup, NoOpJob.class);
+        fJobStore.storeJob(null, detail, false);
+ 
+        String trName = "StoreTriggerReplacesTrigger";
+        String trGroup = "StoreTriggerReplacesTriggerGroup";
+        Trigger tr = new SimpleTrigger(trName ,trGroup, new Date());
+        tr.setJobGroup(jobGroup);
+        tr.setJobName(jobName);
+        tr.setCalendarName(null);
+ 
+        fJobStore.storeTrigger(null, tr, false);
+        assertEquals(tr,fJobStore.retrieveTrigger(null,trName,trGroup));
+ 
+        try {
+            fJobStore.storeTrigger(null, tr, false);
+            fail("an attempt to store duplicate trigger succeeded");
+        } catch(ObjectAlreadyExistsException oaee) {
+            // expected
+        }
+
+        tr.setCalendarName("QQ");
+        fJobStore.storeTrigger(null, tr, true); //fails here
+        assertEquals(tr, fJobStore.retrieveTrigger(null, trName, trGroup));
+        assertEquals( "StoreJob doesn't replace triggers", "QQ", fJobStore.retrieveTrigger(null, trName, trGroup).getCalendarName());
+    }
+
     public static class SampleSignaler implements SchedulerSignaler {
         int fMisfireCount = 0;
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.