Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Nov 11, 2024
1 parent 636cc32 commit 36bd885
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 93 deletions.
8 changes: 4 additions & 4 deletions src/Lucene.Net.Tests/Index/TestAddIndexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public RunAddIndexesThreads(int numCopy)
}
}

internal void LaunchThreads(int numIter)
internal virtual void LaunchThreads(int numIter)
{
for (int i = 0; i < NUM_THREADS; i++)
{
Expand Down Expand Up @@ -794,21 +794,21 @@ public override void Run()
}
}

internal void JoinThreads()
internal virtual void JoinThreads()
{
for (int i = 0; i < NUM_THREADS; i++)
{
threads[i].Join();
}
}

internal void Close(bool doWait)
internal virtual void Close(bool doWait)
{
didClose = true;
writer2.Dispose(doWait);
}

internal void CloseDir()
internal virtual void CloseDir()
{
for (int i = 0; i < NUM_COPY; i++)
{
Expand Down
38 changes: 29 additions & 9 deletions src/Lucene.Net.Tests/Index/TestBackwardsCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,38 @@ public void testCreateMoreTermsIndex() throws Exception {
*/

internal static readonly string[] oldNames = {
"40.cfs", "40.nocfs", "41.cfs", "41.nocfs", "42.cfs",
"42.nocfs", "45.cfs", "45.nocfs", "461.cfs", "461.nocfs"
"40.cfs",
"40.nocfs",
"41.cfs",
"41.nocfs",
"42.cfs",
"42.nocfs",
"45.cfs",
"45.nocfs",
"461.cfs",
"461.nocfs"
};

internal readonly string[] unsupportedNames = {
"19.cfs", "19.nocfs", "20.cfs", "20.nocfs", "21.cfs",
"21.nocfs", "22.cfs", "22.nocfs", "23.cfs", "23.nocfs",
"24.cfs", "24.nocfs", "29.cfs", "29.nocfs"
"19.cfs",
"19.nocfs",
"20.cfs",
"20.nocfs",
"21.cfs",
"21.nocfs",
"22.cfs",
"22.nocfs",
"23.cfs",
"23.nocfs",
"24.cfs",
"24.nocfs",
"29.cfs",
"29.nocfs"
};

internal static readonly string[] oldSingleSegmentNames = {
"40.optimized.cfs", "40.optimized.nocfs"
"40.optimized.cfs",
"40.optimized.nocfs"
};

internal static IDictionary<string, Directory> oldIndexDirs;
Expand Down Expand Up @@ -299,16 +319,16 @@ public virtual void TestUnsupportedOldIndexes()
writer = null;
}

StringBuilder sb = new StringBuilder(1024);
StringBuilder bos = new StringBuilder(512); // LUCENENET specific: allocating 512 chars instead of 1024 bytes
CheckIndex checker = new CheckIndex(dir);
CheckIndex.Status indexStatus;
using (var infoStream = new StringWriter(sb))
using (var infoStream = new StringWriter(bos))
{
checker.InfoStream = infoStream;
indexStatus = checker.DoCheckIndex();
}
Assert.IsFalse(indexStatus.Clean);
Assert.IsTrue(sb.ToString().Contains(nameof(IndexFormatTooOldException)));
Assert.IsTrue(bos.ToString().Contains(nameof(IndexFormatTooOldException)));

dir.Dispose();
TestUtil.Rm(oldIndxeDir);
Expand Down
32 changes: 25 additions & 7 deletions src/Lucene.Net.Tests/Index/TestBackwardsCompatibility3x.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,36 @@ public void testCreateSingleSegmentNoCFS() throws IOException {
internal const string CURRENT_RESOURCE_DIRECTORY = "Lucene.Net.Tests.Index.";

internal static readonly string[] oldNames = {
"30.cfs", "30.nocfs", "31.cfs", "31.nocfs", "32.cfs",
"32.nocfs", "34.cfs", "34.nocfs"
"30.cfs",
"30.nocfs",
"31.cfs",
"31.nocfs",
"32.cfs",
"32.nocfs",
"34.cfs",
"34.nocfs"
};

internal readonly string[] unsupportedNames = {
"19.cfs", "19.nocfs", "20.cfs", "20.nocfs", "21.cfs",
"21.nocfs", "22.cfs", "22.nocfs", "23.cfs", "23.nocfs",
"24.cfs", "24.nocfs", "29.cfs", "29.nocfs"
"19.cfs",
"19.nocfs",
"20.cfs",
"20.nocfs",
"21.cfs",
"21.nocfs",
"22.cfs",
"22.nocfs",
"23.cfs",
"23.nocfs",
"24.cfs",
"24.nocfs",
"29.cfs",
"29.nocfs"
};

internal static readonly string[] oldSingleSegmentNames = {
"31.optimized.cfs", "31.optimized.nocfs"
"31.optimized.cfs",
"31.optimized.nocfs"
};

internal static IDictionary<string, Directory> oldIndexDirs;
Expand Down Expand Up @@ -232,7 +250,7 @@ public virtual void TestUnsupportedOldIndexes()
writer = null;
}

StringBuilder bos = new StringBuilder();
StringBuilder bos = new StringBuilder(512); // LUCENENET specific: allocating 512 chars instead of 1024 bytes
CheckIndex checker = new CheckIndex(dir);
checker.InfoStream = new StringWriter(bos);
CheckIndex.Status indexStatus = checker.DoCheckIndex();
Expand Down
3 changes: 2 additions & 1 deletion src/Lucene.Net.Tests/Index/TestBinaryDocValuesUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,8 @@ public virtual void TestUpdateOldSegments()
writer = new IndexWriter(dir, conf);
writer.UpdateBinaryDocValue(new Term("id", "doc"), "f", ToBytes(4L));
OldFormatImpersonationIsActive = false;
try {
try
{
writer.Dispose();
Assert.Fail("should not have succeeded to update a segment written with an old Codec");
} catch (Exception e) when (e.IsUnsupportedOperationException()) {
Expand Down
53 changes: 19 additions & 34 deletions src/Lucene.Net.Tests/Index/TestDeletionPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ namespace Lucene.Net.Index
[TestFixture]
public class TestDeletionPolicy : LuceneTestCase
{
private void VerifyCommitOrder<T>(IList<T> commits)
// LUCENENET specific - made static to avoid having to reference the outer class instance
private static void VerifyCommitOrder<T>(IList<T> commits)
where T : IndexCommit
{
if (commits.Count == 0)
Expand All @@ -67,21 +68,18 @@ private void VerifyCommitOrder<T>(IList<T> commits)

internal class KeepAllDeletionPolicy : IndexDeletionPolicy
{
private readonly TestDeletionPolicy outerInstance;

internal int numOnInit;
internal int numOnCommit;
internal Directory dir;

internal KeepAllDeletionPolicy(TestDeletionPolicy outerInstance, Directory dir)
internal KeepAllDeletionPolicy(Directory dir)
{
this.outerInstance = outerInstance;
this.dir = dir;
}

public override void OnInit<T>(IList<T> commits)
{
outerInstance.VerifyCommitOrder(commits);
VerifyCommitOrder(commits);
numOnInit++;
}

Expand All @@ -91,7 +89,7 @@ public override void OnCommit<T>(IList<T> commits)
DirectoryReader r = DirectoryReader.Open(dir);
Assert.AreEqual(r.Leaves.Count, lastCommit.SegmentCount, "lastCommit.segmentCount()=" + lastCommit.SegmentCount + " vs IndexReader.segmentCount=" + r.Leaves.Count);
r.Dispose();
outerInstance.VerifyCommitOrder(commits);
VerifyCommitOrder(commits);
numOnCommit++;
}
}
Expand All @@ -102,19 +100,12 @@ public override void OnCommit<T>(IList<T> commits)
/// </summary>
internal class KeepNoneOnInitDeletionPolicy : IndexDeletionPolicy
{
private readonly TestDeletionPolicy outerInstance;

public KeepNoneOnInitDeletionPolicy(TestDeletionPolicy outerInstance)
{
this.outerInstance = outerInstance;
}

internal int numOnInit;
internal int numOnCommit;

public override void OnInit<T>(IList<T> commits)
{
outerInstance.VerifyCommitOrder(commits);
VerifyCommitOrder(commits);
numOnInit++;
// On init, delete all commit points:
foreach (IndexCommit commit in commits)
Expand All @@ -126,7 +117,7 @@ public override void OnInit<T>(IList<T> commits)

public override void OnCommit<T>(IList<T> commits)
{
outerInstance.VerifyCommitOrder(commits);
VerifyCommitOrder(commits);
int size = commits.Count;
// Delete all but last one:
for (int i = 0; i < size - 1; i++)
Expand All @@ -139,17 +130,14 @@ public override void OnCommit<T>(IList<T> commits)

internal class KeepLastNDeletionPolicy : IndexDeletionPolicy
{
private readonly TestDeletionPolicy outerInstance;

internal int numOnInit;
internal int numOnCommit;
internal int numToKeep;
internal int numDelete;
internal ISet<string> seen = new JCG.HashSet<string>();

public KeepLastNDeletionPolicy(TestDeletionPolicy outerInstance, int numToKeep)
public KeepLastNDeletionPolicy(int numToKeep)
{
this.outerInstance = outerInstance;
this.numToKeep = numToKeep;
}

Expand All @@ -159,7 +147,7 @@ public override void OnInit<T>(IList<T> commits)
{
Console.WriteLine("TEST: onInit");
}
outerInstance.VerifyCommitOrder(commits);
VerifyCommitOrder(commits);
numOnInit++;
// do no deletions on init
DoDeletes(commits, false);
Expand All @@ -171,7 +159,7 @@ public override void OnCommit<T>(IList<T> commits)
{
Console.WriteLine("TEST: onCommit");
}
outerInstance.VerifyCommitOrder(commits);
VerifyCommitOrder(commits);
DoDeletes(commits, true);
}

Expand Down Expand Up @@ -210,15 +198,12 @@ internal static long GetCommitTime(IndexCommit commit)
/// </summary>
internal class ExpirationTimeDeletionPolicy : IndexDeletionPolicy
{
private readonly TestDeletionPolicy outerInstance;

internal Directory dir;
internal double expirationTimeSeconds;
internal int numDelete;

public ExpirationTimeDeletionPolicy(TestDeletionPolicy outerInstance, Directory dir, double seconds)
public ExpirationTimeDeletionPolicy(Directory dir, double seconds)
{
this.outerInstance = outerInstance;
this.dir = dir;
this.expirationTimeSeconds = seconds;
}
Expand All @@ -229,13 +214,13 @@ public override void OnInit<T>(IList<T> commits)
{
return;
}
outerInstance.VerifyCommitOrder(commits);
VerifyCommitOrder(commits);
OnCommit(commits);
}

public override void OnCommit<T>(IList<T> commits)
{
outerInstance.VerifyCommitOrder(commits);
VerifyCommitOrder(commits);

IndexCommit lastCommit = commits[commits.Count - 1];

Expand Down Expand Up @@ -264,7 +249,7 @@ public virtual void TestExpirationTimeDeletionPolicy()

Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetIndexDeletionPolicy(new ExpirationTimeDeletionPolicy(this, dir, SECONDS));
.SetIndexDeletionPolicy(new ExpirationTimeDeletionPolicy(dir, SECONDS));
MergePolicy mp = conf.MergePolicy;
mp.NoCFSRatio = 1.0;
IndexWriter writer = new IndexWriter(dir, conf);
Expand Down Expand Up @@ -363,7 +348,7 @@ public virtual void TestKeepAllDeletionPolicy()
Directory dir = NewDirectory();

IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetIndexDeletionPolicy(new KeepAllDeletionPolicy(this, dir))
.SetIndexDeletionPolicy(new KeepAllDeletionPolicy(dir))
.SetMaxBufferedDocs(10)
.SetMergeScheduler(new SerialMergeScheduler());
MergePolicy mp = conf.MergePolicy;
Expand Down Expand Up @@ -457,7 +442,7 @@ public virtual void TestOpenPriorSnapshot()
Directory dir = NewDirectory();

IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetIndexDeletionPolicy(new KeepAllDeletionPolicy(this, dir))
.SetIndexDeletionPolicy(new KeepAllDeletionPolicy(dir))
.SetMaxBufferedDocs(2)
.SetMergePolicy(NewLogMergePolicy(10)));
KeepAllDeletionPolicy policy = (KeepAllDeletionPolicy)writer.Config.IndexDeletionPolicy;
Expand Down Expand Up @@ -576,7 +561,7 @@ public virtual void TestKeepNoneOnInitDeletionPolicy()

IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetOpenMode(OpenMode.CREATE)
.SetIndexDeletionPolicy(new KeepNoneOnInitDeletionPolicy(this))
.SetIndexDeletionPolicy(new KeepNoneOnInitDeletionPolicy())
.SetMaxBufferedDocs(10);
MergePolicy mp = conf.MergePolicy;
mp.NoCFSRatio = useCompoundFile ? 1.0 : 0.0;
Expand Down Expand Up @@ -626,7 +611,7 @@ public virtual void TestKeepLastNDeletionPolicy()

Directory dir = NewDirectory();

KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(this, N);
KeepLastNDeletionPolicy policy = new KeepLastNDeletionPolicy(N);
for (int j = 0; j < N + 1; j++)
{
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
Expand Down Expand Up @@ -698,7 +683,7 @@ public virtual void TestKeepLastNDeletionPolicyWithCreates()
Directory dir = NewDirectory();
IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetOpenMode(OpenMode.CREATE)
.SetIndexDeletionPolicy(new KeepLastNDeletionPolicy(this, N))
.SetIndexDeletionPolicy(new KeepLastNDeletionPolicy(N))
.SetMaxBufferedDocs(10);
MergePolicy mp = conf.MergePolicy;
mp.NoCFSRatio = useCompoundFile ? 1.0 : 0.0;
Expand Down
15 changes: 1 addition & 14 deletions src/Lucene.Net.Tests/Index/TestDirectoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,7 @@ public virtual void TestTermVectors()
d.Dispose();
}

// 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");
// }
// LUCENENET specific - Removed AssertTermDocsCount() because it was not in use

[Test]
public virtual void TestBinaryFields()
Expand Down
Loading

0 comments on commit 36bd885

Please sign in to comment.