public void Should_cancel_remaining_requests_when_receiving_accepted_result()
        {
            DropSynchronizationContext();

            var tokens = new List <CancellationToken>();

            sender
            .When(s => s.SendToReplicaAsync(Arg.Any <Uri>(), Arg.Any <Request>(), Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>()))
            .Do(info => tokens.Add(info.Arg <CancellationToken>()));

            strategy = new ParallelRequestStrategy(int.MaxValue);

            var sendTask = strategy.SendAsync(request, sender, Budget.WithRemaining(5.Seconds()), replicas, replicas.Length, token);

            CompleteRequest(replicas.Last(), ResponseVerdict.Accept);

            sendTask.GetAwaiter().GetResult();

            tokens.Should().HaveCount(replicas.Length);

            foreach (var t in tokens)
            {
                t.IsCancellationRequested.Should().BeTrue();
            }
        }
コード例 #2
0
        public void Should_fire_initial_requests_to_all_replicas_if_parallelism_level_is_greater_than_replicas_count()
        {
            strategy = new ParallelRequestStrategy(int.MaxValue);

            strategy.SendAsync(request, parameters, sender, Budget.WithRemaining(5.Seconds()), replicas, replicas.Length, token);

            sender.ReceivedCalls().Should().HaveCount(replicas.Length);

            foreach (var replica in replicas)
            {
                sender.Received(1).SendToReplicaAsync(replica, request, Arg.Any <TimeSpan?>(), Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>());
            }
        }
コード例 #3
0
 public SimpleClusterClient(Uri[] addressList, TimeSpan?timeout = null, ILog log = null)
 {
     replicasCount = addressList.Length;
     globalTimeout = timeout ?? TimeSpan.FromSeconds(15);
     clusterClient = new ClusterClient(log, config =>
     {
         config.ClusterProvider = new ConstantTopologyClusterProvider(addressList);
         config.SetupWebRequestTransport();
         config.SetupWeighedReplicaOrdering(builder => { builder.AddAdaptiveHealthModifierWithLinearDecay(TuningPolicies.ByResponseVerdict, 10.Minutes()); });
     });
     forkingRequestStrategy  = new ForkingRequestStrategy(new EqualDelaysProvider(addressList.Length), addressList.Length);
     parallelRequestStrategy = new ParallelRequestStrategy(addressList.Length);
 }
コード例 #4
0
        public void Should_ignore_connection_timeout()
        {
            strategy = new ParallelRequestStrategy(int.MaxValue);

            parameters = parameters.WithConnectionTimeout(5.Seconds());

            strategy.SendAsync(request, parameters, sender, Budget.WithRemaining(5.Seconds()), replicas, replicas.Length, token);

            sender.ReceivedCalls().Should().HaveCount(replicas.Length);

            foreach (var replica in replicas)
            {
                sender.Received(1).SendToReplicaAsync(replica, Arg.Any <Request>(), null, Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>());
            }
        }
        public void SetUp()
        {
            request       = Request.Get("foo/bar");
            replicas      = Enumerable.Range(0, 10).Select(i => new Uri($"http://replica-{i}/")).ToArray();
            resultSources = replicas.ToDictionary(r => r, _ => new TaskCompletionSource <ReplicaResult>());

            sender = Substitute.For <IRequestSender>();
            sender
            .SendToReplicaAsync(Arg.Any <Uri>(), Arg.Any <Request>(), Arg.Any <TimeSpan>(), Arg.Any <CancellationToken>())
            .Returns(info => resultSources[info.Arg <Uri>()].Task);

            token = new CancellationTokenSource().Token;

            strategy = new ParallelRequestStrategy(3);
        }