Added tests for the DefaultLifecycleProcessor and a custom "lifecycleProcessor" bean.
This commit is contained in:
parent
1ac7b95c1d
commit
a64f0f1ebe
|
|
@ -55,8 +55,8 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
|||
|
||||
|
||||
/**
|
||||
* Specify the maximum time allotted for the shutdown of any phase
|
||||
* (group of SmartLifecycle beans with the same 'phase' value).
|
||||
* Specify the maximum time allotted in milliseconds for the shutdown of
|
||||
* any phase (group of SmartLifecycle beans with the same 'phase' value).
|
||||
* The default value is 30 seconds.
|
||||
*/
|
||||
public void setTimeoutPerShutdownPhase(long timeoutPerShutdownPhase) {
|
||||
|
|
|
|||
|
|
@ -18,13 +18,19 @@ package org.springframework.context.support;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.context.LifecycleProcessor;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
|
||||
/**
|
||||
|
|
@ -33,6 +39,29 @@ import org.springframework.context.SmartLifecycle;
|
|||
*/
|
||||
public class DefaultLifecycleProcessorTests {
|
||||
|
||||
@Test
|
||||
public void defaultLifecycleProcessorInstance() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
context.refresh();
|
||||
Object lifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor");
|
||||
assertNotNull(lifecycleProcessor);
|
||||
assertEquals(DefaultLifecycleProcessor.class, lifecycleProcessor.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customLifecycleProcessorInstance() {
|
||||
BeanDefinition beanDefinition = new RootBeanDefinition(DefaultLifecycleProcessor.class);
|
||||
beanDefinition.getPropertyValues().addPropertyValue("timeoutPerShutdownPhase", 1000);
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
context.registerBeanDefinition("lifecycleProcessor", beanDefinition);
|
||||
context.refresh();
|
||||
LifecycleProcessor bean = context.getBean("lifecycleProcessor", LifecycleProcessor.class);
|
||||
Object contextLifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor");
|
||||
assertNotNull(contextLifecycleProcessor);
|
||||
assertSame(bean, contextLifecycleProcessor);
|
||||
assertEquals(1000L, new DirectFieldAccessor(contextLifecycleProcessor).getPropertyValue("timeoutPerShutdownPhase"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleSmartLifecycleAutoStartup() throws Exception {
|
||||
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<Lifecycle>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue