< Summary

Information
Class: Elsa.Diagnostics.StructuredLogs.Providers.InMemory.RingBuffer<T>
Assembly: Elsa.Diagnostics.StructuredLogs
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.StructuredLogs/Providers/InMemory/RingBuffer.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 38
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
get_DroppedCount()100%11100%
Add(...)100%22100%
Snapshot()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.StructuredLogs/Providers/InMemory/RingBuffer.cs

#LineLine coverage
 1namespace Elsa.Diagnostics.StructuredLogs.Providers.InMemory;
 2
 3public class RingBuffer<T>
 4{
 85    private readonly Queue<T> _items = new();
 86    private readonly object _lock = new();
 7    private readonly int _capacity;
 8
 89    public RingBuffer(int capacity)
 10    {
 811        if (capacity <= 0)
 112            throw new ArgumentOutOfRangeException(nameof(capacity), "Capacity must be greater than zero.");
 13
 714        _capacity = capacity;
 715    }
 16
 917    public long DroppedCount { get; private set; }
 18
 19    public void Add(T item)
 20    {
 1921        lock (_lock)
 22        {
 1923            if (_items.Count == _capacity)
 24            {
 225                _items.Dequeue();
 226                DroppedCount++;
 27            }
 28
 1929            _items.Enqueue(item);
 1930        }
 1931    }
 32
 33    public IReadOnlyCollection<T> Snapshot()
 34    {
 535        lock (_lock)
 536            return _items.ToList();
 537    }
 38}