예제 #1
0
        public async Task Should_call_invoker()
        {
            _invoker.Invoke(_descriptor, _request, _requestGraph.CancellationToken).Returns(_response);

            var result = await _messageHandler.SendAsync(_request, _requestGraph.CancellationToken);

            result.ShouldEqual(_response);
        }
        public async Task Should_call_invoker()
        {
            _invoker.Invoke(_action, _request, _requestGraph.CancellationToken).Returns(_response);

            var result = await _messageHandler.SendAsync(_request, _requestGraph.CancellationToken);

            result.ShouldEqual(_response);

            _metrics.TotalRequests.ShouldEqual(1);
            _metrics.GetAverageRequestTime(_action).ShouldBeGreaterThan(TimeSpan.Zero);
        }
예제 #3
0
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var result = await _behaviorChainInvoker.Invoke(
                    _actionDescriptor, request, cancellationToken);

                stopwatch.Stop();

                if (_configuration.EnableMetrics)
                {
                    _metrics.IncrementRequests();
                    _actionMetrics.AddRequestTime(stopwatch.Elapsed);
                }

                return(result);
            }
            catch (Exception exception)
            {
                if (exception is GraphiteRuntimeInitializationException)
                {
                    throw;
                }
                throw new UnhandledGraphiteRequestException(exception);
            }
        }
예제 #4
0
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage requestMessage, CancellationToken cancellationToken)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                return(await _behaviorChainInvoker.Invoke(
                           _actionDescriptor, requestMessage, cancellationToken));
            }
            catch (BadRequestException exception)
            {
                var response = requestMessage.CreateResponse(HttpStatusCode.BadRequest);
                response.SafeSetReasonPhrase(exception.Message);
                return(response);
            }
            catch (Exception exception)
            {
                if (exception is UnhandledGraphiteException)
                {
                    throw;
                }
                throw new UnhandledGraphiteException(_actionDescriptor,
                                                     _container, exception);
            }
            finally
            {
                stopwatch.Stop();
                if (_configuration.Metrics)
                {
                    _metrics.IncrementRequests();
                    _actionMetrics.AddRequestTime(stopwatch.Elapsed);
                }
            }
        }