public async STT.Task TreeLock_CannotAcquireAsync() { var token = CancellationToken.None; await Test(async() => { var locks = await TreeLock.GetAllLocksAsync(token); Assert.AreEqual(0, locks.Count); using (await TreeLock.AcquireAsync(token, "/Root/A/B/C")) { locks = await TreeLock.GetAllLocksAsync(token); 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 { await TreeLock.AcquireAsync(token, "/Root/A/B/C/D"); Assert.Fail($"LockedTreeException was not thrown. Path: {path}"); } catch (LockedTreeException) { } locks = await TreeLock.GetAllLocksAsync(token); Assert.AreEqual(1, locks.Count); Assert.IsTrue(locks.ContainsValue("/Root/A/B/C")); } } }); }
public async STT.Task TreeLock_ReleaseAsync() { var token = CancellationToken.None; await Test(async() => { var locks = await TreeLock.GetAllLocksAsync(token); Assert.AreEqual(0, locks.Count); using (await TreeLock.AcquireAsync(token, "/Root/A/B/C1")) { using (await TreeLock.AcquireAsync(token, "/Root/A/B/C2")) { locks = await TreeLock.GetAllLocksAsync(token); 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 = await TreeLock.GetAllLocksAsync(token); Assert.AreEqual(1, locks.Count); Assert.IsTrue(locks.ContainsValue("/Root/A/B/C1")); Assert.IsTrue(await IsLockedAsync("/Root/A/B/C1/D", token)); Assert.IsTrue(await IsLockedAsync("/Root/A/B/C1", token)); Assert.IsTrue(await IsLockedAsync("/Root/A/B", token)); Assert.IsTrue(await IsLockedAsync("/Root/A", token)); Assert.IsTrue(await IsLockedAsync("/Root", token)); Assert.IsFalse(await IsLockedAsync("/Root/A/B/C2/D", token)); Assert.IsFalse(await IsLockedAsync("/Root/A/B/C2", token)); } locks = await TreeLock.GetAllLocksAsync(token); Assert.AreEqual(0, locks.Count); Assert.IsFalse(await IsLockedAsync("/Root/A/B/C1/D", token)); Assert.IsFalse(await IsLockedAsync("/Root/A/B/C2/D", token)); Assert.IsFalse(await IsLockedAsync("/Root/A/B/C1", token)); Assert.IsFalse(await IsLockedAsync("/Root/A/B/C2", token)); Assert.IsFalse(await IsLockedAsync("/Root/A/B", token)); Assert.IsFalse(await IsLockedAsync("/Root/A", token)); Assert.IsFalse(await IsLockedAsync("/Root", token)); }); }
public async STT.Task TreeLock_AcquireAndScopeAsync() { var token = CancellationToken.None; await Test(async() => { using (await TreeLock.AcquireAsync(CancellationToken.None, "/Root/A/B/C")) { var locks = await TreeLock.GetAllLocksAsync(CancellationToken.None); Assert.AreEqual(1, locks.Count); Assert.IsTrue(locks.ContainsValue("/Root/A/B/C")); Assert.IsTrue(await IsLockedAsync("/Root/A/B/C/D", token)); Assert.IsTrue(await IsLockedAsync("/Root/A/B/C", token)); Assert.IsTrue(await IsLockedAsync("/Root/A/B", token)); Assert.IsTrue(await IsLockedAsync("/Root/A", token)); Assert.IsTrue(await IsLockedAsync("/Root", token)); Assert.IsFalse(await IsLockedAsync("/Root/A/B/X", token)); Assert.IsFalse(await IsLockedAsync("/Root/A/X", token)); Assert.IsFalse(await IsLockedAsync("/Root/X", token)); } }); }