Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            clientState = ClientState.Failure;

            var taskBatches =
                Enumerable
                .Range(0, 1000)
                .Select(async c =>
            {
                var tasks =
                    Enumerable
                    .Range(0, 100)
                    .Select(MakeCall);

                var res = await Task.WhenAll(tasks);
                return(new List <int>(res));
            });
            var batches = await Task.WhenAll(taskBatches);

            var totalItems =
                batches
                .SelectMany(t => t)
                .Count();

            Console.WriteLine($"clientStats: totalClientCalls:{TotalClientCalls}, totalClientErrors: {TotalClientErrors}");
            Console.WriteLine($"callerStats: totalCallsMade:{TotalCallsMade}, totalErrorsReceived: {TotalErrorsReceived}");

            var tokenBucker = TokenBucket.Create(
                tokens: 50,
                timeWindow: TimeSpan.FromSeconds(1),
                returnTokens: 50
                );
        }
Ejemplo n.º 2
0
        public void PolicyExecutesThePassedDelegate()
        {
            bool executed = false;
            var  policy   = TokenBucket.Create(50, TimeSpan.FromMinutes(1), 2);

            policy.Execute(() => executed = true);

            executed.Should().BeTrue();
        }
Ejemplo n.º 3
0
        public void ReplaceMeWithRealTests()
        {
            /*
             * This test is for illustrative purposes, to show the interfaces a typical synchronous non-generic policy fulfills.
             * Real tests should check policy behaviour.
             */
            var policy = TokenBucket.Create(50, TimeSpan.FromMinutes(1), 2);

            policy.Should().BeAssignableTo <ISyncPolicy>();
            policy.Should().BeAssignableTo <ITokenBucket>();
        }