Ejemplo n.º 1
0
        public void UseFifo()
        {
            // Arrange
            var queue = new LogEventQueue(null);

            queue.Enqueue("1");
            queue.Enqueue("2");
            queue.Enqueue("3");

            // Act
            var dequeueResult1 = queue.TryDequeue(long.MaxValue, out var got1);
            var dequeueResult2 = queue.TryDequeue(long.MaxValue, out var got2);
            var dequeueResult3 = queue.TryDequeue(long.MaxValue, out var got3);
            var dequeueResult4 = queue.TryDequeue(long.MaxValue, out var got4);

            // Assert
            dequeueResult1.ShouldBe(LogEventQueue.DequeueResult.Ok);
            dequeueResult2.ShouldBe(LogEventQueue.DequeueResult.Ok);
            dequeueResult3.ShouldBe(LogEventQueue.DequeueResult.Ok);
            dequeueResult4.ShouldBe(LogEventQueue.DequeueResult.QueueEmpty);

            got1.ShouldBe("1");
            got2.ShouldBe("2");
            got3.ShouldBe("3");
            got4.ShouldBe("");
        }
Ejemplo n.º 2
0
        public void NotEnqueueGivenFullQueue()
        {
            // Arrange
            var queue = new LogEventQueue(3);

            queue.Enqueue("1");
            queue.Enqueue("2");
            queue.Enqueue("3");

            // Act
            var got = queue.TryEnqueue("4");

            // Assert
            got.ShouldBe(LogEventQueue.EnqueueResult.QueueFull);
        }
Ejemplo n.º 3
0
        public void ThrowExceptionGivenFullQueue()
        {
            // Arrange
            var queue = new LogEventQueue(3);

            queue.Enqueue("1");
            queue.Enqueue("2");
            queue.Enqueue("3");

            // Act
            Action got = () => queue.Enqueue("4");

            // Assert
            got.ShouldThrow <Exception>();
        }
Ejemplo n.º 4
0
        public void ReadLogEvents()
        {
            // Arrange
            var queue = new LogEventQueue();

            queue.Enqueue(FooLogEvent);
            queue.Enqueue(BarLogEvent);

            // Act
            var got = LogEventQueueReader.Read(queue, null, null);

            // Assert
            got.LogEvents.ShouldBe(new[] { FooLogEvent, BarLogEvent });
            got.HasReachedLimit.ShouldBeFalse();
        }
Ejemplo n.º 5
0
        public void RespectBatchSizeLimit()
        {
            // Arrange
            var queue = new LogEventQueue();

            queue.Enqueue(FooLogEvent);
            queue.Enqueue(BarLogEvent);

            var batchSizeLimit = (FooLogEvent.Length + BarLogEvent.Length) * 2 / 3;

            // Act
            var got = LogEventQueueReader.Read(queue, null, batchSizeLimit);

            // Assert
            got.LogEvents.ShouldBe(new[] { FooLogEvent });
            got.HasReachedLimit.ShouldBeTrue();
        }
Ejemplo n.º 6
0
        public void RespectlogEventsInBatchLimit()
        {
            // Arrange
            var queue = new LogEventQueue();

            queue.Enqueue(FooLogEvent);
            queue.Enqueue(BarLogEvent);

            const int logEventsInBatchLimit = 1;

            // Act
            var got = LogEventQueueReader.Read(queue, logEventsInBatchLimit, null);

            // Assert
            got.LogEvents.ShouldBe(new[] { FooLogEvent });
            got.HasReachedLimit.ShouldBeTrue();
        }
        public void SkipLogEventGivenItExceedsBatchSizeLimit()
        {
            // Arrange
            const string logEventExceedingBatchSizeLimit = "{ \"foo\": \"This document exceeds the batch size limit\" }";

            var queue = new LogEventQueue(null);

            queue.Enqueue(logEventExceedingBatchSizeLimit);
            queue.Enqueue(BarLogEvent);

            var batchSizeLimit = ByteSize.From(logEventExceedingBatchSizeLimit) - 1;

            // Act
            var got = LogEventQueueReader.Read(queue, int.MaxValue, batchSizeLimit);

            // Assert
            got.LogEvents.ShouldBe(new[] { BarLogEvent });
            got.HasReachedLimit.ShouldBeFalse();
        }
Ejemplo n.º 8
0
        public void DequeueGivenMaxSize(string logEvent, int maxSize, LogEventQueue.DequeueResult want)
        {
            // Arrange
            var queue = new LogEventQueue(null);

            queue.Enqueue(logEvent);

            // Act
            var got = queue.TryDequeue(maxSize, out var dequeuedLogEvent);

            // Assert
            got.ShouldBe(want);
            dequeuedLogEvent.ShouldBe(want == LogEventQueue.DequeueResult.Ok ? logEvent : "");
        }
Ejemplo n.º 9
0
        public void Dequeue()
        {
            // Arrange
            var queue = new LogEventQueue(null);

            queue.Enqueue("1");

            // Act
            var result = queue.TryDequeue(long.MaxValue, out var got);

            // Assert
            result.ShouldBe(LogEventQueue.DequeueResult.Ok);
            got.ShouldBe("1");
        }
        public void ReadLogEvent()
        {
            // Arrange
            var queue = new LogEventQueue(null);

            queue.Enqueue(FooLogEvent);

            // Act
            var got = LogEventQueueReader.Read(queue, int.MaxValue, long.MaxValue);

            // Assert
            got.LogEvents.ShouldBe(
                new[]
            {
                FooLogEvent
            });
            got.HasReachedLimit.ShouldBeFalse();
        }