public void TestThrottle() { Throttle throttle = new Throttle(new TokenBucket(1000, 2000)); long delay1 = throttle.GetDelayMilliseconds(1000); Assert.Equal(0, delay1); long delay2 = throttle.GetDelayMilliseconds(1000); Assert.InRange(delay2, 400, 500); }
/// <inheritdoc/> public AmazonCloudWatchClient FailbackToPrimaryRegion(Throttle throttle) { var _cloudWatchClient = _failoverSink.FailbackToPrimaryRegion(_throttle); if (_cloudWatchClient is not null) { // Jittered Delay var delay = _throttle.GetDelayMilliseconds(1); if (delay > 0) { Task.Delay((int)(delay * (1.0d + Utility.Random.NextDouble() * ConfigConstants.DEFAULT_JITTING_FACTOR))).Wait(); } // Dispose CloudWatchClient.Dispose(); // Override client CloudWatchClient = _cloudWatchClient; } return(null); }
public void TestThrottleWith2Buckets() { Throttle throttle = new Throttle(new TokenBucket[] { new TokenBucket(1000, 2000), new TokenBucket(1000 * 1000, 5 * 1000 * 1000) }); Assert.ThrowsAny <Exception>(() => throttle.GetDelayMilliseconds(1000)); long delay1 = throttle.GetDelayMilliseconds(new long[] { 1000, 1000 * 1000 }); Assert.Equal(0, delay1); long delay2 = throttle.GetDelayMilliseconds(new long[] { 0, 1000 * 1000 }); Assert.InRange(delay2, 150, 200); long delay3 = throttle.GetDelayMilliseconds(new long[] { 1000, 0 }); Assert.InRange(delay3, 400, 500); }
/// <inheritdoc/> public AmazonCloudWatchLogsClient FailbackToPrimaryRegion(Throttle throttle) { var _cloudWatchLogsClient = _failoverSink.FailbackToPrimaryRegion(_throttle); if (_cloudWatchLogsClient is not null) { // Jittered Delay var delay = _throttle.GetDelayMilliseconds(1); if (delay > 0) { Task.Delay((int)(delay * (1.0d + Utility.Random.NextDouble() * ConfigConstants.DEFAULT_JITTING_FACTOR))).Wait(); } // Dispose CloudWatchLogsClient.Dispose(); // Override client CloudWatchLogsClient = _cloudWatchLogsClient; // Reset CloudWatch Logs sequence token _sequenceToken = null; GetSequenceTokenAsync(ResolveTimestampInLogStreamName(DateTime.UtcNow), true).Wait(); } return(null); }
protected override long GetDelayMilliseconds(int recordCount, long batchBytes) { long timeToWait = _throttle.GetDelayMilliseconds(new long[] { recordCount, batchBytes }); return(timeToWait); }
protected override long GetDelayMilliseconds(int recordCount, long batchBytes) { long timeToWait = _throttle.GetDelayMilliseconds(new long[] { 1, recordCount, batchBytes }); //The 1st element indicates 1 API call. return(timeToWait); }
/// <inheritdoc/> protected override int GetDelayMilliseconds(int recordCount, long batchBytes) => (int)_throttle.GetDelayMilliseconds(1);
protected override long GetDelayMilliseconds(int recordCount, long batchBytes) { return(Throttle.GetDelayMilliseconds(1)); }