Skip to content

Commit

Permalink
Test review TestF-TestL, apache#259
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Jan 24, 2024
1 parent a6da17e commit fcbdd92
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 70 deletions.
22 changes: 8 additions & 14 deletions src/Lucene.Net.Tests/Search/TestFieldCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public class TestFieldCache : LuceneTestCase

/// <summary>
/// LUCENENET specific. Ensure we have an infostream attached to the default FieldCache
/// when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream()
/// method (which polluted the state of these tests), but we need to make the tests self-contained
/// when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream()
/// method (which polluted the state of these tests), but we need to make the tests self-contained
/// so they can be run correctly regardless of order. Not setting the InfoStream skips an execution
/// path within these tests, so we should do it to make sure we test all of the code.
/// </summary>
Expand Down Expand Up @@ -488,10 +488,10 @@ public virtual void TestGetDocsWithFieldThreadSafety()
AtomicBoolean failed = new AtomicBoolean();
AtomicInt32 iters = new AtomicInt32();
int NUM_ITER = 200 * RandomMultiplier;
Barrier restart = new Barrier(NUM_THREADS, (barrier) => new RunnableAnonymousClass(this, cache, iters).Run());
Barrier restart = new Barrier(NUM_THREADS, (barrier) => new RunnableAnonymousClass(cache, iters).Run());
for (int threadIDX = 0; threadIDX < NUM_THREADS; threadIDX++)
{
threads[threadIDX] = new ThreadAnonymousClass(this, cache, failed, iters, NUM_ITER, restart);
threads[threadIDX] = new ThreadAnonymousClass(cache, failed, iters, NUM_ITER, restart);
threads[threadIDX].Start();
}

Expand All @@ -504,14 +504,11 @@ public virtual void TestGetDocsWithFieldThreadSafety()

private sealed class RunnableAnonymousClass //: IThreadRunnable
{
private readonly TestFieldCache outerInstance;

private readonly IFieldCache cache;
private readonly AtomicInt32 iters;

public RunnableAnonymousClass(TestFieldCache outerInstance, IFieldCache cache, AtomicInt32 iters)
public RunnableAnonymousClass(IFieldCache cache, AtomicInt32 iters)
{
this.outerInstance = outerInstance;
this.cache = cache;
this.iters = iters;
}
Expand All @@ -525,17 +522,14 @@ public void Run()

private sealed class ThreadAnonymousClass : ThreadJob
{
private readonly TestFieldCache outerInstance;

private readonly IFieldCache cache;
private readonly AtomicBoolean failed;
private readonly AtomicInt32 iters;
private readonly int NUM_ITER;
private readonly Barrier restart;

public ThreadAnonymousClass(TestFieldCache outerInstance, IFieldCache cache, AtomicBoolean failed, AtomicInt32 iters, int NUM_ITER, Barrier restart)
public ThreadAnonymousClass(IFieldCache cache, AtomicBoolean failed, AtomicInt32 iters, int NUM_ITER, Barrier restart)
{
this.outerInstance = outerInstance;
this.cache = cache;
this.failed = failed;
this.iters = iters;
Expand Down Expand Up @@ -744,7 +738,7 @@ public virtual void TestDocValuesIntegration()
bits = FieldCache.DEFAULT.GetDocsWithField(ar, "numeric");
Assert.IsTrue(bits.Get(0));

// SortedSet type: can be retrieved via getDocTermOrds()
// SortedSet type: can be retrieved via getDocTermOrds()
if (DefaultCodecSupportsSortedSet)
{
try
Expand Down Expand Up @@ -1036,4 +1030,4 @@ public virtual void TestIntFieldCache()

}

}
}
8 changes: 4 additions & 4 deletions src/Lucene.Net.Tests/Search/TestFieldCacheRangeFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public class TestFieldCacheRangeFilter : BaseTestRangeFilter
{
/// <summary>
/// LUCENENET specific. Ensure we have an infostream attached to the default FieldCache
/// when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream()
/// method (which polluted the state of these tests), but we need to make the tests self-contained
/// when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream()
/// method (which polluted the state of these tests), but we need to make the tests self-contained
/// so they can be run correctly regardless of order. Not setting the InfoStream skips an execution
/// path within these tests, so we should do it to make sure we test all of the code.
/// </summary>
Expand Down Expand Up @@ -501,7 +501,7 @@ public virtual void TestFieldCacheRangeFilterFloats()

int numDocs = reader.NumDocs;
float minIdO = Convert.ToSingle(minId + .5f);
float medIdO = Convert.ToSingle((float)minIdO + ((maxId - minId)) / 2.0f);
float medIdO = Convert.ToSingle(minIdO + ((maxId - minId)) / 2.0f);

ScoreDoc[] result;
Query q = new TermQuery(new Term("body", "body"));
Expand Down Expand Up @@ -598,4 +598,4 @@ public virtual void TestSparseIndex()
dir.Dispose();
}
}
}
}
12 changes: 6 additions & 6 deletions src/Lucene.Net.Tests/Search/TestFieldCacheRewriteMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public class TestFieldCacheRewriteMethod : TestRegexpRandom2
protected internal override void AssertSame(string regexp)
{
RegexpQuery fieldCache = new RegexpQuery(new Term(fieldName, regexp), RegExpSyntax.NONE);
fieldCache.MultiTermRewriteMethod = (new FieldCacheRewriteMethod());
fieldCache.MultiTermRewriteMethod = new FieldCacheRewriteMethod();

RegexpQuery filter = new RegexpQuery(new Term(fieldName, regexp), RegExpSyntax.NONE);
filter.MultiTermRewriteMethod = (MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
filter.MultiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;

TopDocs fieldCacheDocs = searcher1.Search(fieldCache, 25);
TopDocs filterDocs = searcher2.Search(filter, 25);
Expand All @@ -54,9 +54,9 @@ public virtual void TestEquals()
Assert.AreEqual(a1, a2);
Assert.IsFalse(a1.Equals(b));

a1.MultiTermRewriteMethod = (new FieldCacheRewriteMethod());
a2.MultiTermRewriteMethod = (new FieldCacheRewriteMethod());
b.MultiTermRewriteMethod = (new FieldCacheRewriteMethod());
a1.MultiTermRewriteMethod = new FieldCacheRewriteMethod();
a2.MultiTermRewriteMethod = new FieldCacheRewriteMethod();
b.MultiTermRewriteMethod = new FieldCacheRewriteMethod();
Assert.AreEqual(a1, a2);
Assert.IsFalse(a1.Equals(b));
QueryUtils.Check(a1);
Expand All @@ -79,4 +79,4 @@ public override void TestRegexps()

#endregion
}
}
}
4 changes: 2 additions & 2 deletions src/Lucene.Net.Tests/Search/TestFieldCacheTermsFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Lucene.Net.Search
/// <summary>
/// A basic unit test for FieldCacheTermsFilter
/// </summary>
/// <seealso cref= Lucene.Net.Search.FieldCacheTermsFilter </seealso>
/// <seealso cref="Lucene.Net.Search.FieldCacheTermsFilter" />
[TestFixture]
public class TestFieldCacheTermsFilter : LuceneTestCase
{
Expand Down Expand Up @@ -77,4 +77,4 @@ public virtual void TestMissingTerms()
rd.Dispose();
}
}
}
}
3 changes: 1 addition & 2 deletions src/Lucene.Net.Tests/Search/TestFieldValueFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace Lucene.Net.Search
using RandomIndexWriter = Lucene.Net.Index.RandomIndexWriter;
using Term = Lucene.Net.Index.Term;

