Skip to content

Commit 716aa69

Browse files
committed
fixed scheduling tests
1 parent 0d70e08 commit 716aa69

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

org.springframework.context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
import org.springframework.util.ReflectionUtils;
2424

2525
/**
26-
* Variation of {@link MethodInvokingRunnable} meant to be used for processing
26+
* Variant of {@link MethodInvokingRunnable} meant to be used for processing
2727
* of no-arg scheduled methods. Propagates user exceptions to the caller,
2828
* assuming that an error strategy for Runnables is in place.
2929
*
3030
* @author Juergen Hoeller
3131
* @since 3.0.6
32+
* @see org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor
3233
*/
3334
public class ScheduledMethodRunnable implements Runnable {
3435

@@ -59,6 +60,7 @@ public Method getMethod() {
5960

6061
public void run() {
6162
try {
63+
ReflectionUtils.makeAccessible(this.method);
6264
this.method.invoke(this.target);
6365
}
6466
catch (InvocationTargetException ex) {

org.springframework.context/src/test/java/org/springframework/scheduling/annotation/taskNamespaceTests.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@
1111
<context:load-time-weaver aspectj-weaving="on"/>
1212
-->
1313

14-
<task:annotation-driven executor="executor"/>
14+
<task:annotation-driven executor="executor" scheduler="scheduler"/>
15+
16+
<task:scheduled-tasks scheduler="scheduler">
17+
<task:scheduled ref="target" method="test" fixed-rate="1000"/>
18+
</task:scheduled-tasks>
1519

1620
<bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
1721
<property name="threadNamePrefix" value="testExecutor"/>
1822
</bean>
1923

24+
<bean id="scheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
25+
<property name="threadNamePrefix" value="testScheduler"/>
26+
</bean>
27+
2028
<bean id="target" class="org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessorTests$TestBean"/>
2129

2230
</beans>

org.springframework.context/src/test/java/org/springframework/scheduling/config/ScheduledTasksBeanDefinitionParserTests.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,19 +16,18 @@
1616

1717
package org.springframework.scheduling.config;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
21-
19+
import java.lang.reflect.Method;
2220
import java.util.Collection;
2321
import java.util.Map;
2422

23+
import static org.junit.Assert.*;
2524
import org.junit.Before;
2625
import org.junit.Test;
2726

2827
import org.springframework.beans.DirectFieldAccessor;
2928
import org.springframework.context.ApplicationContext;
3029
import org.springframework.context.support.ClassPathXmlApplicationContext;
31-
import org.springframework.scheduling.support.MethodInvokingRunnable;
30+
import org.springframework.scheduling.support.ScheduledMethodRunnable;
3231

3332
/**
3433
* @author Mark Fisher
@@ -64,11 +63,11 @@ public void checkTarget() {
6463
Map<Runnable, Long> tasks = (Map<Runnable, Long>) new DirectFieldAccessor(
6564
this.registrar).getPropertyValue("fixedRateTasks");
6665
Runnable runnable = tasks.keySet().iterator().next();
67-
assertEquals(MethodInvokingRunnable.class, runnable.getClass());
68-
Object targetObject = ((MethodInvokingRunnable) runnable).getTargetObject();
69-
String targetMethod = ((MethodInvokingRunnable) runnable).getTargetMethod();
66+
assertEquals(ScheduledMethodRunnable.class, runnable.getClass());
67+
Object targetObject = ((ScheduledMethodRunnable) runnable).getTarget();
68+
Method targetMethod = ((ScheduledMethodRunnable) runnable).getMethod();
7069
assertEquals(this.testBean, targetObject);
71-
assertEquals("test", targetMethod);
70+
assertEquals("test", targetMethod.getName());
7271
}
7372

7473
@Test

0 commit comments

Comments
 (0)