A Sequence group that can dynamically have Sequences added and removed while being thread safe. The SequenceGroup.Value get and set methods are lock free and can be concurrently called with the SequenceGroup.Add and SequenceGroup.Remove.
Inheritance: ISequence
コード例 #1
0
 public void ShouldNotFailIfTryingToRemoveNotExistingSequence()
 {
     var group = new SequenceGroup();
     group.Add(new Sequence());
     group.Add(new Sequence());
     group.remove(new Sequence());
 }
コード例 #2
0
        public void ShouldAddOneSequenceToGroup()
        {
            var sequence = new Sequence(7L);
            var sequenceGroup = new SequenceGroup();
            sequenceGroup.Add(sequence);

            Assert.AreEqual(sequence.Value, sequenceGroup.Value);
        }
コード例 #3
0
        public void ShouldReportSizeOfGroup()
        {
            var sequenceGroup = new SequenceGroup();
            sequenceGroup.Add(new Sequence());
            sequenceGroup.Add(new Sequence());
            sequenceGroup.Add(new Sequence());

            Assert.AreEqual(3, sequenceGroup.Size);
        }
コード例 #4
0
        public void ShouldReportTheMinimumSequenceForGroupOfTwo()
        {
            var sequenceThree = new Sequence(3L);
            var sequenceSeven = new Sequence(7L);
            var sequenceGroup = new SequenceGroup();
            sequenceGroup.Add(sequenceSeven);
            sequenceGroup.Add(sequenceThree);

            Assert.AreEqual(sequenceThree.Value, sequenceGroup.Value);
        }
コード例 #5
0
        public void ShouldRemoveSequenceFromGroup()
        {
            var sequenceThree = new Sequence(3L);
            var sequenceSeven = new Sequence(7L);
            var sequenceGroup = new SequenceGroup();
            sequenceGroup.Add(sequenceSeven);
            sequenceGroup.Add(sequenceThree);

            Assert.AreEqual(sequenceThree.Value, sequenceGroup.Value);
            Assert.True(sequenceGroup.remove(sequenceThree));
            Assert.AreEqual(sequenceSeven.Value, sequenceGroup.Value);
            Assert.AreEqual(1, sequenceGroup.Size);
        }
コード例 #6
0
        public void ShouldSetGroupSequenceToSameValue()
        {
            var sequenceThree = new Sequence(3L);
            var sequenceSeven = new Sequence(7L);
            var sequenceGroup = new SequenceGroup();
            sequenceGroup.Add(sequenceSeven);
            sequenceGroup.Add(sequenceThree);
            var expectedSequence = 11L;
            sequenceGroup.Value = expectedSequence;

            Assert.AreEqual(expectedSequence, sequenceThree.Value);
            Assert.AreEqual(expectedSequence, sequenceSeven.Value);
        }
コード例 #7
0
 public void ShouldReturnMaxSequenceWhenEmptyGroup()
 {
     var sequenceGroup = new SequenceGroup();
     Assert.AreEqual(long.MaxValue, sequenceGroup.Value);
 }
コード例 #8
0
        public void ShouldAddWhileRunning()
        {
            var ringBuffer = RingBuffer<TestEvent>.CreateSingleProducer(() => new TestEvent(), 32);
            var sequenceThree = new Sequence(3L);
            var sequenceSeven = new Sequence(7L);
            var sequenceGroup = new SequenceGroup();
            sequenceGroup.Add(sequenceSeven);

            for (int i = 0; i < 11; i++)
            {
                ringBuffer.Publish(ringBuffer.Next());
            }

            sequenceGroup.AddWhileRunning(ringBuffer, sequenceThree);
            Assert.AreEqual(sequenceThree.Value,10L);
        }