public void WhenTwoFailuresHaveOccurredTheIntervalBacksOff()
 {
     var bcs = new BatchedConnectionStatus(DefaultPeriod);
     bcs.MarkFailure();
     bcs.MarkFailure();
     Assert.AreEqual(TimeSpan.FromSeconds(10), bcs.NextInterval);
 }
 public void WhenSixFailuresHaveOccurredTheQueueIsDropped()
 {
     var bcs = new BatchedConnectionStatus(DefaultPeriod);
     for (var i = 0; i < 6; ++i )
         bcs.MarkFailure();
     Assert.That(bcs.ShouldDropQueue);
 }
 public void WhenABatchSucceedsTheStatusResets()
 {
     var bcs = new BatchedConnectionStatus(DefaultPeriod);
     bcs.MarkFailure();
     bcs.MarkFailure();
     bcs.MarkSuccess();
     Assert.AreEqual(DefaultPeriod, bcs.NextInterval);
 }
        /// <summary>
        /// Construct a sink posting to the specified database.
        /// </summary>
        /// <param name="batchSizeLimit">The maximum number of events to include in a single batch.</param>
        /// <param name="period">The time to wait between checking for event batches.</param>
        protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period)
        {
            _batchSizeLimit = batchSizeLimit;
            _queue = new ConcurrentQueue<LogEvent>();
            _timer = new Timer(s => OnTick());
            _status = new BatchedConnectionStatus(period);

            AppDomain.CurrentDomain.DomainUnload += OnAppDomainUnloading;
            AppDomain.CurrentDomain.ProcessExit += OnAppDomainUnloading;
        }
        /// <summary>
        /// Construct a sink posting to the specified database.
        /// </summary>
        /// <param name="batchSizeLimit">The maximum number of events to include in a single batch.</param>
        /// <param name="period">The time to wait between checking for event batches.</param>
        protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period)
        {
            _batchSizeLimit = batchSizeLimit;
            _queue          = new ConcurrentQueue <LogEvent>();
            _timer          = new Timer(s => OnTick());
            _status         = new BatchedConnectionStatus(period);

            AppDomain.CurrentDomain.DomainUnload       += OnAppDomainUnloading;
            AppDomain.CurrentDomain.ProcessExit        += OnAppDomainUnloading;
            AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnloading;
        }
 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);
 }
        /// <summary>
        /// Construct a sink posting to the specified database.
        /// </summary>
        /// <param name="batchSizeLimit">The maximum number of events to include in a single batch.</param>
        /// <param name="period">The time to wait between checking for event batches.</param>
        protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period)
        {
            _batchSizeLimit = batchSizeLimit;
            _queue          = new ConcurrentQueue <LogEvent>();
            _status         = new BatchedConnectionStatus(period);

#if WAITABLE_TIMER
            _timer = new Timer(s => OnTick(), null, -1, -1);
#else
            _timer = new PortableTimer(cancel => OnTick());
#endif
        }
Example #8
0
        /// <summary>
        /// Construct a sink posting to the specified database.
        /// </summary>
        /// <param name="batchSizeLimit">The maximum number of events to include in a single batch.</param>
        /// <param name="period">The time to wait between checking for event batches.</param>
        protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period)
        {
            _batchSizeLimit = batchSizeLimit;
            _queue          = new ConcurrentQueue <LogEvent>();
            _status         = new BatchedConnectionStatus(period);

#if NO_TIMER
            _timer = new PortableTimer(cancel => OnTick());
#else
            _timer = new Timer(s => OnTick(), null, -1, -1);
#endif

#if !NO_APPDOMAIN
            AppDomain.CurrentDomain.DomainUnload       += OnAppDomainUnloading;
            AppDomain.CurrentDomain.ProcessExit        += OnAppDomainUnloading;
            AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnloading;
#endif
        }
Example #9
0
        PeriodicBatchingSink(PeriodicBatchingSinkOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.BatchSizeLimit <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(options), "The batch size limit must be greater than zero.");
            }
            if (options.Period <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(options), "The period must be greater than zero.");
            }

            _batchSizeLimit        = options.BatchSizeLimit;
            _queue                 = new BoundedConcurrentQueue <LogEvent>(options.QueueLimit);
            _status                = new BatchedConnectionStatus(options.Period);
            _eagerlyEmitFirstEvent = options.EagerlyEmitFirstEvent;
            _timer                 = new PortableTimer(cancel => OnTick());
        }
 public void WhenOneFailureHasOccurredTheRegularIntervalIsUsed()
 {
     var bcs = new BatchedConnectionStatus(DefaultPeriod);
     bcs.MarkFailure();
     Assert.AreEqual(DefaultPeriod, bcs.NextInterval);
 }