public virtual void TestNonexistantFields() { Directory dir = NewDirectory(); RandomIndexWriter iw = new RandomIndexWriter(Random(), dir, Similarity, TimeZone); Document doc = new Document(); iw.AddDocument(doc); DirectoryReader ir = iw.Reader; iw.Dispose(); AtomicReader ar = GetOnlySegmentReader(ir); IFieldCache cache = FieldCache.DEFAULT; cache.PurgeAllCaches(); Assert.AreEqual(0, cache.GetCacheEntries().Length); #pragma warning disable 612, 618 Bytes bytes = cache.GetBytes(ar, "bogusbytes", true); Assert.AreEqual(0, bytes.Get(0)); Int16s shorts = cache.GetInt16s(ar, "bogusshorts", true); Assert.AreEqual(0, shorts.Get(0)); #pragma warning restore 612, 618 Int32s ints = cache.GetInt32s(ar, "bogusints", true); Assert.AreEqual(0, ints.Get(0)); Int64s longs = cache.GetInt64s(ar, "boguslongs", true); Assert.AreEqual(0, longs.Get(0)); Singles floats = cache.GetSingles(ar, "bogusfloats", true); Assert.AreEqual(0, floats.Get(0), 0.0f); Doubles doubles = cache.GetDoubles(ar, "bogusdoubles", true); Assert.AreEqual(0, doubles.Get(0), 0.0D); BytesRef scratch = new BytesRef(); BinaryDocValues binaries = cache.GetTerms(ar, "bogusterms", true); binaries.Get(0, scratch); Assert.AreEqual(0, scratch.Length); SortedDocValues sorted = cache.GetTermsIndex(ar, "bogustermsindex"); Assert.AreEqual(-1, sorted.GetOrd(0)); sorted.Get(0, scratch); Assert.AreEqual(0, scratch.Length); SortedSetDocValues sortedSet = cache.GetDocTermOrds(ar, "bogusmultivalued"); sortedSet.SetDocument(0); Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, sortedSet.NextOrd()); IBits bits = cache.GetDocsWithField(ar, "bogusbits"); Assert.IsFalse(bits.Get(0)); // check that we cached nothing Assert.AreEqual(0, cache.GetCacheEntries().Length); ir.Dispose(); dir.Dispose(); }
public virtual void TestGetDocsWithFieldThreadSafety() { IFieldCache cache = FieldCache.DEFAULT; cache.PurgeAllCaches(); int NUM_THREADS = 3; ThreadClass[] threads = new ThreadClass[NUM_THREADS]; AtomicBoolean failed = new AtomicBoolean(); AtomicInt32 iters = new AtomicInt32(); int NUM_ITER = 200 * RANDOM_MULTIPLIER; Barrier restart = new Barrier(NUM_THREADS, (barrier) => new RunnableAnonymousInnerClassHelper(this, cache, iters).Run()); for (int threadIDX = 0; threadIDX < NUM_THREADS; threadIDX++) { threads[threadIDX] = new ThreadAnonymousInnerClassHelper(this, cache, failed, iters, NUM_ITER, restart); threads[threadIDX].Start(); } for (int threadIDX = 0; threadIDX < NUM_THREADS; threadIDX++) { threads[threadIDX].Join(); } Assert.IsFalse(failed.Get()); }
public virtual void TestDocsWithField() { IFieldCache cache = FieldCache.DEFAULT; cache.PurgeAllCaches(); Assert.AreEqual(0, cache.GetCacheEntries().Length); cache.GetDoubles(Reader, "theDouble", true); // The double[] takes two slots (one w/ null parser, one // w/ real parser), and docsWithField should also // have been populated: Assert.AreEqual(3, cache.GetCacheEntries().Length); IBits bits = cache.GetDocsWithField(Reader, "theDouble"); // No new entries should appear: Assert.AreEqual(3, cache.GetCacheEntries().Length); Assert.IsTrue(bits is Bits.MatchAllBits); Int32s ints = cache.GetInt32s(Reader, "sparse", true); Assert.AreEqual(6, cache.GetCacheEntries().Length); IBits docsWithField = cache.GetDocsWithField(Reader, "sparse"); Assert.AreEqual(6, cache.GetCacheEntries().Length); for (int i = 0; i < docsWithField.Length; i++) { if (i % 2 == 0) { Assert.IsTrue(docsWithField.Get(i)); Assert.AreEqual(i, ints.Get(i)); } else { Assert.IsFalse(docsWithField.Get(i)); } } Int32s numInts = cache.GetInt32s(Reader, "numInt", Random.NextBoolean()); docsWithField = cache.GetDocsWithField(Reader, "numInt"); for (int i = 0; i < docsWithField.Length; i++) { if (i % 2 == 0) { Assert.IsTrue(docsWithField.Get(i)); Assert.AreEqual(i, numInts.Get(i)); } else { Assert.IsFalse(docsWithField.Get(i)); } } }
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(); }
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(); }
public void Run() { Cache.PurgeAllCaches(); Iters.IncrementAndGet(); }