public async Task SmartLifecycleGroupShutdown() { var stoppedBeans = new ConcurrentQueue <ILifecycle>(); var bean1 = TestSmartLifecycleBean.ForShutdownTests(1, 300, stoppedBeans); var bean2 = TestSmartLifecycleBean.ForShutdownTests(3, 100, stoppedBeans); var bean3 = TestSmartLifecycleBean.ForShutdownTests(1, 600, stoppedBeans); var bean4 = TestSmartLifecycleBean.ForShutdownTests(2, 400, stoppedBeans); var bean5 = TestSmartLifecycleBean.ForShutdownTests(2, 700, stoppedBeans); var bean6 = TestSmartLifecycleBean.ForShutdownTests(int.MaxValue, 200, stoppedBeans); var bean7 = TestSmartLifecycleBean.ForShutdownTests(3, 200, stoppedBeans); var processor = new DefaultLifecycleProcessor(CreateApplicationContext(new List <ILifecycle>() { bean1, bean2, bean3, bean4, bean5, bean6, bean7 }, new List <ISmartLifecycle>())); await processor.OnRefresh(); await processor.Stop(); var stopped = stoppedBeans.ToArray(); Assert.Equal(int.MaxValue, GetPhase(stopped[0])); Assert.Equal(3, GetPhase(stopped[1])); Assert.Equal(3, GetPhase(stopped[2])); Assert.Equal(2, GetPhase(stopped[3])); Assert.Equal(2, GetPhase(stopped[4])); Assert.Equal(1, GetPhase(stopped[5])); Assert.Equal(1, GetPhase(stopped[6])); }
public async Task MixedShutdown() { var stoppedBeans = new ConcurrentQueue <ILifecycle>(); ILifecycle bean1 = TestLifecycleBean.ForShutdownTests(stoppedBeans); ILifecycle bean2 = TestSmartLifecycleBean.ForShutdownTests(500, 200, stoppedBeans); ILifecycle bean3 = TestSmartLifecycleBean.ForShutdownTests(int.MaxValue, 100, stoppedBeans); ILifecycle bean4 = TestLifecycleBean.ForShutdownTests(stoppedBeans); ILifecycle bean5 = TestSmartLifecycleBean.ForShutdownTests(1, 200, stoppedBeans); ILifecycle bean6 = TestSmartLifecycleBean.ForShutdownTests(-1, 100, stoppedBeans); ILifecycle bean7 = TestSmartLifecycleBean.ForShutdownTests(int.MinValue, 300, stoppedBeans); var processor = new DefaultLifecycleProcessor(CreateApplicationContext(new List <ILifecycle>() { bean1, bean2, bean3, bean4, bean5, bean6, bean7 }, new List <ISmartLifecycle>())); await processor.OnRefresh(); Assert.True(bean2.IsRunning); Assert.True(bean3.IsRunning); Assert.True(bean5.IsRunning); Assert.True(bean6.IsRunning); Assert.True(bean7.IsRunning); Assert.False(bean1.IsRunning); Assert.False(bean4.IsRunning); await bean1.Start(); await bean4.Start(); Assert.True(bean1.IsRunning); Assert.True(bean4.IsRunning); await processor.Stop(); Assert.False(bean2.IsRunning); Assert.False(bean3.IsRunning); Assert.False(bean5.IsRunning); Assert.False(bean6.IsRunning); Assert.False(bean7.IsRunning); Assert.False(bean1.IsRunning); Assert.False(bean4.IsRunning); var stopped = stoppedBeans.ToArray(); Assert.Equal(7, stopped.Length); Assert.Equal(int.MaxValue, GetPhase(stopped[0])); Assert.Equal(500, GetPhase(stopped[1])); Assert.Equal(1, GetPhase(stopped[2])); Assert.Equal(0, GetPhase(stopped[3])); Assert.Equal(0, GetPhase(stopped[4])); Assert.Equal(-1, GetPhase(stopped[5])); Assert.Equal(int.MinValue, GetPhase(stopped[6])); }
public async Task SingleSmartLifecycleShutdown() { var stoppedBeans = new ConcurrentQueue <ILifecycle>(); var bean = TestSmartLifecycleBean.ForShutdownTests(99, 300, stoppedBeans); var processor = new DefaultLifecycleProcessor(CreateApplicationContext(new List <ILifecycle>() { bean }, new List <ISmartLifecycle>())); await processor.OnRefresh(); Assert.True(bean.IsRunning); await processor.Stop(); var stopped = stoppedBeans.ToArray(); Assert.Same(bean, stopped[0]); }