Skip to content

Commit

Permalink
Test review through TestExceedMaxTermLength; make some static readonl…
Browse files Browse the repository at this point in the history
…y values const
  • Loading branch information
paulirwin committed Nov 10, 2024
1 parent 729b1d1 commit e71ce81
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 249 deletions.
4 changes: 2 additions & 2 deletions src/Lucene.Net.Tests/Index/BinaryTokenStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Lucene.Net.Index
/// A binary tokenstream that lets you index a single
/// binary token (BytesRef value).
/// </summary>
/// <seealso> cref= CannedBinaryTokenStream </seealso>
/// <seealso cref="Lucene.Net.Analysis.CannedBinaryTokenStream" />
public sealed class BinaryTokenStream : TokenStream
{
private readonly IByteTermAttribute bytesAtt;// = addAttribute(typeof(ByteTermAttribute));
Expand Down Expand Up @@ -91,4 +91,4 @@ public override void CopyTo(IAttribute target)
}
}
}
}
}
143 changes: 86 additions & 57 deletions src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs

Large diffs are not rendered by default.

106 changes: 47 additions & 59 deletions src/Lucene.Net.Tests/Index/TestDirectoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using JCG = J2N.Collections.Generic;
using Assert = Lucene.Net.TestFramework.Assert;
using Console = Lucene.Net.Util.SystemConsole;
using Lucene.Net.Support.Threading;

namespace Lucene.Net.Index
{
Expand Down Expand Up @@ -165,7 +164,8 @@ public virtual void TestIsCurrent()
}

/// <summary>
/// Tests the IndexReader.getFieldNames implementation </summary>
/// Tests the IndexReader.getFieldNames implementation
/// </summary>
/// <exception cref="Exception"> on error </exception>
[Test]
public virtual void TestGetFieldNames()
Expand Down Expand Up @@ -318,7 +318,8 @@ public virtual void TestTermVectors()
{
Directory d = NewDirectory();
// set up writer
IndexWriter writer = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(NewLogMergePolicy()));
IndexWriter writer = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetMergePolicy(NewLogMergePolicy()));
// want to get some more segments here
// new termvector fields
int mergeFactor = ((LogMergePolicy)writer.Config.MergePolicy).MergeFactor;
Expand Down Expand Up @@ -349,19 +350,20 @@ public virtual void TestTermVectors()
d.Dispose();
}

internal virtual void AssertTermDocsCount(string msg, IndexReader reader, Term term, int expected)
{
DocsEnum tdocs = TestUtil.Docs(Random, reader, term.Field, new BytesRef(term.Text), MultiFields.GetLiveDocs(reader), null, 0);
int count = 0;
if (tdocs != null)
{
while (tdocs.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
{
count++;
}
}
Assert.AreEqual(expected, count, msg + ", count mismatch");
}
// LUCENENET specific - commented out unused method
// internal virtual void AssertTermDocsCount(string msg, IndexReader reader, Term term, int expected)
// {
// DocsEnum tdocs = TestUtil.Docs(Random, reader, term.Field, new BytesRef(term.Text), MultiFields.GetLiveDocs(reader), null, 0);
// int count = 0;
// if (tdocs != null)
// {
// while (tdocs.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
// {
// count++;
// }
// }
// Assert.AreEqual(expected, count, msg + ", count mismatch");
// }

[Test]
public virtual void TestBinaryFields()
Expand Down Expand Up @@ -448,7 +450,7 @@ public virtual void TestFilesOpenClose()
dir.Dispose();

// Try to erase the data - this ensures that the writer closed all files
System.IO.Directory.Delete(dirFile.FullName, true);
TestUtil.Rm(dirFile);
dir = NewFSDirectory(dirFile);

// Now create the data set again, just as before
Expand All @@ -465,7 +467,7 @@ public virtual void TestFilesOpenClose()

// The following will fail if reader did not close
// all files
System.IO.Directory.Delete(dirFile.FullName, true);
TestUtil.Rm(dirFile);
}

[Test]
Expand Down Expand Up @@ -499,12 +501,7 @@ public virtual void TestOpenReaderAfterDelete()
dir.Dispose();
}

/// <summary>
/// LUCENENET specific
/// Is non-static because NewStringField, NewTextField, NewField methods
/// are no longer static.
/// </summary>
internal void AddDocumentWithFields(IndexWriter writer)
internal static void AddDocumentWithFields(IndexWriter writer)
{
Document doc = new Document();

Expand All @@ -517,12 +514,7 @@ internal void AddDocumentWithFields(IndexWriter writer)
writer.AddDocument(doc);
}

/// <summary>
/// LUCENENET specific
/// Is non-static because NewStringField, NewTextField, NewField methods
/// are no longer static.
/// </summary>
internal void AddDocumentWithDifferentFields(IndexWriter writer)
internal static void AddDocumentWithDifferentFields(IndexWriter writer)
{
Document doc = new Document();

Expand All @@ -535,12 +527,7 @@ internal void AddDocumentWithDifferentFields(IndexWriter writer)
writer.AddDocument(doc);
}

/// <summary>
/// LUCENENET specific
/// Is non-static because NewTextField, NewField methods are no longer
/// static.
/// </summary>
internal void AddDocumentWithTermVectorFields(IndexWriter writer)
internal static void AddDocumentWithTermVectorFields(IndexWriter writer)
{
Document doc = new Document();
FieldType customType5 = new FieldType(TextField.TYPE_STORED);
Expand All @@ -564,11 +551,7 @@ internal void AddDocumentWithTermVectorFields(IndexWriter writer)
writer.AddDocument(doc);
}

