Skip to content

Commit a64f0f1

Browse files
committed
Added tests for the DefaultLifecycleProcessor and a custom "lifecycleProcessor" bean.
1 parent 1ac7b95 commit a64f0f1

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

org.springframework.context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
5555

5656

5757
/**
58-
* Specify the maximum time allotted for the shutdown of any phase
59-
* (group of SmartLifecycle beans with the same 'phase' value).
58+
* Specify the maximum time allotted in milliseconds for the shutdown of
59+
* any phase (group of SmartLifecycle beans with the same 'phase' value).
6060
* The default value is 30 seconds.
6161
*/
6262
public void setTimeoutPerShutdownPhase(long timeoutPerShutdownPhase) {

org.springframework.context/src/test/java/org/springframework/context/support/DefaultLifecycleProcessorTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertSame;
2123
import static org.junit.Assert.assertTrue;
2224

2325
import java.util.concurrent.CopyOnWriteArrayList;
2426

2527
import org.junit.Test;
2628

29+
import org.springframework.beans.DirectFieldAccessor;
30+
import org.springframework.beans.factory.config.BeanDefinition;
31+
import org.springframework.beans.factory.support.RootBeanDefinition;
2732
import org.springframework.context.Lifecycle;
33+
import org.springframework.context.LifecycleProcessor;
2834
import org.springframework.context.SmartLifecycle;
2935

3036
/**
@@ -33,6 +39,29 @@
3339
*/
3440
public class DefaultLifecycleProcessorTests {
3541

42+
@Test
43+
public void defaultLifecycleProcessorInstance() {
44+
StaticApplicationContext context = new StaticApplicationContext();
45+
context.refresh();
46+
Object lifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor");
47+
assertNotNull(lifecycleProcessor);
48+
assertEquals(DefaultLifecycleProcessor.class, lifecycleProcessor.getClass());
49+
}
50+
51+
@Test
52+
public void customLifecycleProcessorInstance() {
53+
BeanDefinition beanDefinition = new RootBeanDefinition(DefaultLifecycleProcessor.class);
54+
beanDefinition.getPropertyValues().addPropertyValue("timeoutPerShutdownPhase", 1000);
55+
StaticApplicationContext context = new StaticApplicationContext();
56+
context.registerBeanDefinition("lifecycleProcessor", beanDefinition);
57+
context.refresh();
58+
LifecycleProcessor bean = context.getBean("lifecycleProcessor", LifecycleProcessor.class);
59+
Object contextLifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor");
60+
assertNotNull(contextLifecycleProcessor);
61+
assertSame(bean, contextLifecycleProcessor);
62+
assertEquals(1000L, new DirectFieldAccessor(contextLifecycleProcessor).getPropertyValue("timeoutPerShutdownPhase"));
63+
}
64+
3665
@Test
3766
public void singleSmartLifecycleAutoStartup() throws Exception {
3867
CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<Lifecycle>();

0 commit comments

Comments
 (0)