示例#1
0
        public void FindAndRemovesUnusedKeys()
        {
            StoreJob(1, "Create leak");
            StoreJob(1, "Code");

            using (var visitor = new FindUnusedKeysVisitor())
            {
                using (var tr = _db.StartReadOnlyTransaction())
                {
                    visitor.ImportAllKeys(tr);
                    visitor.Iterate(tr);
                }
                var report = DumpUnseenKeys(visitor, "\r\n");
                Approvals.Verify(report);

                using (var tr = _db.StartTransaction())
                {
                    visitor.DeleteUnused(tr);
                    tr.Commit();
                }
            }
            ReopenDb();
            AssertNoLeaksInDb();
            using (var tr = _db.StartReadOnlyTransaction())
            {
                var jobs = tr.Singleton<JobMap>();
                //check that db has is not broken after removing unused keys
                Assert.Equal(jobs.Jobs[1].Duty.Name, "Code");
            }
        }
示例#2
0
 string FindLeaks()
 {
     using (var visitor = new FindUnusedKeysVisitor())
     {
         using (var tr = _db.StartReadOnlyTransaction())
         {
             visitor.ImportAllKeys(tr);
             visitor.Iterate(tr);
             return DumpUnseenKeys(visitor, " ");
         }
     }
 }
示例#3
0
        public void FindAndRemovesUnusedKeys()
        {
            StoreJobInDictionary("programming", "code");
            StoreJobInDictionary("chess", "mate");
            using (var tr = _db.StartTransaction())
            {
                var sports = tr.Singleton<Directory>();
                sports.Dir["programming"] = new JobMap();
                tr.Commit();
            }

            using (var visitor = new FindUnusedKeysVisitor())
            {
                using (var tr = _db.StartReadOnlyTransaction())
                {
                    visitor.ImportAllKeys(tr);
                    visitor.Iterate(tr);
                }
                var report = DumpUnseenKeys(visitor, "\r\n");
                Approvals.Verify(report);

                using (var tr = _db.StartTransaction())
                {
                    visitor.DeleteUnused(tr);
                    tr.Commit();
                }
            }
            ReopenDb();
            AssertNoLeaksInDb();
            using (var tr = _db.StartReadOnlyTransaction())
            {
                //check that db has is not broken after removing unused keys
                var sports = tr.Singleton<Directory>();
                Assert.Equal(sports.Dir["chess"].Jobs[0].Duty.Name, "mate");
            }
        }
示例#4
0
 public VisitorForFindUnused(FindUnusedKeysVisitor finder)
 {
     _finder = finder;
 }
示例#5
0
 static string DumpUnseenKeys(FindUnusedKeysVisitor visitor, string concat)
 {
     var builder = new StringBuilder();
     foreach (var unseenKey in visitor.UnseenKeys())
     {
         if (builder.Length > 0)
             builder.Append(concat);
         foreach (var b in unseenKey.Key)
             builder.Append(b.ToString("X2"));
         builder.Append(" Value len:");
         builder.Append(unseenKey.ValueSize);
     }
     return builder.ToString();
 }
示例#6
0
 public VisitorForFindUnused(FindUnusedKeysVisitor finder)
 {
     _finder = finder;
 }