Skip to content

Commit

Permalink
Test review Core I-J (#926)
Browse files Browse the repository at this point in the history
* Fix static copied methods

* Unify IndexWriterConfig styling in tests

* Clean up conditioned-out code in TestIndexWriterReader

* Replace (MergeTrigger)int.MinValue with MergeTrigger.NONE

* Add LUCENENET to C#-specific comment

* Use invariant culture for number conversion in TestIndexWriterExceptions

* Make IOUtils.CHARSET_UTF_8 not use a BOM; remove obsolete attribute

* Remove using aliases from TestIndexWriterReader

* Add comment explaining MergeTrigger.NONE use

* Use invariant culture for Convert.ToString in TestStressNRT

* Update TestTermsEnum to better match Java code, with fix for MakeIndex

* Other miscellaneous test review, code analysis fixes, and Java-matching for the core I-J tests
  • Loading branch information
paulirwin committed Mar 21, 2024
1 parent 63e1053 commit 444e6d0
Show file tree
Hide file tree
Showing 76 changed files with 1,183 additions and 1,088 deletions.
3 changes: 2 additions & 1 deletion Lucene.Net.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coord/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coord/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=LUCENENET/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
6 changes: 3 additions & 3 deletions src/Lucene.Net.TestFramework/Index/MockRandomMergePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public override MergeSpecification FindForcedMerges(SegmentInfos segmentInfos, i

public override MergeSpecification FindForcedDeletesMerges(SegmentInfos segmentInfos)
{
// LUCENENET specific - just use int.MinValue to indicate "null"
return FindMerges((MergeTrigger)int.MinValue, segmentInfos);
// LUCENENET specific - use NONE instead of null
return FindMerges(MergeTrigger.NONE, segmentInfos);
}

protected override void Dispose(bool disposing)
Expand All @@ -130,4 +130,4 @@ public override bool UseCompoundFile(SegmentInfos infos, SegmentCommitInfo merge
return random.Next(5) != 1;
}
}
}
}
20 changes: 7 additions & 13 deletions src/Lucene.Net.Tests/Index/TestIndexCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public virtual void TestEqualsHashCode()
// LUCENE-2417: equals and hashCode() impl was inconsistent
Directory dir = NewDirectory();

IndexCommit ic1 = new IndexCommitAnonymousClass(this, dir);
IndexCommit ic1 = new IndexCommitAnonymousClass(dir);

IndexCommit ic2 = new IndexCommitAnonymousClass2(this, dir);
IndexCommit ic2 = new IndexCommitAnonymousClass2(dir);

Assert.AreEqual(ic1, ic2);
Assert.AreEqual(ic1.GetHashCode(), ic2.GetHashCode(), "hash codes are not equals");
Expand All @@ -44,13 +44,10 @@ public virtual void TestEqualsHashCode()

private sealed class IndexCommitAnonymousClass : IndexCommit
{
private readonly TestIndexCommit outerInstance;
private readonly Directory dir;

private Directory dir;

public IndexCommitAnonymousClass(TestIndexCommit outerInstance, Directory dir)
public IndexCommitAnonymousClass(Directory dir)
{
this.outerInstance = outerInstance;
this.dir = dir;
}

Expand All @@ -75,13 +72,10 @@ public override void Delete()

private sealed class IndexCommitAnonymousClass2 : IndexCommit
{
private readonly TestIndexCommit outerInstance;

private Directory dir;
private readonly Directory dir;

public IndexCommitAnonymousClass2(TestIndexCommit outerInstance, Directory dir)
public IndexCommitAnonymousClass2(Directory dir)
{
this.outerInstance = outerInstance;
this.dir = dir;
}

Expand All @@ -104,4 +98,4 @@ public override void Delete()
public override int SegmentCount => 2;
}
}
}
}
19 changes: 14 additions & 5 deletions src/Lucene.Net.Tests/Index/TestIndexFileDeleter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ public virtual void TestDeleteLeftoverFiles()
mergePolicy.NoCFSRatio = 1.0;
mergePolicy.MaxCFSSegmentSizeMB = double.PositiveInfinity;

IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(10).SetMergePolicy(mergePolicy).SetUseCompoundFile(true));
IndexWriter writer = new IndexWriter(
dir,
NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).
SetMaxBufferedDocs(10).
SetMergePolicy(mergePolicy).SetUseCompoundFile(true)
);

int i;
for (i = 0; i < 35; i++)
Expand All @@ -75,7 +80,11 @@ public virtual void TestDeleteLeftoverFiles()
writer.Dispose();

