AddShutdownHook() 공개 메소드

Add a IRunnable which will be executed on the shutdown of this instance
public AddShutdownHook ( IRunnable hook ) : void
hook IRunnable
리턴 void
        public void STE_should_not_run_cancelled_shutdown_hooks()
        {
            var executor = new SingleThreadEventExecutor("Foo" + ThreadLocalRandom.Current.Next(),
                TimeSpan.FromMilliseconds(100));

            var hook = new MyHook();
            executor.AddShutdownHook(hook);
            executor.RemoveShutdownHook(hook);
            executor.GracefulShutdownAsync().Wait();
            Assert.False(hook.WasExecuted);
        }
        public void STE_should_run_shutdown_hooks()
        {
            var executor = new SingleThreadEventExecutor("Foo" + ThreadLocalRandom.Current.Next(),
                TimeSpan.FromMilliseconds(100));

            var hook = new MyHook();
            executor.AddShutdownHook(hook);

            // added a sanity check here to make sure that normal scheduled operations can run
            Func<bool> myFunc = () => true;
            var task = executor.SubmitAsync(myFunc);
            Assert.True(task.Wait(200), "Should have completed task in under 200 milliseconds");
            Assert.True(task.Result);
            // end sanity check, begin actual test

            executor.GracefulShutdownAsync().Wait();
            Assert.True(hook.WasExecuted);
        }