public HttpLogShipper( IHttpClient client, string requestUri, string bufferBaseFilename, int batchPostingLimit, TimeSpan period, IBatchFormatter batchFormatter) { if (bufferBaseFilename == null) { throw new ArgumentNullException(nameof(bufferBaseFilename)); } if (batchPostingLimit <= 0) { throw new ArgumentException("batchPostingLimit must be 1 or greater", nameof(batchPostingLimit)); } this.client = client ?? throw new ArgumentNullException(nameof(client)); this.requestUri = requestUri ?? throw new ArgumentNullException(nameof(requestUri)); this.batchPostingLimit = batchPostingLimit; this.batchFormatter = batchFormatter ?? throw new ArgumentNullException(nameof(batchFormatter)); bookmarkFilename = Path.GetFullPath(bufferBaseFilename + ".bookmark"); logFolder = Path.GetDirectoryName(bookmarkFilename); candidateSearchPath = Path.GetFileName(bufferBaseFilename) + "*.json"; connectionSchedule = new ExponentialBackoffConnectionSchedule(period); timer = new PortableTimer(OnTick); SetTimer(); }
[InlineData(10 * 60)] // 10 min public void SchedulerShouldReturnPeriodOnSuccess(int periodInSeconds) { var expected = TimeSpan.FromSeconds(periodInSeconds); var schedule = new ExponentialBackoffConnectionSchedule(expected); var actual = schedule.NextInterval; actual.ShouldBe(expected); }
[InlineData(10 * 60)] // 10 min public void SchedulerShouldBehaveExponentially(int periodInSeconds) { var period = TimeSpan.FromSeconds(periodInSeconds); var schedule = new ExponentialBackoffConnectionSchedule(period); IBackoff backoff = new LinearBackoff(period); while (backoff is not CappedBackoff) { schedule.MarkFailure(); backoff = backoff.GetNext(schedule.NextInterval); } schedule.NextInterval.ShouldBe(ExponentialBackoffConnectionSchedule.MaximumBackoffInterval); }
[InlineData(10 * 60)] // 10 min public void SchedulerShouldRemainCappedDuringFailures(int periodInSeconds) { var period = TimeSpan.FromSeconds(periodInSeconds); var schedule = new ExponentialBackoffConnectionSchedule(period); while (schedule.NextInterval != ExponentialBackoffConnectionSchedule.MaximumBackoffInterval) { schedule.MarkFailure(); } for (var i = 0; i < 10000; i++) { schedule.NextInterval.ShouldBe(ExponentialBackoffConnectionSchedule.MaximumBackoffInterval); schedule.MarkFailure(); } }
public HttpLogShipper( IHttpClient client, string requestUri, string bufferPathFormat, int batchPostingLimit, TimeSpan period, IBatchFormatter batchFormatter) { if (bufferPathFormat == null) { throw new ArgumentNullException(nameof(bufferPathFormat)); } if (bufferPathFormat != bufferPathFormat.Trim()) { throw new ArgumentException("bufferPathFormat must not contain any leading or trailing whitespaces", nameof(bufferPathFormat)); } if (batchPostingLimit <= 0) { throw new ArgumentException("batchPostingLimit must be 1 or greater", nameof(batchPostingLimit)); } this.client = client ?? throw new ArgumentNullException(nameof(client)); this.requestUri = requestUri ?? throw new ArgumentNullException(nameof(requestUri)); this.batchPostingLimit = batchPostingLimit; this.batchFormatter = batchFormatter ?? throw new ArgumentNullException(nameof(batchFormatter)); var bufferPathFormatMatch = BufferPathFormatRegex.Match(bufferPathFormat); if (!bufferPathFormatMatch.Success) { throw new ArgumentException($"bufferPathFormat must include one of the date formats [{string.Join(", ", Enum.GetNames(typeof(DateFormats)))}]"); } var prefix = bufferPathFormatMatch.Groups["prefix"]; var postfix = bufferPathFormatMatch.Groups["postfix"]; bookmarkFilename = Path.GetFullPath(prefix.Value.TrimEnd(new char[] { '-' }) + ".bookmark"); logFolder = Path.GetDirectoryName(bookmarkFilename); candidateSearchPath = $"{Path.GetFileName(prefix.Value)}*{postfix.Value}"; connectionSchedule = new ExponentialBackoffConnectionSchedule(period); timer = new PortableTimer(OnTick); SetTimer(); }
public HttpLogShipper( IHttpClient client, string requestUri, IBufferFiles bufferFiles, int batchPostingLimit, TimeSpan period, IBatchFormatter batchFormatter) { if (batchPostingLimit <= 0) { throw new ArgumentException("batchPostingLimit must be 1 or greater", nameof(batchPostingLimit)); } this.client = client ?? throw new ArgumentNullException(nameof(client)); this.requestUri = requestUri ?? throw new ArgumentNullException(nameof(requestUri)); this.bufferFiles = bufferFiles ?? throw new ArgumentNullException(nameof(bufferFiles)); this.batchPostingLimit = batchPostingLimit; this.batchFormatter = batchFormatter ?? throw new ArgumentNullException(nameof(batchFormatter)); connectionSchedule = new ExponentialBackoffConnectionSchedule(period); timer = new PortableTimer(OnTick); SetTimer(); }