public RequestExecutionModule(
     IResponseSelector responseSelector,
     IReplicaStorageProvider storageProvider,
     IRequestSenderInternal requestSender,
     IClusterResultStatusSelector resultStatusSelector)
 {
     this.responseSelector     = responseSelector;
     this.storageProvider      = storageProvider;
     this.requestSender        = requestSender;
     this.resultStatusSelector = resultStatusSelector;
 }
        public void TestSetup()
        {
            replica1 = new Uri("http://replica1");
            replica2 = new Uri("http://replica2");

            response1        = new Response(ResponseCode.Ok);
            response2        = new Response(ResponseCode.Ok);
            selectedResponse = new Response(ResponseCode.Ok);

            result1 = new ReplicaResult(replica1, response1, ResponseVerdict.DontKnow, TimeSpan.Zero);
            result2 = new ReplicaResult(replica2, response2, ResponseVerdict.DontKnow, TimeSpan.Zero);

            var parameters = RequestParameters.Empty
                             .WithStrategy(Substitute.For <IRequestStrategy>());

            context = new RequestContext(Request.Get("foo/bar"), parameters, Budget.Infinite, new SilentLog(), null, int.MaxValue);
            context.Parameters.Strategy.SendAsync(null, null, null, null, null, 0, default)
            .ReturnsForAnyArgs(
                async info =>
            {
                var replicas = info.Arg <IEnumerable <Uri> >();
                var sender   = info.Arg <IRequestSender>();

                foreach (var replica in replicas)
                {
                    await sender.SendToReplicaAsync(replica, context.Request, null, TimeSpan.Zero, CancellationToken.None);
                }
            });

            clusterProvider = Substitute.For <IClusterProvider>();
            clusterProvider.GetCluster().Returns(new[] { replica1, replica2 });

            requestSender = Substitute.For <IRequestSenderInternal>();
            requestSender.SendToReplicaAsync(Arg.Any <ITransport>(), replica1, Arg.Any <Request>(), Arg.Any <TimeSpan?>(), Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>()).ReturnsTask(_ => result1);
            requestSender.SendToReplicaAsync(Arg.Any <ITransport>(), replica2, Arg.Any <Request>(), Arg.Any <TimeSpan?>(), Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>()).ReturnsTask(_ => result2);

            replicaOrdering = Substitute.For <IReplicaOrdering>();
            replicaOrdering.Order(null, null, null, null).ReturnsForAnyArgs(info => info.Arg <IList <Uri> >().Reverse());

            responseSelector = Substitute.For <IResponseSelector>();
            responseSelector.Select(null, null, null).ReturnsForAnyArgs(_ => selectedResponse);

            resultStatusSelector = Substitute.For <IClusterResultStatusSelector>();
            resultStatusSelector.Select(null, null).ReturnsForAnyArgs(ClusterResultStatus.Success);

            storageProvider = Substitute.For <IReplicaStorageProvider>();
            module          = new RequestExecutionModule(
                clusterProvider,
                replicaOrdering,
                responseSelector,
                storageProvider,
                requestSender,
                resultStatusSelector);
        }
Beispiel #3
0
        public void TestSetup()
        {
            replica           = new Uri("http://replica");
            request           = Request.Get("foo/bar");
            result            = new ReplicaResult(replica, new Response(ResponseCode.Ok), ResponseVerdict.Accept, 1.Milliseconds());
            timeout           = 1.Minutes();
            connectionTimeout = 1.Seconds();

            resultSource = new TaskCompletionSource <ReplicaResult>();

            baseSender = Substitute.For <IRequestSenderInternal>();
            baseSender.SendToReplicaAsync(
                transport: default,
        public void TestSetup()
        {
            replica           = new Uri("http://replica");
            request           = Request.Get("foo/bar");
            result            = new ReplicaResult(replica, new Response(ResponseCode.Ok), ResponseVerdict.Accept, 1.Milliseconds());
            timeout           = 1.Minutes();
            connectionTimeout = 1.Seconds();

            resultSource = new TaskCompletionSource <ReplicaResult>();

            baseSender = Substitute.For <IRequestSenderInternal>();
            baseSender.SendToReplicaAsync(null, null, null, null, TimeSpan.Zero, CancellationToken.None).ReturnsForAnyArgs(_ => resultSource.Task);

            context          = new RequestContext(request, new RequestParameters(Strategy.SingleReplica), Budget.WithRemaining(timeout), new ConsoleLog(), Substitute.For <ITransport>(), int.MaxValue, null, CancellationToken.None);
            contextualSender = new ContextualRequestSender(baseSender, context);
        }
 public ContextualRequestSender(IRequestSenderInternal sender, RequestContext context)
 {
     this.sender  = sender;
     this.context = context;
 }