public async Task RefreshThenStopAndRestartWithMixedBeans() { var startedBeans = new ConcurrentQueue <ILifecycle>(); var simpleBean1 = TestLifecycleBean.ForStartupTests(startedBeans); var simpleBean2 = TestLifecycleBean.ForStartupTests(startedBeans); var smartBean1 = TestSmartLifecycleBean.ForStartupTests(5, startedBeans); var smartBean2 = TestSmartLifecycleBean.ForStartupTests(-3, startedBeans); var processor = new DefaultLifecycleProcessor(CreateApplicationContext(new List <ILifecycle>() { simpleBean1, simpleBean2, smartBean1, smartBean2 }, new List <ISmartLifecycle>())); Assert.False(simpleBean1.IsRunning); Assert.False(simpleBean2.IsRunning); Assert.False(smartBean1.IsRunning); Assert.False(smartBean2.IsRunning); await processor.OnRefresh(); Assert.False(simpleBean1.IsRunning); Assert.False(simpleBean2.IsRunning); Assert.True(smartBean1.IsRunning); Assert.True(smartBean2.IsRunning); Assert.Equal(2, startedBeans.Count); var started = startedBeans.ToArray(); Assert.Equal(-3, GetPhase(started[0])); Assert.Equal(5, GetPhase(started[1])); await processor.Stop(); Assert.False(simpleBean1.IsRunning); Assert.False(simpleBean2.IsRunning); Assert.False(smartBean1.IsRunning); Assert.False(smartBean2.IsRunning); await processor.Start(); Assert.True(simpleBean1.IsRunning); Assert.True(simpleBean2.IsRunning); Assert.True(smartBean1.IsRunning); Assert.True(smartBean2.IsRunning); Assert.Equal(6, startedBeans.Count); started = startedBeans.ToArray(); Assert.Equal(-3, GetPhase(started[2])); Assert.Equal(0, GetPhase(started[3])); Assert.Equal(0, GetPhase(started[4])); Assert.Equal(5, GetPhase(started[5])); }
public async Task SingleSmartLifecycleAutoStartup() { var startedBeans = new ConcurrentQueue <ILifecycle>(); var bean = TestSmartLifecycleBean.ForStartupTests(1, startedBeans); bean.IsAutoStartup = true; var processor = new DefaultLifecycleProcessor(CreateApplicationContext(new List <ILifecycle>() { bean }, new List <ISmartLifecycle>())); Assert.False(bean.IsRunning); await processor.OnRefresh(); Assert.True(bean.IsRunning); await processor.Stop(); Assert.False(bean.IsRunning); Assert.Single(startedBeans); }
public async Task SingleSmartLifecycleWithoutAutoStartup() { var startedBeans = new ConcurrentQueue <ILifecycle>(); var bean = TestSmartLifecycleBean.ForStartupTests(1, startedBeans); bean.IsAutoStartup = false; var processor = new DefaultLifecycleProcessor(new List <ILifecycle>() { bean }); Assert.False(bean.IsRunning); await processor.OnRefresh(); Assert.False(bean.IsRunning); Assert.Empty(startedBeans); await processor.Start(); Assert.True(bean.IsRunning); Assert.Single(startedBeans); await processor.Stop(); }
public async Task SmartLifecycleGroupStartup() { var startedBeans = new ConcurrentQueue <ILifecycle>(); var beanMin = TestSmartLifecycleBean.ForStartupTests(int.MinValue, startedBeans); var bean1 = TestSmartLifecycleBean.ForStartupTests(1, startedBeans); var bean2 = TestSmartLifecycleBean.ForStartupTests(2, startedBeans); var bean3 = TestSmartLifecycleBean.ForStartupTests(3, startedBeans); var beanMax = TestSmartLifecycleBean.ForStartupTests(int.MaxValue, startedBeans); var processor = new DefaultLifecycleProcessor(CreateApplicationContext(new List <ILifecycle>() { bean3, beanMin, bean2, beanMax, bean1 }, new List <ISmartLifecycle>())); Assert.False(beanMin.IsRunning); Assert.False(bean1.IsRunning); Assert.False(bean2.IsRunning); Assert.False(bean3.IsRunning); Assert.False(beanMax.IsRunning); await processor.OnRefresh(); Assert.True(beanMin.IsRunning); Assert.True(bean1.IsRunning); Assert.True(bean2.IsRunning); Assert.True(bean3.IsRunning); Assert.True(beanMax.IsRunning); await processor.Stop(); Assert.Equal(5, startedBeans.Count); var started = startedBeans.ToArray(); Assert.Equal(int.MinValue, GetPhase(started[0])); Assert.Equal(1, GetPhase(started[1])); Assert.Equal(2, GetPhase(started[2])); Assert.Equal(3, GetPhase(started[3])); Assert.Equal(int.MaxValue, GetPhase(started[4])); }