コード例 #1
0
        public void AcquireExpire()
        {

            var lockName = "AcquireExpire" + DateTime.Now.Ticks;

            var collection = GetCollection();
            collection.Should().NotBeNull();

            var locker = new ThrottleLock(collection);
            locker.Should().NotBeNull();

            var result = locker.Acquire(lockName, TimeSpan.FromMilliseconds(5));
            result.Should().BeTrue();

            var status = locker.Status(lockName);
            status.Should().NotBeNull();
            status.IsLocked.Should().BeTrue();

            // wait for expire
            Thread.Sleep(5);

            var blocked = locker.Acquire(lockName, TimeSpan.FromMilliseconds(5));
            blocked.Should().BeTrue();

        }
コード例 #2
0
        public void AcquireBlock()
        {

            var lockName = "AcquireBlock" + DateTime.Now.Ticks;

            var collection = GetCollection();
            collection.Should().NotBeNull();

            var locker = new ThrottleLock(collection, TimeSpan.FromMinutes(5));
            locker.Should().NotBeNull();

            var result = locker.Acquire(lockName);
            result.Should().BeTrue();

            var status = locker.Status(lockName);
            status.Should().NotBeNull();
            status.IsLocked.Should().BeTrue();

            var blocked = locker.Acquire(lockName);
            blocked.Should().BeFalse();

        }