Esempio n. 1
0
        public FileRateLimitingService(IConfigService configService)
        {
            this._configService = configService;
            var rateLimitingConfig = configService.GetJson <RateLimitingConfig>("RateLimiting");

            this._createRate        = new RequestsCounter(rateLimitingConfig.SavePerIP.DurationTime);
            this._getPerIpRate      = new RequestsCounter(rateLimitingConfig.GetPerIP.DurationTime);
            this._getPerFileKeyRate = new RequestsCounter(rateLimitingConfig.GetPerFileKey.DurationTime);

            _clearTimer = new Timer((_) => OnClearTimerTick(), null, 10 * 1000, 10 * 1000);
        }
Esempio n. 2
0
    public async Task InjectsPollyCircuitBreakerPolicy()
    {
        // Arrange
        this.SetBaseAddress("http://localhost/v3/");

        var counter = new RequestsCounter();

        var serviceCollection = new ServiceCollection();

        serviceCollection.AddSingleton(counter);
        serviceCollection.AddTransient <IHttpMessageHandlerBuilderFilter, RequestsFilter>();
        serviceCollection.AddEcsTaskMetadataClientFactory();
        var serviceProvider = serviceCollection.BuildServiceProvider();

        var client = serviceProvider.GetService <IEcsTaskMetadataClient>();

        // Act
        var firstResponse     = await client !.GetContainerStatsAsync(CancellationToken.None).ConfigureAwait(true);
        var firstRequestCount = counter.Requests;

        var secondResponse = await Assert.ThrowsAsync <BrokenCircuitException <HttpResponseMessage> >(() => client !.GetContainerStatsAsync(CancellationToken.None)).ConfigureAwait(true);

        var secondRequestCount = counter.Requests;

        var thirdResponse = await Assert.ThrowsAsync <BrokenCircuitException <HttpResponseMessage> >(() => client !.GetContainerStatsAsync(CancellationToken.None)).ConfigureAwait(true);

        var thirdRequestCount = counter.Requests;

        // Assert
        Assert.Null(firstResponse);
        Assert.Equal(4, firstRequestCount);

        Assert.NotNull(secondResponse);
        Assert.Equal(5, secondRequestCount);

        Assert.NotNull(thirdResponse);
        Assert.Equal(5, thirdRequestCount);
    }
Esempio n. 3
0
    public async Task InjectsPollyRetryPolicy()
    {
        // Arrange
        this.SetBaseAddress("http://localhost/v3/");

        var counter = new RequestsCounter();

        var serviceCollection = new ServiceCollection();

        serviceCollection.AddSingleton(counter);
        serviceCollection.AddTransient <IHttpMessageHandlerBuilderFilter, RequestsFilter>();
        serviceCollection.AddEcsTaskMetadataClientFactory();
        var serviceProvider = serviceCollection.BuildServiceProvider();

        var client = serviceProvider.GetService <IEcsTaskMetadataClient>();

        // Act
        var response = await client !.GetContainerStatsAsync(CancellationToken.None).ConfigureAwait(true);

        // Assert
        Assert.Null(response);
        Assert.Equal(4, counter.Requests);
    }
Esempio n. 4
0
 public RequestsFilter(RequestsCounter counter) =>
 this.counter = counter;
Esempio n. 5
0
 public RequestsHandler(RequestsCounter counter) =>
 this.counter = counter;
Esempio n. 6
0
		public void IncrementRequests(string method = null, string details = null) {
			if (RequestsCounter == null)
				RequestsCounter = new RequestsCounterData();

			RequestsCounter.IncrementRequests(method, details);
		} // IncrementRequests