Esempio n. 1
0
        public void TreeLock_CannotAcquire()
        {
            Test <object>(() =>
            {
                var locks = TreeLock.GetAllLocks();
                Assert.AreEqual(0, locks.Count);

                using (TreeLock.Acquire("/Root/A/B/C"))
                {
                    locks = TreeLock.GetAllLocks();
                    Assert.AreEqual(1, locks.Count);
                    Assert.IsTrue(locks.ContainsValue("/Root/A/B/C"));

                    foreach (var path in new[] { "/Root/A/B/C/D", "/Root/A/B/C", "/Root/A/B", "/Root/A", "/Root" })
                    {
                        try
                        {
                            TreeLock.Acquire("/Root/A/B/C/D");
                            Assert.Fail($"LockedTreeException was not thrown. Path: {path}");
                        }
                        catch (LockedTreeException)
                        {
                        }

                        locks = TreeLock.GetAllLocks();
                        Assert.AreEqual(1, locks.Count);
                        Assert.IsTrue(locks.ContainsValue("/Root/A/B/C"));
                    }
                }

                return(null);
            });
        }
Esempio n. 2
0
        public void TreeLock_Release()
        {
            Test <object>(() =>
            {
                var locks = TreeLock.GetAllLocks();
                Assert.AreEqual(0, locks.Count);

                using (TreeLock.Acquire("/Root/A/B/C1"))
                {
                    using (TreeLock.Acquire("/Root/A/B/C2"))
                    {
                        locks = TreeLock.GetAllLocks();
                        Assert.AreEqual(2, locks.Count);
                        Assert.IsTrue(locks.ContainsValue("/Root/A/B/C1"));
                        Assert.IsTrue(locks.ContainsValue("/Root/A/B/C2"));

                        Assert.IsTrue(IsLocked("/Root/A/B/C1/D"));
                        Assert.IsTrue(IsLocked("/Root/A/B/C2/D"));
                        Assert.IsTrue(IsLocked("/Root/A/B/C1"));
                        Assert.IsTrue(IsLocked("/Root/A/B/C2"));
                        Assert.IsTrue(IsLocked("/Root/A/B"));
                        Assert.IsTrue(IsLocked("/Root/A"));
                        Assert.IsTrue(IsLocked("/Root"));
                    }
                    locks = TreeLock.GetAllLocks();
                    Assert.AreEqual(1, locks.Count);
                    Assert.IsTrue(locks.ContainsValue("/Root/A/B/C1"));

                    Assert.IsTrue(IsLocked("/Root/A/B/C1/D"));
                    Assert.IsTrue(IsLocked("/Root/A/B/C1"));
                    Assert.IsTrue(IsLocked("/Root/A/B"));
                    Assert.IsTrue(IsLocked("/Root/A"));
                    Assert.IsTrue(IsLocked("/Root"));

                    Assert.IsFalse(IsLocked("/Root/A/B/C2/D"));
                    Assert.IsFalse(IsLocked("/Root/A/B/C2"));
                }
                locks = TreeLock.GetAllLocks();
                Assert.AreEqual(0, locks.Count);

                Assert.IsFalse(IsLocked("/Root/A/B/C1/D"));
                Assert.IsFalse(IsLocked("/Root/A/B/C2/D"));
                Assert.IsFalse(IsLocked("/Root/A/B/C1"));
                Assert.IsFalse(IsLocked("/Root/A/B/C2"));
                Assert.IsFalse(IsLocked("/Root/A/B"));
                Assert.IsFalse(IsLocked("/Root/A"));
                Assert.IsFalse(IsLocked("/Root"));

                return(null);
            });
        }
Esempio n. 3
0
        public void TreeLock_AcquireAndScope()
        {
            Test(() =>
            {
                using (TreeLock.Acquire("/Root/A/B/C"))
                {
                    var locks = TreeLock.GetAllLocks();
                    Assert.AreEqual(1, locks.Count);
                    Assert.IsTrue(locks.ContainsValue("/Root/A/B/C"));

                    Assert.IsTrue(IsLocked("/Root/A/B/C/D"));
                    Assert.IsTrue(IsLocked("/Root/A/B/C"));
                    Assert.IsTrue(IsLocked("/Root/A/B"));
                    Assert.IsTrue(IsLocked("/Root/A"));
                    Assert.IsTrue(IsLocked("/Root"));

                    Assert.IsFalse(IsLocked("/Root/A/B/X"));
                    Assert.IsFalse(IsLocked("/Root/A/X"));
                    Assert.IsFalse(IsLocked("/Root/X"));
                }
            });
        }