< 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{
 225    private readonly Queue<T> _items = new();
 226    private readonly object _lock = new();
 7    private readonly int _capacity;
 8
 229    public RingBuffer(int capacity)
 10    {
 2211        if (capacity <= 0)
 112            throw new ArgumentOutOfRangeException(nameof(capacity), "Capacity must be greater than zero.");
 13
 2114        _capacity = capacity;
 2115    }
 16
 3517    public long DroppedCount { get; private set; }
 18
 19    public void Add(T item)
 20    {
 4621        lock (_lock)
 22        {
 4623            if (_items.Count == _capacity)
 24            {
 425                _items.Dequeue();
 426                DroppedCount++;
 27            }
 28
 4629            _items.Enqueue(item);
 4630        }
 4631    }
 32
 33    public IReadOnlyCollection<T> Snapshot()
 34    {
 2735        lock (_lock)
 2736            return _items.ToList();
 2737    }
 38}