///
[TestFixture]
public class TestFieldValueFilter : LuceneTestCase
{
Expand Down Expand Up @@ -124,4 +123,4 @@ private int[] BuildIndex(RandomIndexWriter writer, int docs)
return docStates;
}
}
}
}
42 changes: 7 additions & 35 deletions src/Lucene.Net.Tests/Search/TestFilteredQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Lucene.Net.Search
/// <summary>
/// FilteredQuery JUnit tests.
///
/// <p>Created: Apr 21, 2004 1:21:46 PM
/// Created: Apr 21, 2004 1:21:46 PM
///
///
/// @since 1.4
Expand Down Expand Up @@ -109,10 +109,6 @@ private static Filter NewStaticFilterB()

private sealed class FilterAnonymousClass : Filter
{
public FilterAnonymousClass()
{
}

public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
{
if (acceptDocs is null)
Expand Down Expand Up @@ -212,10 +208,6 @@ private static Filter NewStaticFilterA()

private sealed class FilterAnonymousClass2 : Filter
{
public FilterAnonymousClass2()
{
}

public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
{
Assert.IsNull(acceptDocs, "acceptDocs should be null, as we have an index without deletions");
Expand Down Expand Up @@ -458,10 +450,6 @@ private static FilteredQuery.FilterStrategy RandomFilterStrategy(Random random,

private sealed class RandomAccessFilterStrategyAnonymousClass : FilteredQuery.RandomAccessFilterStrategy
{
public RandomAccessFilterStrategyAnonymousClass()
{
}

protected override bool UseRandomAccess(IBits bits, int firstFilterDoc)
{
return true;
Expand Down Expand Up @@ -495,7 +483,7 @@ public virtual void TestQueryFirstFilterStrategy()
writer.Dispose();

IndexSearcher searcher = NewSearcher(reader);
Query query = new FilteredQuery(new TermQuery(new Term("field", "0")), new FilterAnonymousClass3(this, reader), FilteredQuery.QUERY_FIRST_FILTER_STRATEGY);
Query query = new FilteredQuery(new TermQuery(new Term("field", "0")), new FilterAnonymousClass3(), FilteredQuery.QUERY_FIRST_FILTER_STRATEGY);

TopDocs search = searcher.Search(query, 10);
Assert.AreEqual(totalDocsWithZero, search.TotalHits);
Expand All @@ -504,16 +492,6 @@ public virtual void TestQueryFirstFilterStrategy()

private sealed class FilterAnonymousClass3 : Filter
{
private readonly TestFilteredQuery outerInstance;

private IndexReader reader;

public FilterAnonymousClass3(TestFilteredQuery outerInstance, IndexReader reader)
{
this.outerInstance = outerInstance;
this.reader = reader;
}

public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
{
bool nullBitset = Random.Next(10) == 5;
Expand All @@ -529,20 +507,17 @@ public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDo
{
bitSet.Set(d);
}
return new DocIdSetAnonymousClass(this, nullBitset, reader, bitSet);
return new DocIdSetAnonymousClass(nullBitset, reader, bitSet);
}

private sealed class DocIdSetAnonymousClass : DocIdSet
{
private readonly FilterAnonymousClass3 outerInstance;

private readonly bool nullBitset;
private readonly AtomicReader reader;
private readonly BitSet bitSet;

public DocIdSetAnonymousClass(FilterAnonymousClass3 outerInstance, bool nullBitset, AtomicReader reader, BitSet bitSet)
public DocIdSetAnonymousClass(bool nullBitset, AtomicReader reader, BitSet bitSet)
{
this.outerInstance = outerInstance;
this.nullBitset = nullBitset;
this.reader = reader;
this.bitSet = bitSet;
Expand Down Expand Up @@ -613,7 +588,7 @@ public virtual void TestLeapFrogStrategy()
writer.Dispose();
bool queryFirst = Random.NextBoolean();
IndexSearcher searcher = NewSearcher(reader);
Query query = new FilteredQuery(new TermQuery(new Term("field", "0")), new FilterAnonymousClass4(this, queryFirst), queryFirst ? FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY : Random
Query query = new FilteredQuery(new TermQuery(new Term("field", "0")), new FilterAnonymousClass4(queryFirst), queryFirst ? FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY : Random
.NextBoolean() ? FilteredQuery.RANDOM_ACCESS_FILTER_STRATEGY : FilteredQuery.LEAP_FROG_FILTER_FIRST_STRATEGY); // if filterFirst, we can use random here since bits are null

TopDocs search = searcher.Search(query, 10);
Expand All @@ -623,13 +598,10 @@ public virtual void TestLeapFrogStrategy()

private sealed class FilterAnonymousClass4 : Filter
{
private readonly TestFilteredQuery outerInstance;

private readonly bool queryFirst;

public FilterAnonymousClass4(TestFilteredQuery outerInstance, bool queryFirst)
public FilterAnonymousClass4(bool queryFirst)
{
this.outerInstance = outerInstance;
this.queryFirst = queryFirst;
}

Expand Down Expand Up @@ -701,4 +673,4 @@ public override long GetCost()
}
}
}
}
}
33 changes: 27 additions & 6 deletions src/Lucene.Net.Tests/Search/TestIndexSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,34 @@ public override void TearDown()
[Test]
public virtual void TestHugeN()
{
// LUCENENET: this differs from Java
TaskScheduler service = new LimitedConcurrencyLevelTaskScheduler(4);

IndexSearcher[] searchers = new IndexSearcher[] { new IndexSearcher(reader), new IndexSearcher(reader, service) };
Query[] queries = new Query[] { new MatchAllDocsQuery(), new TermQuery(new Term("field", "1")) };
Sort[] sorts = new Sort[] { null, new Sort(new SortField("field2", SortFieldType.STRING)) };
Filter[] filters = new Filter[] { null, new QueryWrapperFilter(new TermQuery(new Term("field2", "true"))) };
ScoreDoc[] afters = new ScoreDoc[] { null, new FieldDoc(0, 0f, new object[] { new BytesRef("boo!") }) };
IndexSearcher[] searchers = new IndexSearcher[]
{
new IndexSearcher(reader),
new IndexSearcher(reader, service)
};
Query[] queries = new Query[]
{
new MatchAllDocsQuery(),
new TermQuery(new Term("field", "1"))
};
Sort[] sorts = new Sort[]
{
null,
new Sort(new SortField("field2", SortFieldType.STRING))
};
Filter[] filters = new Filter[]
{
null,
new QueryWrapperFilter(new TermQuery(new Term("field2", "true")))
};
ScoreDoc[] afters = new ScoreDoc[]
{
null,
new FieldDoc(0, 0f, new object[] { new BytesRef("boo!") })
};

foreach (IndexSearcher searcher in searchers)
{
Expand Down Expand Up @@ -140,4 +161,4 @@ public virtual void TestSearchAfterPassedMaxDoc()
}
}
}
}
}
5 changes: 4 additions & 1 deletion src/Lucene.Net.Tests/Search/TestLiveFieldValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
using JCG = J2N.Collections.Generic;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;

#if FEATURE_RANDOM_NEXTINT64_NEXTSINGLE
using RandomizedTesting.Generators;
#endif

namespace Lucene.Net.Search
{
Expand Down Expand Up @@ -245,4 +248,4 @@ public override void Run()
}
}
}
}
}

0 comments on commit fcbdd92

Please sign in to comment.