1 16 package org.quartz; 17 18 import java.util.Calendar ; 19 20 import junit.framework.TestCase; 21 22 import org.quartz.JobDetail; 23 import org.quartz.JobExecutionContext; 24 import org.quartz.JobExecutionException; 25 import org.quartz.Scheduler; 26 import org.quartz.SimpleTrigger; 27 import org.quartz.StatefulJob; 28 import org.quartz.Trigger; 29 import org.quartz.impl.StdSchedulerFactory; 30 31 34 public class PriorityTest extends TestCase { 35 36 private static StringBuffer result = new StringBuffer (); 37 38 public static class TestJob implements StatefulJob { 39 public void execute(JobExecutionContext context) throws JobExecutionException { 40 result.append(context.getTrigger().getName()); 41 } 42 } 43 44 public void testSameDefaultPriority() throws Exception { 45 result = new StringBuffer (); 46 47 Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); 48 49 Calendar cal = Calendar.getInstance(); 50 cal.add(Calendar.SECOND, 1); 51 52 Trigger trig1 = new SimpleTrigger("T1", null, cal.getTime()); 53 Trigger trig2 = new SimpleTrigger("T2", null, cal.getTime()); 54 55 JobDetail jobDetail = new JobDetail("JD", null, TestJob.class); 56 57 sched.scheduleJob(jobDetail, trig1); 58 59 trig2.setJobName(jobDetail.getName()); 60 sched.scheduleJob(trig2); 61 62 sched.start(); 63 64 Thread.sleep(2000); 65 66 assertEquals("T1T2", result.toString()); 67 68 sched.shutdown(); 69 } 70 71 public void testDifferentPriority() throws Exception { 72 result = new StringBuffer (); 73 74 Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); 75 76 Calendar cal = Calendar.getInstance(); 77 cal.add(Calendar.SECOND, 1); 78 79 Trigger trig1 = new SimpleTrigger("T1", null, cal.getTime()); 80 trig1.setPriority(5); 81 82 Trigger trig2 = new SimpleTrigger("T2", null, cal.getTime()); 83 trig2.setPriority(10); 84 85 JobDetail jobDetail = new JobDetail("JD", null, TestJob.class); 86 87 sched.scheduleJob(jobDetail, trig1); 88 89 trig2.setJobName(jobDetail.getName()); 90 sched.scheduleJob(trig2); 91 92 sched.start(); 93 94 Thread.sleep(2000); 95 96 assertEquals("T2T1", result.toString()); 97 98 sched.shutdown(); 99 } 100 } 101 | Popular Tags |