CheckSanity() public static method

Quick and dirty convenience method that instantiates an instance with "good defaults" and uses it to test the CacheEntrys
public static CheckSanity ( ) : Insanity[]
return Insanity[]
コード例 #1
0
        public virtual void  TestSanity()
        {
            FieldCache cache = Lucene.Net.Search.FieldCache_Fields.DEFAULT;

            cache.PurgeAllCaches();

            double[] doubles;
            int[]    ints;

            doubles = cache.GetDoubles(readerA, "theDouble");
            doubles = cache.GetDoubles(readerA, "theDouble", Lucene.Net.Search.FieldCache_Fields.DEFAULT_DOUBLE_PARSER);
            doubles = cache.GetDoubles(readerB, "theDouble", Lucene.Net.Search.FieldCache_Fields.DEFAULT_DOUBLE_PARSER);

            ints = cache.GetInts(readerX, "theInt");
            ints = cache.GetInts(readerX, "theInt", Lucene.Net.Search.FieldCache_Fields.DEFAULT_INT_PARSER);

            // // //

            Insanity[] insanity = FieldCacheSanityChecker.CheckSanity(cache.GetCacheEntries());

            if (0 < insanity.Length)
            {
                System.IO.StreamWriter temp_writer;
                temp_writer           = new System.IO.StreamWriter(System.Console.OpenStandardError(), System.Console.Error.Encoding);
                temp_writer.AutoFlush = true;
                DumpArray(GetTestLabel() + " INSANITY", insanity, temp_writer);
            }

            Assert.AreEqual(0, insanity.Length, "shouldn't be any cache insanity");
            cache.PurgeAllCaches();
        }
コード例 #2
0
        public virtual void TestSanity()
        {
            IFieldCache cache = FieldCache.DEFAULT;

            cache.PurgeAllCaches();

            cache.GetDoubles(ReaderA, "theDouble", false);
#pragma warning disable 612, 618
            cache.GetDoubles(ReaderA, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);
            cache.GetDoubles(ReaderAclone, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);
            cache.GetDoubles(ReaderB, "theDouble", FieldCache.DEFAULT_DOUBLE_PARSER, false);

            cache.GetInt32s(ReaderX, "theInt", false);
            cache.GetInt32s(ReaderX, "theInt", FieldCache.DEFAULT_INT32_PARSER, false);
#pragma warning restore 612, 618

            // // //

            Insanity[] insanity = FieldCacheSanityChecker.CheckSanity(cache.GetCacheEntries());

            if (0 < insanity.Length)
            {
                DumpArray(GetTestClass().Name + "#" + TestName + " INSANITY", insanity, Console.Error);
            }

            Assert.AreEqual(0, insanity.Length, "shouldn't be any cache insanity");
            cache.PurgeAllCaches();
        }
コード例 #3
0
        public virtual void  TestInsanity2()
        {
            FieldCache cache = Lucene.Net.Search.FieldCache_Fields.DEFAULT;

            cache.PurgeAllCaches();

            System.String[] strings;
            sbyte[]         bytes;

            strings = cache.GetStrings(readerA, "theString");
            strings = cache.GetStrings(readerB, "theString");
            strings = cache.GetStrings(readerX, "theString");

            // this one is ok
            bytes = cache.GetBytes(readerX, "theByte");


            // // //

            Insanity[] insanity = FieldCacheSanityChecker.CheckSanity(cache.GetCacheEntries());

            Assert.AreEqual(1, insanity.Length, "wrong number of cache errors");
            Assert.AreEqual(InsanityType.SUBREADER, insanity[0].GetType(), "wrong type of cache error");
            Assert.AreEqual(3, insanity[0].GetCacheEntries().Length, "wrong number of entries in cache error");

            // we expect bad things, don't let tearDown complain about them
            cache.PurgeAllCaches();
        }
コード例 #4
0
        /// <summary> Asserts that FieldCacheSanityChecker does not detect any
        /// problems with FieldCache.DEFAULT.
        /// <p/>
        /// If any problems are found, they are logged to System.err
        /// (allong with the msg) when the Assertion is thrown.
        /// <p/>
        /// 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.
        /// <p/>
        /// </summary>
        /// <seealso cref="FieldCacheSanityChecker">
        /// </seealso>
        protected internal virtual void  AssertSaneFieldCaches(System.String msg)
        {
            CacheEntry[] entries  = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetCacheEntries();
            Insanity[]   insanity = null;
            try
            {
                try
                {
                    insanity = FieldCacheSanityChecker.CheckSanity(entries);
                }
                catch (System.SystemException e)
                {
                    System.IO.StreamWriter temp_writer;
                    temp_writer           = new System.IO.StreamWriter(System.Console.OpenStandardError(), System.Console.Error.Encoding);
                    temp_writer.AutoFlush = true;
                    DumpArray(msg + ": FieldCache", entries, temp_writer);
                    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)
                {
                    System.IO.StreamWriter temp_writer2;
                    temp_writer2           = new System.IO.StreamWriter(System.Console.OpenStandardError(), System.Console.Error.Encoding);
                    temp_writer2.AutoFlush = true;
                    DumpArray(msg + ": Insane FieldCache usage(s)", insanity, temp_writer2);
                }
            }
        }
