コード例 #1
0
        public async Task <ClusterResult> ExecuteAsync(IRequestContext context, Func <IRequestContext, Task <ClusterResult> > next)
        {
            var replicas = clusterProvider.GetCluster();

            if (replicas == null || replicas.Count == 0)
            {
                LogReplicasNotFound(context);
                return(ClusterResult.ReplicasNotFound(context.Request));
            }

            var contextImpl      = (RequestContext)context;
            var contextualSender = new ContextualRequestSender(requestSender, contextImpl);

            var maxReplicasToUse = context.MaximumReplicasToUse;
            var orderedReplicas  = replicaOrdering.Order(replicas, storageProvider, contextImpl.Request, contextImpl.Parameters);
            var limitedReplicas  = orderedReplicas.Take(maxReplicasToUse);

            await contextImpl.Parameters.Strategy.SendAsync(
                contextImpl.Request,
                contextImpl.Parameters,
                contextualSender,
                contextImpl.Budget,
                limitedReplicas,
                Math.Min(replicas.Count, maxReplicasToUse),
                context.CancellationToken)
            .ConfigureAwait(false);

            context.CancellationToken.ThrowIfCancellationRequested();

            var replicaResults = contextImpl.FreezeReplicaResults();

            var selectedResponse = responseSelector.Select(contextImpl.Request, context.Parameters, replicaResults);

            var resultStatus = resultStatusSelector.Select(replicaResults, contextImpl.Budget);

            return(new ClusterResult(resultStatus, replicaResults, selectedResponse, context.Request));
        }
コード例 #2
0
        public void Should_return_result_with_status_given_by_result_status_selector(ClusterResultStatus status)
        {
            resultStatusSelector.Select(null, null).ReturnsForAnyArgs(status);

            Execute().Status.Should().Be(status);
        }