Example #1
0
        public void TreeLock_TSQL_Underscore()
        {
            // This test makes sure that it does not cause a problem if a path
            // contains an underscore. Previously this did not work correctly
            // because the SQL LIKE operator treated it as a special character.

            Test <object>(() =>
            {
                using (TreeLock.Acquire("/Root/A/BxB/C"))
                {
                    TreeLock.AssertFree("/Root/A/B_B");

                    using (TreeLock.Acquire("/Root/A/B_B"))
                    {
                        TreeLock.AssertFree("/Root/A/B_");
                        TreeLock.AssertFree("/Root/A/ByB");
                    }

                    var thrown = false;
                    try
                    {
                        TreeLock.AssertFree("/Root/A/BxB");
                    }
                    catch (LockedTreeException)
                    {
                        thrown = true;
                    }

                    Assert.IsTrue(thrown, "#1");

                    return(null);
                }
            });
        }
Example #2
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);
            });
        }
Example #3
0
        public void RebuildIndex(Node node, bool recursive = false, IndexRebuildLevel rebuildLevel = IndexRebuildLevel.IndexOnly)
        {
            // do nothing in case of IndexOnly level, because this is a NULL populator
            if (rebuildLevel == IndexRebuildLevel.IndexOnly)
            {
                return;
            }

            using (var op = SnTrace.Index.StartOperation("NullPopulator.RefreshIndex. Version: {0}, VersionId: {1}, recursive: {2}, level: {3}", node.Version, node.VersionId, recursive, rebuildLevel))
            {
                using (new Storage.Security.SystemAccount())
                {
                    if (recursive)
                    {
                        using (TreeLock.Acquire(node.Path))
                        {
                            foreach (var n in NodeEnumerator.GetNodes(node.Path))
                            {
                                DataBackingStore.SaveIndexDocument(n, false, false, out _);
                            }
                        }
                    }
                    else
                    {
                        TreeLock.AssertFree(node.Path);
                        DataBackingStore.SaveIndexDocument(node, false, false, out _);
                    }
                }
                op.Successful = true;
            }
        }
Example #4
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);
            });
        }
Example #5
0
        private void RebuildIndex_Recursive(Node node, bool databaseAndIndex)
        {
            using (TreeLock.Acquire(node.Path))
            {
                DeleteTree(node.Path, node.Id);
                if (databaseAndIndex)
                {
                    DataBackingStore.SaveIndexDocument(node, false, false, out _);

                    Parallel.ForEach(NodeQuery.QueryNodesByPath(node.Path, true).Nodes,
                                     n => { DataBackingStore.SaveIndexDocument(n, false, false, out _); });
                }

                AddTree(node.Path, node.Id);
            }
        }
Example #6
0
        private void RebuildIndex_Recursive(Node node, bool databaseAndIndex)
        {
            bool hasBinary;

            using (TreeLock.Acquire(node.Path))
            {
                DeleteTree(node.Path, node.Id, true);
                if (databaseAndIndex)
                {
                    foreach (var n in NodeQuery.QueryNodesByPath(node.Path, true).Nodes)
                    {
                        DataBackingStore.SaveIndexDocument(n, false, false, out hasBinary);
                    }
                }
                PopulateTree(node.Path, node.Id);
            }
        }
Example #7
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"));
                }
            });
        }