コード例 #1
0
        public void ConstructorMaximumRoutablesForwardingCountZero_ShouldThrow_ArgumentOutOfRangeException()
        {
            var routers       = new IRouter <TestRoutable> [0];
            var preprocessors = new IRoutablePreprocessor <TestRoutable> [0];

            Assert.Throws <ArgumentOutOfRangeException>(() => new HubConfiguration <TestRoutable>(
                                                            routers,
                                                            preprocessors,
                                                            MaximumRoutablesQueueLengthDefault,
                                                            0,
                                                            WaitForMoreRoutablesForwardingDelayDefault));
        }
コード例 #2
0
        public void Constructor_Should_SetProperties()
        {
            var router1       = new TestRouter <TestRoutable>();
            var routers       = new IRouter <TestRoutable>[] { router1 };
            var preprocessor1 = new TestReturnNullPreprocessor();
            var preprocessors = new IRoutablePreprocessor <TestRoutable>[] { preprocessor1 };

            this.prepareConfiguration(routers, preprocessors, out var configuration);
            configuration.Routers.Should().Contain(routers);
            configuration.Preprocessors.Should().Contain(preprocessor1);
            configuration.MaximumRoutablesQueueLength.Should().Be(MaximumRoutablesQueueLengthDefault);
        }
コード例 #3
0
        public void ConstructorWaitForMoreRoutablesForwardingDelayNegative_ShouldThrow_ArgumentOutOfRangeException()
        {
            var routers       = new IRouter <TestRoutable> [0];
            var preprocessors = new IRoutablePreprocessor <TestRoutable> [0];

            Assert.Throws <ArgumentOutOfRangeException>(() => new HubConfiguration <TestRoutable>(
                                                            routers,
                                                            preprocessors,
                                                            MaximumRoutablesQueueLengthDefault,
                                                            MaximumRoutablesForwardingCountDefault,
                                                            TimeSpan.FromMilliseconds(-1)));
        }
コード例 #4
0
        public void ConstructorWaitForMoreRoutablesForwardingDelayZero_Should_Succeed()
        {
            var routers          = new IRouter <TestRoutable> [0];
            var preprocessors    = new IRoutablePreprocessor <TestRoutable> [0];
            var hubConfiguration = new HubConfiguration <TestRoutable>(
                routers,
                preprocessors,
                MaximumRoutablesQueueLengthDefault,
                MaximumRoutablesForwardingCountDefault,
                TimeSpan.Zero);

            hubConfiguration.WaitForMoreRoutablesForwardingDelay.Should().Be(TimeSpan.Zero);
        }
コード例 #5
0
        void prepare(out TestRouter <TestRoutable> router, out HubConfiguration <TestRoutable> hubConfiguration)
        {
            router = new TestRouter <TestRoutable>();
            var routers = new IRouter <TestRoutable>[] { router };

            var preprocessors = new IRoutablePreprocessor <TestRoutable> [0];

            hubConfiguration = new HubConfiguration <TestRoutable>(
                routers,
                preprocessors,
                MaximumRoutablesQueueLengthDefault,
                MaximumRoutablesForwardingCountDefault,
                WaitForMoreRoutablesForwardingDelayDefault);
        }
コード例 #6
0
        public async Task Reconfigure_Should_StoreConfigurationAndSetRunning()
        {
            var routers          = new IRouter <TestRoutable> [0];
            var preprocessors    = new IRoutablePreprocessor <TestRoutable> [0];
            var hubConfiguration = new HubConfiguration <TestRoutable>(
                routers,
                preprocessors,
                MaximumRoutablesQueueLengthDefault,
                MaximumRoutablesForwardingCountDefault,
                WaitForMoreRoutablesForwardingDelayDefault);
            var hub = new Hub <TestRoutable>();

            hub.IsRunning.Should().BeFalse();
            await hub.ReconfigureAsync(hubConfiguration, default);

            hub.Configuration.Should().BeSameAs(hubConfiguration);
            hub.IsRunning.Should().BeTrue();
        }
