fixed scheduling tests
This commit is contained in:
parent
0d70e08ac3
commit
716aa6974c
|
|
@ -23,12 +23,13 @@ import java.lang.reflect.UndeclaredThrowableException;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variation of {@link MethodInvokingRunnable} meant to be used for processing
|
* Variant of {@link MethodInvokingRunnable} meant to be used for processing
|
||||||
* of no-arg scheduled methods. Propagates user exceptions to the caller,
|
* of no-arg scheduled methods. Propagates user exceptions to the caller,
|
||||||
* assuming that an error strategy for Runnables is in place.
|
* assuming that an error strategy for Runnables is in place.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 3.0.6
|
* @since 3.0.6
|
||||||
|
* @see org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor
|
||||||
*/
|
*/
|
||||||
public class ScheduledMethodRunnable implements Runnable {
|
public class ScheduledMethodRunnable implements Runnable {
|
||||||
|
|
||||||
|
|
@ -59,6 +60,7 @@ public class ScheduledMethodRunnable implements Runnable {
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
ReflectionUtils.makeAccessible(this.method);
|
||||||
this.method.invoke(this.target);
|
this.method.invoke(this.target);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException ex) {
|
catch (InvocationTargetException ex) {
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,20 @@
|
||||||
<context:load-time-weaver aspectj-weaving="on"/>
|
<context:load-time-weaver aspectj-weaving="on"/>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<task:annotation-driven executor="executor"/>
|
<task:annotation-driven executor="executor" scheduler="scheduler"/>
|
||||||
|
|
||||||
|
<task:scheduled-tasks scheduler="scheduler">
|
||||||
|
<task:scheduled ref="target" method="test" fixed-rate="1000"/>
|
||||||
|
</task:scheduled-tasks>
|
||||||
|
|
||||||
<bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
|
<bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
|
||||||
<property name="threadNamePrefix" value="testExecutor"/>
|
<property name="threadNamePrefix" value="testExecutor"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="scheduler" class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
|
||||||
|
<property name="threadNamePrefix" value="testScheduler"/>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<bean id="target" class="org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessorTests$TestBean"/>
|
<bean id="target" class="org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessorTests$TestBean"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,19 +16,18 @@
|
||||||
|
|
||||||
package org.springframework.scheduling.config;
|
package org.springframework.scheduling.config;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import java.lang.reflect.Method;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.scheduling.support.MethodInvokingRunnable;
|
import org.springframework.scheduling.support.ScheduledMethodRunnable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
|
|
@ -64,11 +63,11 @@ public class ScheduledTasksBeanDefinitionParserTests {
|
||||||
Map<Runnable, Long> tasks = (Map<Runnable, Long>) new DirectFieldAccessor(
|
Map<Runnable, Long> tasks = (Map<Runnable, Long>) new DirectFieldAccessor(
|
||||||
this.registrar).getPropertyValue("fixedRateTasks");
|
this.registrar).getPropertyValue("fixedRateTasks");
|
||||||
Runnable runnable = tasks.keySet().iterator().next();
|
Runnable runnable = tasks.keySet().iterator().next();
|
||||||
assertEquals(MethodInvokingRunnable.class, runnable.getClass());
|
assertEquals(ScheduledMethodRunnable.class, runnable.getClass());
|
||||||
Object targetObject = ((MethodInvokingRunnable) runnable).getTargetObject();
|
Object targetObject = ((ScheduledMethodRunnable) runnable).getTarget();
|
||||||
String targetMethod = ((MethodInvokingRunnable) runnable).getTargetMethod();
|
Method targetMethod = ((ScheduledMethodRunnable) runnable).getMethod();
|
||||||
assertEquals(this.testBean, targetObject);
|
assertEquals(this.testBean, targetObject);
|
||||||
assertEquals("test", targetMethod);
|
assertEquals("test", targetMethod.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue