Ejemplo n.º 1
0
        public void sequence_is_decremented()
        {
            var throttler = new SequenceThrottle(10);
            throttler.RequestResource(1);
            throttler.RequestResource(2);

            Assert.AreEqual(2, (int)throttler.CurrentSequence);

            throttler.RemoveMany(2);

            Assert.AreEqual(0, (int)throttler.CurrentSequence);
        }
Ejemplo n.º 2
0
        public void exhausting_threshold_causes_blocking()
        {
            var throttler = new SequenceThrottle(2);

            ThreadPool.QueueUserWorkItem(s => {
                Thread.Sleep(3000);
                throttler.RemoveMany(2);
            });

            throttler.RequestResource(1);
            throttler.RequestResource(2);
            throttler.RequestResource(3); // This resource will block until a sequence is released laterally
        }