Lucene.Net.Util.LuceneTestCase.AssertSaneFieldCaches C# (CSharp) Method

AssertSaneFieldCaches() protected static method

Asserts that FieldCacheSanityChecker does not detect any problems with FieldCache.DEFAULT.

If any problems are found, they are logged to System.err (allong with the msg) when the Assertion is thrown.

this method is called by tearDown after every test method, however IndexReaders scoped inside test methods may be garbage collected prior to this method being called, causing errors to be overlooked. Tests are encouraged to keep their IndexReaders scoped at the class level, or to explicitly call this method directly in the same scope as the IndexReader.

protected static AssertSaneFieldCaches ( string msg ) : void
msg string
return void
        protected static void AssertSaneFieldCaches(string msg)
        {
            CacheEntry[] entries = FieldCache.DEFAULT.CacheEntries;
            Insanity[] insanity = null;
            try
            {
                try
                {
                    insanity = FieldCacheSanityChecker.CheckSanity(entries);
                }
                catch (Exception e)
                {
                    DumpArray(msg + ": FieldCache", entries, Console.Error);
                    throw e;
                }

                Assert.AreEqual(0, insanity.Length, msg + ": Insane FieldCache usage(s) found");
                insanity = null;
            }
            finally
            {
                // report this in the event of any exception/failure
                // if no failure, then insanity will be null anyway
                if (null != insanity)
                {
                    DumpArray(msg + ": Insane FieldCache usage(s)", insanity, Console.Error);
                }
            }
        }

Usage Example

Example #1
0
            public override void Evaluate()
            {
                s.evaluate();

                Exception problem = null;

                try
                {
                    LuceneTestCase.AssertSaneFieldCaches(d.DisplayName);
                }
                catch (Exception t)
                {
                    problem = t;
                }

                FieldCache.DEFAULT.purgeAllCaches();

                if (problem != null)
                {
                    Rethrow.Rethrow(problem);
                }
            }