/// <summary>
/// LUCENENET specific
/// Is non-static because NewTextField is no longer static.
/// </summary>
internal void AddDoc(IndexWriter writer, string value)
internal static void AddDoc(IndexWriter writer, string value)
{
Document doc = new Document();
doc.Add(NewTextField("content", value, Field.Store.NO));
Expand Down Expand Up @@ -696,7 +679,9 @@ public virtual void TestGetIndexCommit()
Directory d = NewDirectory();

// set up writer
IndexWriter writer = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy(10)));
IndexWriter writer = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetMaxBufferedDocs(2)
.SetMergePolicy(NewLogMergePolicy(10)));
for (int i = 0; i < 27; i++)
{
AddDocumentWithFields(writer);
Expand All @@ -713,7 +698,10 @@ public virtual void TestGetIndexCommit()
Assert.IsTrue(c.Equals(r.IndexCommit));

// Change the index
writer = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.APPEND).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy(10)));
writer = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetOpenMode(OpenMode.APPEND)
.SetMaxBufferedDocs(2)
.SetMergePolicy(NewLogMergePolicy(10)));
for (int i = 0; i < 7; i++)
{
AddDocumentWithFields(writer);
Expand All @@ -726,7 +714,8 @@ public virtual void TestGetIndexCommit()
Assert.IsFalse(r2.IndexCommit.SegmentCount == 1);
r2.Dispose();

writer = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.APPEND));
writer = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetOpenMode(OpenMode.APPEND));
writer.ForceMerge(1);
writer.Dispose();

Expand All @@ -740,7 +729,7 @@ public virtual void TestGetIndexCommit()
d.Dispose();
}

internal Document CreateDocument(string id)
internal static Document CreateDocument(string id)
{
Document doc = new Document();
FieldType customType = new FieldType(TextField.TYPE_STORED);
Expand All @@ -758,7 +747,7 @@ internal Document CreateDocument(string id)
public virtual void TestNoDir()
{
DirectoryInfo tempDir = CreateTempDir("doesnotexist");
System.IO.Directory.Delete(tempDir.FullName, true);
TestUtil.Rm(tempDir);
Directory dir = NewFSDirectory(tempDir);
try
{
Expand All @@ -778,7 +767,8 @@ public virtual void TestNoDupCommitFileNames()
{
Directory dir = NewDirectory();

IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2));
IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetMaxBufferedDocs(2));
writer.AddDocument(CreateDocument("a"));
writer.AddDocument(CreateDocument("a"));
writer.AddDocument(CreateDocument("a"));
Expand Down Expand Up @@ -806,7 +796,8 @@ public virtual void TestNoDupCommitFileNames()
public virtual void TestFieldCacheReuseAfterReopen()
{
Directory dir = NewDirectory();
IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(NewLogMergePolicy(10)));
IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetMergePolicy(NewLogMergePolicy(10)));
Document doc = new Document();
doc.Add(NewStringField("number", "17", Field.Store.NO));
writer.AddDocument(doc);
Expand Down Expand Up @@ -895,7 +886,9 @@ public virtual void TestNoTermsIndex()
}

Assert.AreEqual(-1, ((SegmentReader)r.Leaves[0].Reader).TermInfosIndexDivisor);
writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetCodec(TestUtil.AlwaysPostingsFormat(new Lucene41PostingsFormat())).SetMergePolicy(NewLogMergePolicy(10)));
writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetCodec(TestUtil.AlwaysPostingsFormat(new Lucene41PostingsFormat()))
.SetMergePolicy(NewLogMergePolicy(10)));
writer.AddDocument(doc);
writer.Dispose();

Expand Down Expand Up @@ -950,7 +943,8 @@ public virtual void TestPrepareCommitIsCurrent()
public virtual void TestListCommits()
{
Directory dir = NewDirectory();
IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, null).SetIndexDeletionPolicy(new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy())));
IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, null)
.SetIndexDeletionPolicy(new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy())));
SnapshotDeletionPolicy sdp = (SnapshotDeletionPolicy)writer.Config.IndexDeletionPolicy;
writer.AddDocument(new Document());
writer.Commit();
Expand Down Expand Up @@ -1089,7 +1083,7 @@ public virtual void TestReaderFinishedListener()
writer.Commit();
DirectoryReader reader = writer.GetReader();
int[] closeCount = new int[1];
IReaderDisposedListener listener = new ReaderClosedListenerAnonymousClass(this, reader, closeCount);
IReaderDisposedListener listener = new ReaderClosedListenerAnonymousClass(closeCount);

reader.AddReaderDisposedListener(listener);

Expand All @@ -1110,15 +1104,10 @@ public virtual void TestReaderFinishedListener()

private sealed class ReaderClosedListenerAnonymousClass : IReaderDisposedListener
{
private readonly TestDirectoryReader outerInstance;

private readonly DirectoryReader reader;
private readonly int[] closeCount;

public ReaderClosedListenerAnonymousClass(TestDirectoryReader outerInstance, DirectoryReader reader, int[] closeCount)
public ReaderClosedListenerAnonymousClass(int[] closeCount)
{
this.outerInstance = outerInstance;
this.reader = reader;
this.closeCount = closeCount;
}

Expand Down Expand Up @@ -1249,7 +1238,6 @@ public virtual void TestLoadCertainFields()
dir.Dispose();
}

/// @deprecated just to ensure IndexReader static methods work
[Obsolete("just to ensure IndexReader static methods work")]
[Test]
public virtual void TestBackwards()
Expand Down Expand Up @@ -1321,4 +1309,4 @@ public virtual void TestIndexExistsOnNonExistentDirectory()
dir.Dispose();
}
}
}
}
Loading

0 comments on commit e71ce81

Please sign in to comment.