Provides methods for sanity checking that entries in the FieldCache are not wasteful or inconsistent.

Lucene 2.9 Introduced numerous enhancements into how the FieldCache is used by the low levels of Lucene searching (for Sorting and ValueSourceQueries) to improve both the speed for Sorting, as well as reopening of IndexReaders. But these changes have shifted the usage of FieldCache from "top level" IndexReaders (frequently a MultiReader or DirectoryReader) down to the leaf level SegmentReaders. As a result, existing applications that directly access the FieldCache may find RAM usage increase significantly when upgrading to 2.9 or Later. this class provides an API for these applications (or their Unit tests) to check at run time if the FieldCache contains "insane" usages of the FieldCache.

@lucene.experimental
Esempio n. 1
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();
        }
        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();
        }
Esempio n. 3
0
        /// <summary>
        /// Quick and dirty convenience method that instantiates an instance with
        /// "good defaults" and uses it to test the CacheEntrys </summary>
        /// <seealso cref= #check </seealso>
        public static Insanity[] CheckSanity(params FieldCache.CacheEntry[] cacheEntries)
        {
            FieldCacheSanityChecker sanityChecker = new FieldCacheSanityChecker();

            sanityChecker.RamUsageEstimator = true;
            return(sanityChecker.Check(cacheEntries));
        }
        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();
        }
Esempio n. 5
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);
                }
            }
        }
        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();
        }
        /// <summary> Quick and dirty convenience method that instantiates an instance with
        /// "good defaults" and uses it to test the CacheEntrys
        /// </summary>
        /// <seealso cref="Check">
        /// </seealso>
        public static Insanity[] CheckSanity(params CacheEntry[] cacheEntries)
        {
            FieldCacheSanityChecker sanityChecker = new FieldCacheSanityChecker();

            // doesn't check for interned
            sanityChecker.SetRamUsageEstimator(new RamUsageEstimator(false));
            return(sanityChecker.Check(cacheEntries));
        }
Esempio n. 8
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;
             }
         }
     }
 }
        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();
        }
Esempio n. 10
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();
        }
Esempio n. 11
0
		/// <summary> Quick and dirty convenience method that instantiates an instance with 
		/// "good defaults" and uses it to test the CacheEntry[]
		/// </summary>
		/// <seealso cref="check">
		/// </seealso>
		public static Insanity[] CheckSanity(CacheEntry[] cacheEntries)
		{
			FieldCacheSanityChecker sanityChecker = new FieldCacheSanityChecker();
			// doesn't check for interned
			sanityChecker.SetRamUsageEstimator(new RamUsageEstimator(false));
			return sanityChecker.Check(cacheEntries);
		}
Esempio n. 12
0
        public static Insanity[] CheckSanity(params FieldCache.CacheEntry[] cacheEntries)
        {
            FieldCacheSanityChecker sanityChecker = new FieldCacheSanityChecker(estimateRam: true);

            return(sanityChecker.Check(cacheEntries));
        }
 /// <summary>
 /// Quick and dirty convenience method that instantiates an instance with
 /// "good defaults" and uses it to test the CacheEntrys </summary>
 /// <seealso cref= #check </seealso>
 public static Insanity[] CheckSanity(params FieldCache.CacheEntry[] cacheEntries)
 {
     FieldCacheSanityChecker sanityChecker = new FieldCacheSanityChecker();
     sanityChecker.RamUsageEstimator = true;
     return sanityChecker.Check(cacheEntries);
 }