示例#1
0
        public async Task Should_stop_and_complete_with_a_chain_of_command()
        {
            var supervisor = new Supervisor();

            var manager = new Supervisor();

            supervisor.Add(manager);

            var provocateur = new Agent();

            manager.Add(provocateur);

            manager.SetReady();
            supervisor.SetReady();
            provocateur.SetReady();

            Console.WriteLine("Waiting for Ready...");

            await supervisor.Ready.UntilCompletedOrTimeout(TimeSpan.FromSeconds(5));

            Console.WriteLine("Stopping");

            await supervisor.Stop();

            Console.WriteLine("Waiting for Completed...");

            await supervisor.Completed.UntilCompletedOrTimeout(TimeSpan.FromSeconds(5));
        }
示例#2
0
        Supervisor CreateConsumerSupervisor(SessionContext context, ActiveMqConsumer[] actualConsumers)
        {
            var supervisor = new Supervisor();

            foreach (var consumer in actualConsumers)
            {
                supervisor.Add(consumer);
            }

            _context.AddConsumeAgent(supervisor);

            void HandleException(Exception exception)
            {
                supervisor.Stop(exception.Message);
            }

            context.ConnectionContext.Connection.ExceptionListener += HandleException;

            supervisor.SetReady();

            supervisor.Completed.ContinueWith(task => context.ConnectionContext.Connection.ExceptionListener -= HandleException,
                                              TaskContinuationOptions.ExecuteSynchronously);

            return(supervisor);
        }
        public async Task AddAgentAndStop()
        {
            var supervisor = new Supervisor();

            var provocateur = new Agent();

            provocateur.SetReady();
            supervisor.SetReady();

            supervisor.Add(provocateur);

            await supervisor.Ready;

            await supervisor.Stop();

            await supervisor.Completed;
        }
示例#4
0
        public async Task Should_fault_on_ready_faulted()
        {
            for (int i = 0; i < 50; i++)
            {
                var supervisor = new Supervisor();

                var provocateur = new Agent();
                provocateur.SetNotReady(new IntentionalTestException("So not ready."));
                supervisor.Add(provocateur);

                supervisor.SetReady();

                Assert.That(async() => await supervisor.Ready.OrTimeout(s: 5), Throws.TypeOf <AggregateException>());

                await supervisor.Stop().OrTimeout(s: 5);

                await supervisor.Completed.OrTimeout(s : 5);
            }
        }
示例#5
0
        public async Task Should_fault_on_ready_faulted()
        {
            var supervisor = new Supervisor();

            var provocateur = new Agent();

            provocateur.SetNotReady(new IntentionalTestException("So not ready."));
            supervisor.Add(provocateur);

            supervisor.SetReady();

            Assert.That(async() => await supervisor.Ready.UntilCompletedOrTimeout(TimeSpan.FromSeconds(5)),
                        Throws.TypeOf <AggregateException>());

            Console.WriteLine("Stopping");

            await supervisor.Stop().UntilCompletedOrTimeout(TimeSpan.FromSeconds(5));

            Console.WriteLine("Waiting for Completed...");

            await supervisor.Completed.UntilCompletedOrTimeout(TimeSpan.FromSeconds(5));
        }
示例#6
0
        public async Task Should_stop_and_complete_with_an_agent()
        {
            var supervisor = new Supervisor();

            var provocateur = new Agent();

            provocateur.SetReady();
            supervisor.SetReady();

            supervisor.Add(provocateur);

            Console.WriteLine("Waiting for Ready...");

            await supervisor.Ready.OrTimeout(s : 5);

            Console.WriteLine("Stopping");

            await supervisor.Stop().OrTimeout(s: 5);

            Console.WriteLine("Waiting for Completed...");

            await supervisor.Completed.OrTimeout(s : 5);
        }
示例#7
0
        Supervisor CreateConsumerSupervisor(SessionContext context, ActiveMqBasicConsumer[] actualConsumers)
        {
            Supervisor supervisor = new Supervisor();

            foreach (var consumer in actualConsumers)
            {
                supervisor.Add(consumer);
            }

            Add(supervisor);

            void HandleException(Exception exception)
            {
                supervisor.Stop(exception.Message);
            }

            context.ConnectionContext.Connection.ExceptionListener += HandleException;

            supervisor.SetReady();

            supervisor.Completed.ContinueWith(task => context.ConnectionContext.Connection.ExceptionListener -= HandleException);

            return(supervisor);
        }