Esempio n. 1
0
        public async Task ReconfigureNull_Should_WaitForBusyRouters()
        {
            var stage1Event = new ManualResetEventSlim();
            var stage2Event = new ManualResetEventSlim();
            var router1     = new TestRouter <TestRoutable>
            {
                ForwardCallback = (_routables) =>
                {
                    stage1Event.Set();
                    Thread.Sleep(TimeSpan.FromMilliseconds(1000));
                    stage2Event.Set();
                }
            };
            var hubConfiguration = new HubConfiguration <TestRoutable>(
                new IRouter <TestRoutable>[] { router1 },
                new IRoutablePreprocessor <TestRoutable> [0],
                MaximumRoutablesQueueLengthDefault,
                MaximumRoutablesForwardingCountDefault,
                WaitForMoreRoutablesForwardingDelayDefault);

            var hub = await this.runHub(hubConfiguration);

            var routable1 = new TestRoutable();

            hub.Forward(routable1.AsEnumerable());

            stage1Event.Wait();
            Assert.Throws <OperationCanceledException>(() =>
            {
                hub.ReconfigureAsync(null, new CancellationTokenSource(TimeSpan.FromMilliseconds(500)).Token).GetAwaiter().GetResult();
            });
            stage2Event.Wait();
            await hub.ReconfigureAsync(null, new CancellationTokenSource(TimeSpan.FromMilliseconds(1000)).Token);
        }
Esempio n. 2
0
        public async Task ForwardToMultipleRouters_Should_IgnoreExceptionInRouters()
        {
            var router1 = new TestRouter <TestRoutable>
            {
                ForwardCallback = (_routables) => { throw new InvalidOperationException(); }
            };
            var routed2 = new ManualResetEventSlim(false);
            var router2 = new TestRouter <TestRoutable>
            {
                ForwardCallback = (_routables) => { routed2.Set(); }
            };
            var hubConfiguration = new HubConfiguration <TestRoutable>(
                new IRouter <TestRoutable>[] { router1, router2 },
                new IRoutablePreprocessor <TestRoutable> [0],
                MaximumRoutablesQueueLengthDefault,
                MaximumRoutablesForwardingCountDefault,
                WaitForMoreRoutablesForwardingDelayDefault);

            var hub = await this.runHub(hubConfiguration);

            var routable1 = new TestRoutable();

            hub.Forward(routable1.AsEnumerable());
            routed2.Wait(TimeSpan.FromMilliseconds(500)).Should().BeTrue();
        }
Esempio n. 3
0
        public async Task Reconfigure_Should_StartRouting()
        {
            this.prepare(out var router, out var hubConfiguration);
            var hub = await this.runHub(hubConfiguration);

            var routed = new ManualResetEventSlim(false);

            router.ForwardCallback = (_routable) => { routed.Set(); };
            var routable1 = new TestRoutable();

            hub.Forward(routable1.AsEnumerable());
            routed.Wait(TimeSpan.FromMilliseconds(500)).Should().BeTrue();
        }
Esempio n. 4
0
        public async Task ForwardWhileNotConfigured_Should_DelayEvents()
        {
            var forwarded1Event = new ManualResetEventSlim();
            var forwarded2Event = new ManualResetEventSlim();
            var router1         = new TestRouter <TestRoutable>
            {
                ForwardCallback = (_routables) =>
                {
                    if (forwarded1Event.IsSet)
                    {
                        forwarded2Event.Set();
                    }
                    else
                    {
                        forwarded1Event.Set();
                    }
                }
            };
            var hubConfiguration = new HubConfiguration <TestRoutable>(
                new IRouter <TestRoutable>[] { router1 },
                new IRoutablePreprocessor <TestRoutable> [0],
                MaximumRoutablesQueueLengthDefault,
                MaximumRoutablesForwardingCountDefault,
                WaitForMoreRoutablesForwardingDelayDefault);

            var hub = new Hub <TestRoutable>();

            var routable1 = new TestRoutable();

            hub.Forward(routable1.AsEnumerable());
            forwarded1Event.Wait(TimeSpan.FromMilliseconds(500)).Should().BeFalse();

            await hub.ReconfigureAsync(hubConfiguration, default);

            forwarded1Event.Wait(TimeSpan.FromMilliseconds(500)).Should().BeTrue();

            await hub.ReconfigureAsync(null, default);

            var routable2 = new TestRoutable();

            hub.Forward(routable2.AsEnumerable());
            forwarded2Event.Wait(TimeSpan.FromMilliseconds(500)).Should().BeFalse();

            await hub.ReconfigureAsync(hubConfiguration, default);

            forwarded2Event.Wait(TimeSpan.FromMilliseconds(500)).Should().BeTrue();
        }