// Delete one doc so we get a .del file:
writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(NoMergePolicy.NO_COMPOUND_FILES).SetUseCompoundFile(true));
writer = new IndexWriter(
dir,
NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).
SetMergePolicy(NoMergePolicy.NO_COMPOUND_FILES).SetUseCompoundFile(true)
);
Term searchTerm = new Term("id", "7");
writer.DeleteDocuments(searchTerm);
writer.Dispose();
Expand Down Expand Up @@ -157,7 +166,7 @@ private static ISet<string> DifFiles(string[] files1, string[] files2)
{
set2.Add(files2[x]);
}
IEnumerator<string> i1 = set1.GetEnumerator();
using IEnumerator<string> i1 = set1.GetEnumerator();
while (i1.MoveNext())
{
string o = i1.Current;
Expand All @@ -166,7 +175,7 @@ private static ISet<string> DifFiles(string[] files1, string[] files2)
extra.Add(o);
}
}
IEnumerator<string> i2 = set2.GetEnumerator();
using IEnumerator<string> i2 = set2.GetEnumerator();
while (i2.MoveNext())
{
string o = i2.Current;
Expand Down Expand Up @@ -217,4 +226,4 @@ private void AddDoc(IndexWriter writer, int id)
writer.AddDocument(doc);
}
}
}
}
17 changes: 7 additions & 10 deletions src/Lucene.Net.Tests/Index/TestIndexReaderClose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class TestIndexReaderClose : LuceneTestCase
[Test]
public virtual void TestCloseUnderException()
{
int iters = 1000 + 1 + Random.nextInt(20);
int iters = 1000 + 1 + Random.Next(20);
for (int j = 0; j < iters; j++)
{
Directory dir = NewDirectory();
Expand All @@ -46,7 +46,7 @@ public virtual void TestCloseUnderException()
DirectoryReader open = DirectoryReader.Open(dir);
bool throwOnClose = !Rarely();
AtomicReader wrap = SlowCompositeReaderWrapper.Wrap(open);
FilterAtomicReader reader = new FilterAtomicReaderAnonymousClass(this, wrap, throwOnClose);
FilterAtomicReader reader = new FilterAtomicReaderAnonymousClass(wrap, throwOnClose);
//IList<IReaderDisposedListener> listeners = new JCG.List<IReaderDisposedListener>(); // LUCENENET: This list is unused (and was unused in Java)
int listenerCount = Random.Next(20);
AtomicInt32 count = new AtomicInt32();
Expand Down Expand Up @@ -87,7 +87,7 @@ public virtual void TestCloseUnderException()

try
{
var aaa = reader.Fields;
_ = reader.Fields;
Assert.Fail("we are closed");
}
catch (Exception ex) when (ex.IsAlreadyClosedException())
Expand All @@ -106,14 +106,11 @@ public virtual void TestCloseUnderException()

private sealed class FilterAtomicReaderAnonymousClass : FilterAtomicReader
{
private readonly TestIndexReaderClose outerInstance;
private readonly bool throwOnClose;

private bool throwOnClose;

public FilterAtomicReaderAnonymousClass(TestIndexReaderClose outerInstance, AtomicReader wrap, bool throwOnClose)
public FilterAtomicReaderAnonymousClass(AtomicReader wrap, bool throwOnClose)
: base(wrap)
{
this.outerInstance = outerInstance;
this.throwOnClose = throwOnClose;
}

Expand All @@ -129,7 +126,7 @@ protected internal override void DoClose()

private sealed class CountListener : IReaderDisposedListener
{
internal readonly AtomicInt32 count;
private readonly AtomicInt32 count;

public CountListener(AtomicInt32 count)
{
Expand All @@ -150,4 +147,4 @@ public void OnDispose(IndexReader reader)
}
}
}
}
}
13 changes: 6 additions & 7 deletions src/Lucene.Net.Tests/Index/TestIndexWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ namespace Lucene.Net.Index
[TestFixture]
public class TestIndexWriter : LuceneTestCase
{
private static readonly FieldType storedTextType = new FieldType(TextField.TYPE_NOT_STORED);

#if FEATURE_INDEXWRITER_TESTS
private static readonly FieldType storedTextType = new FieldType(TextField.TYPE_NOT_STORED);

[Test]
public virtual void TestDocCount()
Expand Down Expand Up @@ -155,11 +154,11 @@ public virtual void TestDocCount()

/// <summary>
/// LUCENENET specific
/// Changed from internal static method to private to remove
/// Changed from internal method to private to remove
/// inter-dependencies between TestIndexWriter*.cs, TestAddIndexes.cs
/// and TestDeletionPolicy.cs tests
/// </summary>
private void AddDoc(IndexWriter writer)
private static void AddDoc(IndexWriter writer)
{
Document doc = new Document();
doc.Add(NewTextField("content", "aaa", Field.Store.NO));
Expand All @@ -168,11 +167,11 @@ private void AddDoc(IndexWriter writer)

/// <summary>
/// LUCENENET specific
/// Changed from internal static method to private to remove
/// Changed from internal method to private to remove
/// inter-dependencies between TestIndexWriter*.cs, TestAddIndexes.cs
/// and TestDeletionPolicy.cs tests
/// </summary>
private void AddDocWithIndex(IndexWriter writer, int index)
private static void AddDocWithIndex(IndexWriter writer, int index)
{
Document doc = new Document();
doc.Add(NewField("content", "aaa " + index, storedTextType));
Expand Down Expand Up @@ -2935,4 +2934,4 @@ public virtual void TestClosingNRTReaderDoesNotCorruptYourIndex()
}
#endif
}
}
}

0 comments on commit 444e6d0

Please sign in to comment.