コード例 #5
0
        public virtual void  TestInsanity1()
        {
            FieldCache cache = Lucene.Net.Search.FieldCache_Fields.DEFAULT;

            cache.PurgeAllCaches();

            int[]           ints;
            System.String[] strings;
            sbyte[]         bytes;

            ints    = cache.GetInts(readerX, "theInt", Lucene.Net.Search.FieldCache_Fields.DEFAULT_INT_PARSER);
            strings = cache.GetStrings(readerX, "theInt");

            // this one is ok
            bytes = cache.GetBytes(readerX, "theByte");

            // // //

            Insanity[] insanity = FieldCacheSanityChecker.CheckSanity(cache.GetCacheEntries());

            Assert.AreEqual(1, insanity.Length, "wrong number of cache errors");
            Assert.AreEqual(InsanityType.VALUEMISMATCH, insanity[0].Type, "wrong type of cache error");
            Assert.AreEqual(2, insanity[0].GetCacheEntries().Length, "wrong number of entries in cache error");

            // we expect bad things, don't let tearDown complain about them
            cache.PurgeAllCaches();
        }
コード例 #6
0
 private void  PrintNewInsanity(System.IO.StreamWriter infoStream, System.Object value_Renamed)
 {
     FieldCacheSanityChecker.Insanity[] insanities = FieldCacheSanityChecker.CheckSanity(wrapper);
     for (int i = 0; i < insanities.Length; i++)
     {
         FieldCacheSanityChecker.Insanity insanity = insanities[i];
         CacheEntry[] entries = insanity.GetCacheEntries();
         for (int j = 0; j < entries.Length; j++)
         {
             if (entries[j].Value == value_Renamed)
             {
                 // OK this insanity involves our entry
                 infoStream.WriteLine("WARNING: new FieldCache insanity created\nDetails: " + insanity.ToString());
                 infoStream.WriteLine("\nStack:\n");
                 infoStream.WriteLine(new System.Exception());
                 break;
             }
         }
     }
 }
コード例 #7
0
        public virtual void TestInsanity1()
        {
            IFieldCache cache = FieldCache.DEFAULT;

            cache.PurgeAllCaches();

            cache.GetInts(ReaderX, "theInt", FieldCache.DEFAULT_INT_PARSER, false);
            cache.GetTerms(ReaderX, "theInt", false);
            cache.GetBytes(ReaderX, "theByte", false);

            // // //

            Insanity[] insanity = FieldCacheSanityChecker.CheckSanity(cache.CacheEntries);

            Assert.AreEqual(1, insanity.Length, "wrong number of cache errors");
            Assert.AreEqual(InsanityType.VALUEMISMATCH, insanity[0].Type, "wrong type of cache error");
            Assert.AreEqual(2, insanity[0].CacheEntries.Length, "wrong number of entries in cache error");

            // we expect bad things, don't let tearDown complain about them
            cache.PurgeAllCaches();
        }
コード例 #8
0
        public virtual void TestInsanity2()
        {
            IFieldCache cache = FieldCache.DEFAULT;

            cache.PurgeAllCaches();

            cache.GetTerms(ReaderA, "theInt", false);
            cache.GetTerms(ReaderB, "theInt", false);
            cache.GetTerms(ReaderX, "theInt", false);
#pragma warning disable 612, 618
            cache.GetBytes(ReaderX, "theByte", false);
#pragma warning restore 612, 618

            // // //

            Insanity[] insanity = FieldCacheSanityChecker.CheckSanity(cache.GetCacheEntries());

            Assert.AreEqual(1, insanity.Length, "wrong number of cache errors");
            Assert.AreEqual(InsanityType.SUBREADER, insanity[0].Type, "wrong type of cache error");
            Assert.AreEqual(3, insanity[0].CacheEntries.Length, "wrong number of entries in cache error");

            // we expect bad things, don't let tearDown complain about them
            cache.PurgeAllCaches();
        }