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;
|
||||
|
||||
/**
|
||||
* 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,
|
||||
* assuming that an error strategy for Runnables is in place.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0.6
|
||||
* @see org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor
|
||||
*/
|
||||
public class ScheduledMethodRunnable implements Runnable {
|
||||
|
||||
|
|
@ -59,6 +60,7 @@ public class ScheduledMethodRunnable implements Runnable {
|
|||
|
||||
public void run() {
|
||||
try {
|
||||
ReflectionUtils.makeAccessible(this.method);
|
||||
this.method.invoke(this.target);
|
||||
}
|
||||
catch (InvocationTargetException ex) {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,20 @@
|
|||
<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">
|
||||
<property name="threadNamePrefix" value="testExecutor"/>
|
||||
</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"/>
|
||||
|
||||
</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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,19 +16,18 @@
|
|||
|
||||
package org.springframework.scheduling.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.scheduling.support.MethodInvokingRunnable;
|
||||
import org.springframework.scheduling.support.ScheduledMethodRunnable;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
|
@ -64,11 +63,11 @@ public class ScheduledTasksBeanDefinitionParserTests {
|
|||
Map<Runnable, Long> tasks = (Map<Runnable, Long>) new DirectFieldAccessor(
|
||||
this.registrar).getPropertyValue("fixedRateTasks");
|
||||
Runnable runnable = tasks.keySet().iterator().next();
|
||||
assertEquals(MethodInvokingRunnable.class, runnable.getClass());
|
||||
Object targetObject = ((MethodInvokingRunnable) runnable).getTargetObject();
|
||||
String targetMethod = ((MethodInvokingRunnable) runnable).getTargetMethod();
|
||||
assertEquals(ScheduledMethodRunnable.class, runnable.getClass());
|
||||
Object targetObject = ((ScheduledMethodRunnable) runnable).getTarget();
|
||||
Method targetMethod = ((ScheduledMethodRunnable) runnable).getMethod();
|
||||
assertEquals(this.testBean, targetObject);
|
||||
assertEquals("test", targetMethod);
|
||||
assertEquals("test", targetMethod.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue