コード例 #1
0
        public virtual void TestStats()
        {
            l.Lock();
            Assert.IsTrue(l.IsLocked());
            Assert.IsTrue(l.IsLockedByCurrentThread());
            Assert.AreEqual(1, l.GetLockCount());
            l.Unlock();
            Assert.IsFalse(l.IsLocked());
            Assert.AreEqual(0, l.GetLockCount());
            Assert.AreEqual(-1L, l.GetRemainingLeaseTime());
            l.Lock(1, TimeUnit.MINUTES);
            Assert.IsTrue(l.IsLocked());
            Assert.IsTrue(l.IsLockedByCurrentThread());
            Assert.AreEqual(1, l.GetLockCount());
            Assert.IsTrue(l.GetRemainingLeaseTime() > 1000 * 30);

            CountdownEvent latch2 = new CountdownEvent(1);

            var t2 = new Thread(delegate(object o)
            {
                Assert.IsTrue(ClientLockTest.l.IsLocked());
                Assert.IsFalse(ClientLockTest.l.IsLockedByCurrentThread());
                Assert.AreEqual(1, ClientLockTest.l.GetLockCount());
                Assert.IsTrue(ClientLockTest.l.GetRemainingLeaseTime() > 1000 * 30);
                latch2.Signal();
            });

            t2.Start();

            Assert.IsTrue(latch2.Wait(TimeSpan.FromMinutes(1)));
        }