[Test] public void TestSize2()
		{
			CyclicBuffer cb = new CyclicBuffer(2);

			Assert.AreEqual(0, cb.Length, "Empty Buffer should have length 0");
			Assert.AreEqual(2, cb.MaxSize, "Buffer should have max size 2");

			LoggingEvent event1 = new LoggingEvent(null, null, null, null, null, null);
			LoggingEvent event2 = new LoggingEvent(null, null, null, null, null, null);
			LoggingEvent event3 = new LoggingEvent(null, null, null, null, null, null);

			LoggingEvent discardedEvent = null;
			
			discardedEvent = cb.Append(event1);
			Assert.IsNull(discardedEvent, "No event should be discarded after append 1");
			discardedEvent = cb.Append(event2);
			Assert.IsNull(discardedEvent, "No event should be discarded after append 2");

			discardedEvent = cb.Append(event3);
			Assert.AreSame(event1, discardedEvent, "Expect event1 to now be discarded");

			discardedEvent = cb.PopOldest();
			Assert.AreSame(event2, discardedEvent, "Expect event2 to now be discarded");

			LoggingEvent[] discardedEvents = cb.PopAll();

			Assert.AreEqual(1, discardedEvents.Length, "Poped events length should be 1");
			Assert.AreSame(event3, discardedEvents[0], "Expect event3 to now be popped");
			Assert.AreEqual(0, cb.Length, "Buffer should be back to length 0");
			Assert.AreEqual(2, cb.MaxSize, "Buffer should really really still have max size 2");
		}
Exemple #2
0
		public void TestSize1()
		{
			CyclicBuffer cb = new CyclicBuffer(1);

			Assert.AreEqual(0, cb.Length, "Empty Buffer should have length 0");
			Assert.AreEqual(1, cb.MaxSize, "Buffer should have max size 1");

			LoggingEvent event1 = new LoggingEvent(null, null, null, null, null, null);
			LoggingEvent event2 = new LoggingEvent(null, null, null, null, null, null);

			LoggingEvent discardedEvent = cb.Append(event1);

			Assert.IsNull(discardedEvent, "No event should be discarded untill the buffer is full");
			Assert.AreEqual(1, cb.Length, "Buffer should have length 1");
			Assert.AreEqual(1, cb.MaxSize, "Buffer should still have max size 1");


			discardedEvent = cb.Append(event2);

			Assert.AreSame(event1, discardedEvent, "Expect event1 to now be discarded");
			Assert.AreEqual(1, cb.Length, "Buffer should still have length 1");
			Assert.AreEqual(1, cb.MaxSize, "Buffer should really still have max size 1");

			LoggingEvent[] discardedEvents = cb.PopAll();

			Assert.AreEqual(1, discardedEvents.Length, "Poped events length should be 1");
			Assert.AreSame(event2, discardedEvents[0], "Expect event2 to now be popped");
			Assert.AreEqual(0, cb.Length, "Buffer should be back to length 0");
			Assert.AreEqual(1, cb.MaxSize, "Buffer should really really still have max size 1");
		}
		public void TestConstructorSize0()
		{
			CyclicBuffer cb = new CyclicBuffer(0);
		}
    /// <summary>
    /// Sends the contents of the buffer.
    /// </summary>
    /// <param name="firstLoggingEvent">The first logging event.</param>
    /// <param name="buffer">The buffer containing the events that need to be send.</param>
    /// <remarks>
    /// <para>
    /// The subclass must override <see cref="SendBuffer(LoggingEvent[])"/>.
    /// </para>
    /// </remarks>
    protected virtual void SendFromBuffer(LoggingEvent firstLoggingEvent, CyclicBuffer buffer) {
      LoggingEvent[] bufferEvents = buffer.PopAll();

      if (firstLoggingEvent == null)
        SendBuffer(bufferEvents);
      else if (bufferEvents.Length == 0)
        SendBuffer(new[] {firstLoggingEvent});
      else {
        // Create new array with the firstLoggingEvent at the head
        var events = new LoggingEvent[bufferEvents.Length + 1];
        Array.Copy(bufferEvents, 0, events, 1, bufferEvents.Length);
        events[0] = firstLoggingEvent;

        SendBuffer(events);
      }
    }
    /// <summary>
    /// Initialize the appender based on the options set
    /// </summary>
    /// <remarks>
    /// <para>
    /// This is part of the <see cref="IOptionHandler"/> delayed object
    /// activation scheme. The <see cref="ActivateOptions"/> method must 
    /// be called on this object after the configuration properties have
    /// been set. Until <see cref="ActivateOptions"/> is called this
    /// object is in an undefined state and must not be used. 
    /// </para>
    /// <para>
    /// If any of the configuration properties are modified then 
    /// <see cref="ActivateOptions"/> must be called again.
    /// </para>
    /// </remarks>
    public override void ActivateOptions() {
      base.ActivateOptions();

      // If the appender is in Lossy mode then we will
      // only send the buffer when the Evaluator triggers
      // therefore check we have an evaluator.
      if (m_lossy && m_evaluator == null)
        ErrorHandler.Error("Appender [" + Name +
                           "] is Lossy but has no Evaluator. The buffer will never be sent!");

      if (m_bufferSize > 1)
        m_cb = new CyclicBuffer(m_bufferSize);
      else
        m_cb = null;
    }
Exemple #6
0
		public void TestConstructorSize0()
		{
			CyclicBuffer cb = new CyclicBuffer(0);
			Assert.IsNotNull(cb);
		}