3 using System
.Collections
;
4 using System
.Threading
;
11 public class SanityCheck
{
13 const double default_minutes_to_run
= 1.0;
15 private SanityCheck () { }
17 static public bool CheckQuery (Query query
, FileSystemObject root
)
19 // Find the set of objects that we expect to match the query,
20 // based on our knowledge of the current state of the tree.
21 ICollection matching_fsos
;
22 matching_fsos
= root
.RecursiveQuery (query
);
24 // Query the daemon and get the actual list of hits.
25 Hashtable matching_hits
;
26 matching_hits
= QueryFu
.GetHits (query
);
31 foreach (FileSystemObject fso
in matching_fsos
) {
32 if (matching_hits
.Contains (fso
.Uri
))
33 matching_hits
.Remove (fso
.Uri
);
35 Log
.Failure ("Hit missing from beagled query results: {0}", fso
.Uri
);
40 foreach (Hit hit
in matching_hits
.Values
) {
41 Log
.Failure ("Unexpected extra hit in beagled query results: {0}", hit
.Uri
);
42 Log
.Failure (" Properties:");
43 foreach (Property prop
in hit
.Properties
)
44 Log
.Failure (" {0} = {1}", prop
.Key
, prop
.Value
);
51 static public bool VerifyIndex (FileSystemObject root
)
56 Log
.Info ("Verifying index for root {0}", root
.FullName
);
58 for (int i
= 0; i
< Token
.Count
; ++i
) {
60 query
= QueryFu
.NewTokenQuery (i
);
62 if (! CheckQuery (query
, root
)) {
63 Log
.Spew ("Failed query is:");
64 QueryFu
.SpewQuery (query
);
70 Log
.Info ("Index successfully verified");
72 Log
.Info ("Verification failed");
77 static public bool TestRandomQueries (double minutes_to_run
, FileSystemObject root
)
79 if (minutes_to_run
< 0)
80 minutes_to_run
= default_minutes_to_run
;
82 Log
.Info ("Running random queries for {0:0.0} minutes", minutes_to_run
);
88 sw
= new Stopwatch ();
93 if ((count
% 100 == 0) && sw
.ElapsedTime
> minutes_to_run
* 60)
97 if (count
% 1000 == 0)
98 Log
.Spew ("{0} queries run", count
);
101 query
= QueryFu
.NewRandomQuery ();
103 if (! CheckQuery (query
, root
)) {
104 Log
.Spew ("Failed query is:");
105 QueryFu
.SpewQuery (query
);
111 // In case we ended early
112 minutes_to_run
= sw
.ElapsedTime
/ 60;
114 Log
.Spew ("Ran {0} queries in {1:0.0} minutes ({2:0.0} queries/s)",
115 count
, minutes_to_run
, count
/ (minutes_to_run
* 60));