18
18
19
19
import java .util .HashMap ;
20
20
import java .util .Map ;
21
+
21
22
import javax .sql .DataSource ;
22
23
23
24
import org .junit .Test ;
25
+
24
26
import org .quartz .Job ;
25
27
import org .quartz .JobExecutionContext ;
26
28
import org .quartz .JobExecutionException ;
56
58
public class QuartzSupportTests {
57
59
58
60
@ Test
59
- public void testSchedulerFactoryBeanWithApplicationContext () throws Exception {
61
+ public void schedulerFactoryBeanWithApplicationContext () throws Exception {
60
62
TestBean tb = new TestBean ("tb" , 99 );
61
63
StaticApplicationContext ac = new StaticApplicationContext ();
62
64
@@ -92,13 +94,14 @@ protected Scheduler createScheduler(SchedulerFactory schedulerFactory, String sc
92
94
}
93
95
94
96
@ Test
95
- public void testSchedulerWithTaskExecutor () throws Exception {
97
+ public void schedulerWithTaskExecutor () throws Exception {
96
98
Assume .group (TestGroup .PERFORMANCE );
97
99
98
100
CountingTaskExecutor taskExecutor = new CountingTaskExecutor ();
99
101
DummyJob .count = 0 ;
100
102
101
103
JobDetailImpl jobDetail = new JobDetailImpl ();
104
+ jobDetail .setDurability (true );
102
105
jobDetail .setJobClass (DummyJob .class );
103
106
jobDetail .setName ("myJob" );
104
107
@@ -124,44 +127,22 @@ public void testSchedulerWithTaskExecutor() throws Exception {
124
127
bean .destroy ();
125
128
}
126
129
127
- @ Test
128
- public void testSchedulerWithRunnable () throws Exception {
129
- Assume .group (TestGroup .PERFORMANCE );
130
-
131
- DummyRunnable .count = 0 ;
132
-
130
+ @ Test (expected = IllegalArgumentException .class )
131
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
132
+ public void jobDetailWithRunnableInsteadOfJob () {
133
133
JobDetailImpl jobDetail = new JobDetailImpl ();
134
134
jobDetail .setJobClass ((Class ) DummyRunnable .class );
135
- jobDetail .setName ("myJob" );
136
-
137
- SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean ();
138
- trigger .setName ("myTrigger" );
139
- trigger .setJobDetail (jobDetail );
140
- trigger .setStartDelay (1 );
141
- trigger .setRepeatInterval (500 );
142
- trigger .setRepeatCount (1 );
143
- trigger .afterPropertiesSet ();
144
-
145
- SchedulerFactoryBean bean = new SchedulerFactoryBean ();
146
- bean .setTriggers (trigger .getObject ());
147
- bean .setJobDetails (jobDetail );
148
- bean .afterPropertiesSet ();
149
- bean .start ();
150
-
151
- Thread .sleep (500 );
152
- assertTrue (DummyRunnable .count > 0 );
153
-
154
- bean .destroy ();
155
135
}
156
136
157
137
@ Test
158
- public void testSchedulerWithQuartzJobBean () throws Exception {
138
+ public void schedulerWithQuartzJobBean () throws Exception {
159
139
Assume .group (TestGroup .PERFORMANCE );
160
140
161
141
DummyJob .param = 0 ;
162
142
DummyJob .count = 0 ;
163
143
164
144
JobDetailImpl jobDetail = new JobDetailImpl ();
145
+ jobDetail .setDurability (true );
165
146
jobDetail .setJobClass (DummyJobBean .class );
166
147
jobDetail .setName ("myJob" );
167
148
jobDetail .getJobDataMap ().put ("param" , "10" );
@@ -188,13 +169,14 @@ public void testSchedulerWithQuartzJobBean() throws Exception {
188
169
}
189
170
190
171
@ Test
191
- public void testSchedulerWithSpringBeanJobFactory () throws Exception {
172
+ public void schedulerWithSpringBeanJobFactory () throws Exception {
192
173
Assume .group (TestGroup .PERFORMANCE );
193
174
194
175
DummyJob .param = 0 ;
195
176
DummyJob .count = 0 ;
196
177
197
178
JobDetailImpl jobDetail = new JobDetailImpl ();
179
+ jobDetail .setDurability (true );
198
180
jobDetail .setJobClass (DummyJob .class );
199
181
jobDetail .setName ("myJob" );
200
182
jobDetail .getJobDataMap ().put ("param" , "10" );
@@ -223,13 +205,14 @@ public void testSchedulerWithSpringBeanJobFactory() throws Exception {
223
205
}
224
206
225
207
@ Test
226
- public void testSchedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored () throws Exception {
208
+ public void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored () throws Exception {
227
209
Assume .group (TestGroup .PERFORMANCE );
228
210
229
211
DummyJob .param = 0 ;
230
212
DummyJob .count = 0 ;
231
213
232
214
JobDetailImpl jobDetail = new JobDetailImpl ();
215
+ jobDetail .setDurability (true );
233
216
jobDetail .setJobClass (DummyJob .class );
234
217
jobDetail .setName ("myJob" );
235
218
jobDetail .getJobDataMap ().put ("para" , "10" );
@@ -259,46 +242,13 @@ public void testSchedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() th
259
242
}
260
243
261
244
@ Test
262
- public void testSchedulerWithSpringBeanJobFactoryAndRunnable () throws Exception {
263
- Assume .group (TestGroup .PERFORMANCE );
264
-
265
- DummyRunnable .param = 0 ;
266
- DummyRunnable .count = 0 ;
267
-
268
- JobDetailImpl jobDetail = new JobDetailImpl ();
269
- jobDetail .setJobClass ((Class ) DummyRunnable .class );
270
- jobDetail .setName ("myJob" );
271
- jobDetail .getJobDataMap ().put ("param" , "10" );
272
-
273
- SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean ();
274
- trigger .setName ("myTrigger" );
275
- trigger .setJobDetail (jobDetail );
276
- trigger .setStartDelay (1 );
277
- trigger .setRepeatInterval (500 );
278
- trigger .setRepeatCount (1 );
279
- trigger .afterPropertiesSet ();
280
-
281
- SchedulerFactoryBean bean = new SchedulerFactoryBean ();
282
- bean .setJobFactory (new SpringBeanJobFactory ());
283
- bean .setTriggers (trigger .getObject ());
284
- bean .setJobDetails (jobDetail );
285
- bean .afterPropertiesSet ();
286
- bean .start ();
287
-
288
- Thread .sleep (500 );
289
- assertEquals (10 , DummyRunnable .param );
290
- assertTrue (DummyRunnable .count > 0 );
291
-
292
- bean .destroy ();
293
- }
294
-
295
- @ Test
296
- public void testSchedulerWithSpringBeanJobFactoryAndQuartzJobBean () throws Exception {
245
+ public void schedulerWithSpringBeanJobFactoryAndQuartzJobBean () throws Exception {
297
246
Assume .group (TestGroup .PERFORMANCE );
298
247
DummyJobBean .param = 0 ;
299
248
DummyJobBean .count = 0 ;
300
249
301
250
JobDetailImpl jobDetail = new JobDetailImpl ();
251
+ jobDetail .setDurability (true );
302
252
jobDetail .setJobClass (DummyJobBean .class );
303
253
jobDetail .setName ("myJob" );
304
254
jobDetail .getJobDataMap ().put ("param" , "10" );
@@ -326,7 +276,7 @@ public void testSchedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Excep
326
276
}
327
277
328
278
@ Test
329
- public void testSchedulerWithSpringBeanJobFactoryAndJobSchedulingData () throws Exception {
279
+ public void schedulerWithSpringBeanJobFactoryAndJobSchedulingData () throws Exception {
330
280
Assume .group (TestGroup .PERFORMANCE );
331
281
DummyJob .param = 0 ;
332
282
DummyJob .count = 0 ;
@@ -348,9 +298,8 @@ public void testSchedulerWithSpringBeanJobFactoryAndJobSchedulingData() throws E
348
298
* Tests the creation of multiple schedulers (SPR-772)
349
299
*/
350
300
@ Test
351
- public void testMultipleSchedulers () throws Exception {
352
- ClassPathXmlApplicationContext ctx =
353
- new ClassPathXmlApplicationContext ("/org/springframework/scheduling/quartz/multipleSchedulers.xml" );
301
+ public void multipleSchedulers () throws Exception {
302
+ ClassPathXmlApplicationContext ctx = context ("multipleSchedulers.xml" );
354
303
try {
355
304
Scheduler scheduler1 = (Scheduler ) ctx .getBean ("scheduler1" );
356
305
Scheduler scheduler2 = (Scheduler ) ctx .getBean ("scheduler2" );
@@ -364,10 +313,9 @@ public void testMultipleSchedulers() throws Exception {
364
313
}
365
314
366
315
@ Test
367
- public void testWithTwoAnonymousMethodInvokingJobDetailFactoryBeans () throws InterruptedException {
316
+ public void twoAnonymousMethodInvokingJobDetailFactoryBeans () throws Exception {
368
317
Assume .group (TestGroup .PERFORMANCE );
369
- ClassPathXmlApplicationContext ctx =
370
- new ClassPathXmlApplicationContext ("/org/springframework/scheduling/quartz/multipleAnonymousMethodInvokingJobDetailFB.xml" );
318
+ ClassPathXmlApplicationContext ctx = context ("multipleAnonymousMethodInvokingJobDetailFB.xml" );
371
319
Thread .sleep (3000 );
372
320
try {
373
321
QuartzTestBean exportService = (QuartzTestBean ) ctx .getBean ("exportService" );
@@ -384,10 +332,9 @@ public void testWithTwoAnonymousMethodInvokingJobDetailFactoryBeans() throws Int
384
332
}
385
333
386
334
@ Test
387
- public void testSchedulerAccessorBean () throws InterruptedException {
335
+ public void schedulerAccessorBean () throws Exception {
388
336
Assume .group (TestGroup .PERFORMANCE );
389
- ClassPathXmlApplicationContext ctx =
390
- new ClassPathXmlApplicationContext ("/org/springframework/scheduling/quartz/schedulerAccessorBean.xml" );
337
+ ClassPathXmlApplicationContext ctx = context ("schedulerAccessorBean.xml" );
391
338
Thread .sleep (3000 );
392
339
try {
393
340
QuartzTestBean exportService = (QuartzTestBean ) ctx .getBean ("exportService" );
@@ -405,7 +352,7 @@ public void testSchedulerAccessorBean() throws InterruptedException {
405
352
406
353
@ Test
407
354
@ SuppressWarnings ("resource" )
408
- public void testSchedulerAutoStartsOnContextRefreshedEventByDefault () throws Exception {
355
+ public void schedulerAutoStartsOnContextRefreshedEventByDefault () throws Exception {
409
356
StaticApplicationContext context = new StaticApplicationContext ();
410
357
context .registerBeanDefinition ("scheduler" , new RootBeanDefinition (SchedulerFactoryBean .class ));
411
358
Scheduler bean = context .getBean ("scheduler" , Scheduler .class );
@@ -416,7 +363,7 @@ public void testSchedulerAutoStartsOnContextRefreshedEventByDefault() throws Exc
416
363
417
364
@ Test
418
365
@ SuppressWarnings ("resource" )
419
- public void testSchedulerAutoStartupFalse () throws Exception {
366
+ public void schedulerAutoStartupFalse () throws Exception {
420
367
StaticApplicationContext context = new StaticApplicationContext ();
421
368
BeanDefinition beanDefinition = BeanDefinitionBuilder .genericBeanDefinition (
422
369
SchedulerFactoryBean .class ).addPropertyValue ("autoStartup" , false ).getBeanDefinition ();
@@ -428,35 +375,38 @@ public void testSchedulerAutoStartupFalse() throws Exception {
428
375
}
429
376
430
377
@ Test
431
- public void testSchedulerRepositoryExposure () throws InterruptedException {
432
- ClassPathXmlApplicationContext ctx =
433
- new ClassPathXmlApplicationContext ("/org/springframework/scheduling/quartz/schedulerRepositoryExposure.xml" );
378
+ public void schedulerRepositoryExposure () throws Exception {
379
+ ClassPathXmlApplicationContext ctx = context ("schedulerRepositoryExposure.xml" );
434
380
assertSame (SchedulerRepository .getInstance ().lookup ("myScheduler" ), ctx .getBean ("scheduler" ));
435
381
ctx .close ();
436
382
}
437
383
438
- // SPR-6038: detect HSQL and stop illegal locks being taken
384
+ /**
385
+ * SPR-6038: detect HSQL and stop illegal locks being taken.
386
+ */
439
387
@ Test
440
- public void testSchedulerWithHsqlDataSource () throws Exception {
388
+ public void schedulerWithHsqlDataSource () throws Exception {
441
389
Assume .group (TestGroup .PERFORMANCE );
442
390
443
391
DummyJob .param = 0 ;
444
392
DummyJob .count = 0 ;
445
393
446
- ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext (
447
- "/org/springframework/scheduling/quartz/databasePersistence.xml" );
394
+ ClassPathXmlApplicationContext ctx = context ("databasePersistence.xml" );
448
395
JdbcTemplate jdbcTemplate = new JdbcTemplate (ctx .getBean (DataSource .class ));
449
396
assertTrue ("No triggers were persisted" , jdbcTemplate .queryForList ("SELECT * FROM qrtz_triggers" ).size ()>0 );
450
397
Thread .sleep (3000 );
451
398
try {
452
- // assertEquals(10, DummyJob.param);
453
399
assertTrue (DummyJob .count > 0 );
454
400
}
455
401
finally {
456
402
ctx .close ();
457
403
}
458
404
}
459
405
406
+ private ClassPathXmlApplicationContext context (String path ) {
407
+ return new ClassPathXmlApplicationContext (path , getClass ());
408
+ }
409
+
460
410
461
411
public static class CountingTaskExecutor implements TaskExecutor {
462
412
@@ -512,20 +462,9 @@ protected synchronized void executeInternal(JobExecutionContext jobExecutionCont
512
462
513
463
public static class DummyRunnable implements Runnable {
514
464
515
- private static int param ;
516
-
517
- private static int count ;
518
-
519
- public void setParam (int value ) {
520
- if (param > 0 ) {
521
- throw new IllegalStateException ("Param already set" );
522
- }
523
- param = value ;
524
- }
525
-
526
465
@ Override
527
466
public void run () {
528
- count ++;
467
+ /* no-op */
529
468
}
530
469
}
531
470
0 commit comments