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"); } }
string FindLeaks() { using (var visitor = new FindUnusedKeysVisitor()) { using (var tr = _db.StartReadOnlyTransaction()) { visitor.ImportAllKeys(tr); visitor.Iterate(tr); return DumpUnseenKeys(visitor, " "); } } }
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"); } }
public VisitorForFindUnused(FindUnusedKeysVisitor finder) { _finder = finder; }
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(); }