Пример #1
0
        public static RequestThrottlingMiddleware CreateTestMiddleware(int?maxConcurrentRequests, int requestQueueLimit = 5000, RequestDelegate onRejected = null, RequestDelegate next = null)
        {
            var options = new RequestThrottlingOptions
            {
                MaxConcurrentRequests = maxConcurrentRequests,
                RequestQueueLimit     = requestQueueLimit
            };

            return(BuildFromOptions(options, onRejected, next));
        }
Пример #2
0
        public static RequestThrottlingMiddleware CreateBlockingTestMiddleware(int requestQueueLimit = 5000, RequestDelegate onRejected = null, RequestDelegate next = null)
        {
            var options = new RequestThrottlingOptions
            {
                MaxConcurrentRequests = 999,
                RequestQueueLimit     = requestQueueLimit,
                ServerAlwaysBlocks    = true
            };

            return(BuildFromOptions(options, onRejected, next));
        }
Пример #3
0
        private static RequestThrottlingMiddleware BuildFromOptions(RequestThrottlingOptions options, RequestDelegate onRejected, RequestDelegate next)
        {
            if (onRejected != null)
            {
                options.OnRejected = onRejected;
            }

            return(new RequestThrottlingMiddleware(
                       next: next ?? (context => Task.CompletedTask),
                       loggerFactory: NullLoggerFactory.Instance,
                       options: Options.Create(options)
                       ));
        }
Пример #4
0
        public static RequestThrottlingMiddleware CreateTestMiddleWare(int?maxConcurrentRequests, RequestDelegate next = null)
        {
            var options = new RequestThrottlingOptions
            {
                MaxConcurrentRequests = maxConcurrentRequests
            };

            return(new RequestThrottlingMiddleware(
                       next: next ?? (context => Task.CompletedTask),
                       loggerFactory: NullLoggerFactory.Instance,
                       options: Options.Create(options)
                       ));
        }
Пример #5
0
        public void GlobalSetup()
        {
            var options = new RequestThrottlingOptions
            {
                MaxConcurrentRequests = MaxConcurrentRequests,
                RequestQueueLimit     = _numRequests
            };

            _middleware = new RequestThrottlingMiddleware(
                next: (RequestDelegate)_incrementAndCheck,
                loggerFactory: NullLoggerFactory.Instance,
                options: Options.Create(options)
                );
        }
Пример #6
0
        public void GlobalSetup()
        {
            _restOfServer = YieldsThreadInternally ? (RequestDelegate)YieldsThread : (RequestDelegate)CompletesImmediately;

            var options = new RequestThrottlingOptions
            {
                MaxConcurrentRequests = 8,
                RequestQueueLimit     = _numRequests
            };

            _middleware = new RequestThrottlingMiddleware(
                next: _restOfServer,
                loggerFactory: NullLoggerFactory.Instance,
                options: Options.Create(options)
                );
        }
Пример #7
0
        public static RequestThrottlingMiddleware CreateTestMiddleware(int?maxConcurrentRequests, int requestQueueLimit = 5000, RequestDelegate onRejected = null, RequestDelegate next = null)
        {
            var options = new RequestThrottlingOptions
            {
                MaxConcurrentRequests = maxConcurrentRequests,
                RequestQueueLimit     = requestQueueLimit
            };

            if (onRejected != null)
            {
                options.OnRejected = onRejected;
            }

            return(new RequestThrottlingMiddleware(
                       next: next ?? (context => Task.CompletedTask),
                       loggerFactory: NullLoggerFactory.Instance,
                       options: Options.Create(options)
                       ));
        }