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

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

            throttler.RemoveOne(2);
            throttler.RequestResource(3); // This would block indefinitely if releasing did not work
        }
Ejemplo n.º 3
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
        }