Ejemplo n.º 1
0
        public void ShouldNotReturnNextClaimSequenceUntilBufferHasReserve()
        {
            var dependentSequence = new Sequence(Sequencer.InitialCursorValue);

            Sequence[] dependentSequences = { dependentSequence };
            _claimStrategy.SetSequence(_claimStrategy.BufferSize - 1L, dependentSequences);

            var done        = new Volatile4.Boolean(false);
            var beforeLatch = new ManualResetEvent(false);
            var afterLatch  = new ManualResetEvent(false);

            new Thread(
                () =>
            {
                beforeLatch.Set();

                Assert.AreEqual(_claimStrategy.BufferSize, _claimStrategy.IncrementAndGet(dependentSequences));

                done.WriteFullFence(true);
                afterLatch.Set();
            }).Start();

            beforeLatch.WaitOne();

            Thread.Sleep(100);
            Assert.IsFalse(done.ReadFullFence());

            dependentSequence.Value = (dependentSequence.Value + 1L);

            afterLatch.WaitOne();
            Assert.AreEqual(_claimStrategy.BufferSize, _claimStrategy.Sequence);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Wait for the <see cref="RingBuffer{T}"/> to drain of published events then halt the workers.
        /// </summary>
        public void DrainAndHalt()
        {
            var workerSequences = WorkerSequences;

            while (_ringBuffer.Cursor > Util.GetMinimumSequence(workerSequences))
            {
                Thread.Sleep(0);
            }

            for (int i = 0; i < _workProcessors.Length; i++)
            {
                var workProcessor = _workProcessors[i];
                workProcessor.Halt();
            }

            _running.WriteFullFence(Stopped);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Signal that this <see cref="IEventProcessor"/> should stop when it has finished consuming at the next clean break.
 /// It will call <see cref="ISequenceBarrier.Alert"/> to notify the thread to check status.
 /// </summary>
 public void Halt()
 {
     _running.WriteFullFence(Stopped);
     _sequenceBarrier.Alert();
 }
        public void ShouldNotReturnNextClaimSequenceUntilBufferHasReserve()
        {
            var dependentSequence = new Sequence(Sequencer.InitialCursorValue);
            var dependentSequences = new[] { dependentSequence };
            _claimStrategy.SetSequence(BufferSize - 1L, dependentSequences);

            var done = new Volatile4.Boolean(false);
            var beforeLatch = new ManualResetEvent(false);
            var afterLatch = new ManualResetEvent(false);

            new Thread(() =>
                           {
                               beforeLatch.Set();

                               Assert.AreEqual(_claimStrategy.BufferSize,
                                               _claimStrategy.IncrementAndGet(dependentSequences));

                               done.WriteFullFence(true);
                               afterLatch.Set();
                           }).Start();

            beforeLatch.WaitOne();

            Thread.Sleep(1000);
            Assert.IsFalse(done.ReadFullFence());

            dependentSequence.Value = dependentSequence.Value + 1L;

            afterLatch.WaitOne();
            Assert.AreEqual(_claimStrategy.BufferSize, _claimStrategy.Sequence);
        }
 public void WriteFullFenceChangesInitialValue()
 {
     _volatile.WriteFullFence(NewValue);
     Assert.AreEqual(NewValue, _volatile.ReadUnfenced());
 }