< Summary

Information
Class: Elsa.Diagnostics.OpenTelemetry.Providers.InMemory.RingBuffer<T>
Assembly: Elsa.Diagnostics.OpenTelemetry
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.OpenTelemetry/Providers/InMemory/RingBuffer.cs
Line coverage
95%
Covered lines: 19
Uncovered lines: 1
Coverable lines: 20
Total lines: 46
Line coverage: 95%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

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

#LineLine coverage
 1namespace Elsa.Diagnostics.OpenTelemetry.Providers.InMemory;
 2
 3public class RingBuffer<T>
 4{
 655    private readonly Queue<T> _items = new();
 656    private readonly object _lock = new();
 7    private readonly int _capacity;
 8    private long _droppedCount;
 9
 6510    public RingBuffer(int capacity)
 11    {
 6512        if (capacity <= 0)
 013            throw new ArgumentOutOfRangeException(nameof(capacity), "Capacity must be greater than zero.");
 14
 6515        _capacity = capacity;
 6516    }
 17
 18    public long DroppedCount
 19    {
 20        get
 21        {
 1622            lock (_lock)
 1623                return _droppedCount;
 1624        }
 25    }
 26
 27    public void Add(T item)
 28    {
 2929        lock (_lock)
 30        {
 2931            if (_items.Count == _capacity)
 32            {
 233                _items.Dequeue();
 234                _droppedCount++;
 35            }
 36
 2937            _items.Enqueue(item);
 2938        }
 2939    }
 40
 41    public IReadOnlyCollection<T> Snapshot()
 42    {
 2243        lock (_lock)
 2244            return _items.ToList();
 2245    }
 46}