3 using System
.Collections
;
9 public class SanityCheck
{
11 private SanityCheck () { }
13 static public bool CheckQuery (Beagle
.Query query
, FileModel root
)
15 Hashtable matching_path_hash
;
16 matching_path_hash
= new Hashtable ();
18 foreach (Uri uri
in QueryFu
.GetUris (query
))
19 matching_path_hash
[uri
.LocalPath
] = null;
24 foreach (FileModel file
in root
.GetMatchingDescendants (query
)) {
25 if (! matching_path_hash
.Contains (file
.FullName
)) {
26 Log
.Failure ("Missing match {0}", file
.FullName
);
29 matching_path_hash
.Remove (file
.FullName
);
32 foreach (string path
in matching_path_hash
.Keys
) {
33 Log
.Failure ("Unexpected match {0}", path
);
40 static public bool VerifyIndex (FileModel root
)
42 Log
.Info ("Verifying index for {0}", root
.FullName
);
47 for (int i
= 0; i
< Token
.Count
; ++i
) {
49 query
= QueryFu
.NewTokenQuery (i
);
51 if (! CheckQuery (query
, root
)) {
52 Log
.Spew ("Failed query is:");
53 QueryFu
.SpewQuery (query
);
59 Log
.Info ("Index successfully verified for {0}", root
.FullName
);
61 Log
.Info ("Verification failed for {0}", root
.FullName
);
66 static public bool TestRandomQueries (FileModel root
,
67 double minutes_to_run
)
69 Log
.Info ("Running random queries on {0} for {1:0.0} minutes", root
.FullName
, minutes_to_run
);
75 sw
= new Stopwatch ();
80 if ((count
% 100 == 0) && sw
.ElapsedTime
> minutes_to_run
* 60)
85 query
= QueryFu
.NewRandomQuery ();
87 if (! CheckQuery (query
, root
)) {
88 Log
.Spew ("Failed query is:");
89 QueryFu
.SpewQuery (query
);
95 // In case we ended early
96 minutes_to_run
= sw
.ElapsedTime
/ 60;
98 Log
.Spew ("Ran {0} queries in {1:0.0} minutes ({2:0.0} queries/s)",
99 count
, minutes_to_run
, count
/ (minutes_to_run
* 60));