public void WhenTwoFailuresHaveOccurredTheIntervalBacksOff() { var bcs = new BatchedConnectionStatus(DefaultPeriod); bcs.MarkFailure(); bcs.MarkFailure(); Assert.AreEqual(TimeSpan.FromSeconds(10), bcs.NextInterval); }
public void WhenABatchSucceedsTheStatusResets() { var bcs = new BatchedConnectionStatus(DefaultPeriod); bcs.MarkFailure(); bcs.MarkFailure(); bcs.MarkSuccess(); Assert.AreEqual(DefaultPeriod, bcs.NextInterval); }
public void WhenFourFailuresHaveOccurredTheIntervalBacksOffAndBatchIsDropped() { var bcs = new BatchedConnectionStatus(DefaultPeriod); bcs.MarkFailure(); bcs.MarkFailure(); bcs.MarkFailure(); bcs.MarkFailure(); Assert.AreEqual(TimeSpan.FromSeconds(40), bcs.NextInterval); Assert.That(bcs.ShouldDropBatch); Assert.IsFalse(bcs.ShouldDropQueue); }
public void WhenSixFailuresHaveOccurredTheQueueIsDropped() { var bcs = new BatchedConnectionStatus(DefaultPeriod); for (var i = 0; i < 6; ++i ) bcs.MarkFailure(); Assert.That(bcs.ShouldDropQueue); }
async Task OnTick() { try { bool batchWasFull; do { LogEvent next; while (_waitingBatch.Count < _batchSizeLimit && _queue.TryDequeue(out next)) { if (CanInclude(next)) { _waitingBatch.Enqueue(next); } } if (_waitingBatch.Count == 0) { await OnEmptyBatchAsync(); return; } await EmitBatchAsync(_waitingBatch); batchWasFull = _waitingBatch.Count >= _batchSizeLimit; _waitingBatch.Clear(); _status.MarkSuccess(); }while (batchWasFull); // Otherwise, allow the period to elapse } catch (Exception ex) { SelfLog.WriteLine("Exception while emitting periodic batch from {0}: {1}", this, ex); _status.MarkFailure(); } finally { if (_status.ShouldDropBatch) { _waitingBatch.Clear(); } if (_status.ShouldDropQueue) { LogEvent evt; while (_queue.TryDequeue(out evt)) { } } lock (_stateLock) { if (!_unloading) { SetTimer(_status.NextInterval); } } } }
void OnTick() { try { do { LogEvent next; while (_waitingBatch.Count < _batchSizeLimit && _queue.TryDequeue(out next)) { if (CanInclude(next)) { _waitingBatch.Enqueue(next); } } if (_waitingBatch.Count == 0) { OnEmptyBatch(); return; } EmitBatch(_waitingBatch); _waitingBatch.Clear(); _status.MarkSuccess(); }while (true); } catch (Exception ex) { SelfLog.WriteLine("Exception while emitting periodic batch from {0}: {1}", this, ex); _status.MarkFailure(); } finally { if (_status.ShouldDropBatch) { _waitingBatch.Clear(); } if (_status.ShouldDropQueue) { LogEvent evt; while (_queue.TryDequeue(out evt)) { } } lock (_stateLock) { if (!_unloading) { _timer.Change(_status.NextInterval, TimeSpan.FromMilliseconds(-1)); } } } }
public void WhenOneFailureHasOccurredTheRegularIntervalIsUsed() { var bcs = new BatchedConnectionStatus(DefaultPeriod); bcs.MarkFailure(); Assert.AreEqual(DefaultPeriod, bcs.NextInterval); }