コード例 #7
0
        public void Constructor_Should_SetProperties()
        {
            var router1       = new TestRouter <LogEvent <StandardLoglevel> >();
            var routers       = new IRouter <LogEvent <StandardLoglevel> >[] { router1 };
            var preprocessor1 = new TestPreprocessor();
            var preprocessors = new IRoutablePreprocessor <LogEvent <StandardLoglevel> >[] { preprocessor1 };

            var logfileConfiguration = new LogfileConfiguration <StandardLoglevel>(
                routers,
                preprocessors,
                1,
                2,
                TimeSpan.FromMilliseconds(3),
                true);

            logfileConfiguration.Routers.Should().Contain(router1);
            logfileConfiguration.Preprocessors.Should().Contain(preprocessor1);
            logfileConfiguration.MaximumRoutablesQueueLength.Should().Be(1);
            logfileConfiguration.MaximumRoutablesForwardingCount.Should().Be(2);
            logfileConfiguration.WaitForMoreRoutablesForwardingDelay.Should().Be(TimeSpan.FromMilliseconds(3));
            logfileConfiguration.IsDeveloperModeEnabled.Should().BeTrue();
        }
コード例 #8
0
        public async Task ForwardWithPreprocessorReturnEmptyListOnRouting_Should_BlockAllEvents()
        {
            var routed1 = new ManualResetEventSlim(false);
            IEnumerable <TestRoutable> routables1 = null;
            var router1 = new TestRouter <TestRoutable>()
            {
                ForwardCallback = (_routables) => { routables1 = _routables; routed1.Set(); }
            };
            var routers          = new IRouter <TestRoutable>[] { router1 };
            var preprocessors    = new IRoutablePreprocessor <TestRoutable>[] { new TestRemoveRoutablePreprocessor(onEnqueueing: false) };
            var hubConfiguration = new HubConfiguration <TestRoutable>(
                routers,
                preprocessors,
                MaximumRoutablesQueueLengthDefault,
                MaximumRoutablesForwardingCountDefault,
                WaitForMoreRoutablesForwardingDelayDefault);
            var hub = new Hub <TestRoutable>();
            await hub.ReconfigureAsync(hubConfiguration, default);

            hub.Forward(new[] { new TestRoutable() });
            routed1.Wait(TimeSpan.FromMilliseconds(500)).Should().BeFalse();
            routables1.Should().BeNull();
        }
コード例 #9
0
 /// <summary>
 /// Adds a preprocessor.
 /// </summary>
 /// <typeparam name="T">The event type.</typeparam>
 /// <param name="self">The configuration builder.</param>
 /// <param name="preprocessor">The preprocessor to add.</param>
 /// <returns>The same configuration builder instance to allow a fluent syntax.</returns>
 public static HubConfigurationBuilder <T> AddPreprocessor <T>(this HubConfigurationBuilder <T> self, IRoutablePreprocessor <T> preprocessor)
     where T : IRoutable
 {
     if (preprocessor == null)
     {
         throw new ArgumentNullException(nameof(preprocessor));
     }
     self.Preprocessors.Add(preprocessor);
     return(self);
 }
コード例 #10
0
 /// <summary>
 /// Adds a preprocessor.
 /// </summary>
 /// <typeparam name="T">The loglevel type.</typeparam>
 /// <param name="self">The configuration builder.</param>
 /// <param name="preprocessor">The preprocessor to add.</param>
 /// <returns>The same configuration builder instance to allow a fluent syntax.</returns>
 /// <exception cref="ArgumentNullException">Thrown if either
 ///		<paramref name="self"/> or <paramref name="preprocessor"/> is null.</exception>
 public static LogfileConfigurationBuilder <TLoglevel> AddPreprocessor <TLoglevel>(this LogfileConfigurationBuilder <TLoglevel> self, IRoutablePreprocessor <LogEvent <TLoglevel> > preprocessor)
     where TLoglevel : Enum
 {
     if (self == null)
     {
         throw new ArgumentNullException(nameof(self));
     }
     if (preprocessor == null)
     {
         throw new ArgumentNullException(nameof(preprocessor));
     }
     self.Preprocessors.Add(preprocessor);
     return(self);
 }
コード例 #11
0
        public void ConstructorRoutersNull_ShouldThrow_ArgumentNullException()
        {
            var preprocessors = new IRoutablePreprocessor <TestRoutable> [0];

            Assert.Throws <ArgumentNullException>(() => this.prepareConfiguration(null, preprocessors, out var _));
        }