Ejemplo n.º 1
0
        public void TestTakeTaskAlwaysHasTask()
        {
            // for https://github.com/netty/netty/issues/1614
            var executor = new DefaultTestExecutor(true);

            //add scheduled task
            TestRunnable t = new TestRunnable();
            var          f = executor.Schedule(t, TimeSpan.FromMilliseconds(1500));

            AtomicBoolean stop = new AtomicBoolean(false);

            //ensure always has at least one task in taskQueue
            //check if scheduled tasks are triggered
            try
            {
                Task.Run(() =>
                {
                    while (!stop.Value)
                    {
                        executor.Execute(NoopRunnable.Instance);
                    }
                    executor.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero);
                });
                f.Completion.GetAwaiter().GetResult();

                Assert.True(t.Ran.Value);
            }
            finally
            {
                stop.Value = true;
            }
        }
Ejemplo n.º 2
0
        public void TestTakeTask()
        {
            var executor = new DefaultTestExecutor(true);

            //add task
            TestRunnable beforeTask = new TestRunnable();

            executor.Execute(beforeTask);

            //add scheduled task
            TestRunnable scheduledTask = new TestRunnable();
            var          f             = executor.Schedule(scheduledTask, TimeSpan.FromMilliseconds(1500));

            //add task
            TestRunnable afterTask = new TestRunnable();

            executor.Execute(afterTask);

            f.Completion.GetAwaiter().GetResult();

            Assert.True(beforeTask.Ran.Value);
            Assert.True(scheduledTask.Ran.Value);
            Assert.True(afterTask.Ran.Value);

            executor.ShutdownGracefullyAsync(TimeSpan.Zero, TimeSpan.Zero);
        }