Skip to content

Commit

Permalink
Test review of TestStressIndexing2
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Mar 11, 2024
1 parent 836e38e commit 578184f
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions src/Lucene.Net.Tests/Index/TestStressIndexing2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ public class TestStressIndexing2 : LuceneTestCase

public sealed class YieldTestPoint : ITestPoint
{
private readonly TestStressIndexing2 outerInstance;

public YieldTestPoint(TestStressIndexing2 outerInstance)
{
this.outerInstance = outerInstance;
}

public void Apply(string name)
{
// if (name.equals("startCommit")) {
Expand Down Expand Up @@ -156,10 +149,11 @@ public virtual void TestMultiConfig()
}
}

internal static Term idTerm = new Term("id", "");
// internal static Term idTerm = new Term("id", ""); // LUCENENET: unused
internal IndexingThread[] threads;

internal static IComparer<IIndexableField> fieldNameComparer = Comparer<IIndexableField>.Create((o1, o2) => o1.Name.CompareToOrdinal(o2.Name));
internal static IComparer<IIndexableField> fieldNameComparer = Comparer<IIndexableField>.Create((o1, o2) =>
o1.Name.CompareToOrdinal(o2.Name));

// this test avoids using any extra synchronization in the multiple
// indexing threads to test that IndexWriter does correctly synchronize
Expand All @@ -174,7 +168,11 @@ public class DocsAndWriter
public virtual DocsAndWriter IndexRandomIWReader(int nThreads, int iterations, int range, Directory dir)
{
IDictionary<string, Document> docs = new Dictionary<string, Document>();
IndexWriter w = RandomIndexWriter.MockIndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.CREATE).SetRAMBufferSizeMB(0.1).SetMaxBufferedDocs(maxBufferedDocs).SetMergePolicy(NewLogMergePolicy()), new YieldTestPoint(this));
IndexWriter w = RandomIndexWriter.MockIndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetOpenMode(OpenMode.CREATE)
.SetRAMBufferSizeMB(0.1)
.SetMaxBufferedDocs(maxBufferedDocs)
.SetMergePolicy(NewLogMergePolicy()), new YieldTestPoint());
w.Commit();
LogMergePolicy lmp = (LogMergePolicy)w.Config.MergePolicy;
lmp.NoCFSRatio = 0.0;
Expand All @@ -189,7 +187,7 @@ public virtual DocsAndWriter IndexRandomIWReader(int nThreads, int iterations, i
threads = new IndexingThread[nThreads];
for (int i = 0; i < threads.Length; i++)
{
IndexingThread th = new IndexingThread(this);
IndexingThread th = new IndexingThread();
th.w = w;
th.@base = 1000000 * i;
th.range = range;
Expand All @@ -212,7 +210,7 @@ public virtual DocsAndWriter IndexRandomIWReader(int nThreads, int iterations, i
for (int i = 0; i < threads.Length; i++)
{
IndexingThread th = threads[i];
UninterruptableMonitor.Enter(th);
UninterruptableMonitor.Enter(th); // LUCENENET: using UninterruptableMonitor instead of lock/synchronized, see docs for type
try
{
docs.PutAll(th.docs);
Expand All @@ -233,15 +231,21 @@ public virtual DocsAndWriter IndexRandomIWReader(int nThreads, int iterations, i
public virtual IDictionary<string, Document> IndexRandom(int nThreads, int iterations, int range, Directory dir, int maxThreadStates, bool doReaderPooling)
{
IDictionary<string, Document> docs = new Dictionary<string, Document>();
IndexWriter w = RandomIndexWriter.MockIndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.CREATE).SetRAMBufferSizeMB(0.1).SetMaxBufferedDocs(maxBufferedDocs).SetIndexerThreadPool(new DocumentsWriterPerThreadPool(maxThreadStates)).SetReaderPooling(doReaderPooling).SetMergePolicy(NewLogMergePolicy()), new YieldTestPoint(this));
IndexWriter w = RandomIndexWriter.MockIndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
.SetOpenMode(OpenMode.CREATE)
.SetRAMBufferSizeMB(0.1)
.SetMaxBufferedDocs(maxBufferedDocs)
.SetIndexerThreadPool(new DocumentsWriterPerThreadPool(maxThreadStates))
.SetReaderPooling(doReaderPooling)
.SetMergePolicy(NewLogMergePolicy()), new YieldTestPoint());
LogMergePolicy lmp = (LogMergePolicy)w.Config.MergePolicy;
lmp.NoCFSRatio = 0.0;
lmp.MergeFactor = mergeFactor;

threads = new IndexingThread[nThreads];
for (int i = 0; i < threads.Length; i++)
{
IndexingThread th = new IndexingThread(this);
IndexingThread th = new IndexingThread();
th.w = w;
th.@base = 1000000 * i;
th.range = range;
Expand All @@ -264,7 +268,7 @@ public virtual IDictionary<string, Document> IndexRandom(int nThreads, int itera
for (int i = 0; i < threads.Length; i++)
{
IndexingThread th = threads[i];
UninterruptableMonitor.Enter(th);
UninterruptableMonitor.Enter(th); // LUCENENET: using UninterruptableMonitor instead of lock/synchronized, see docs for type
try
{
docs.PutAll(th.docs);
Expand All @@ -281,11 +285,7 @@ public virtual IDictionary<string, Document> IndexRandom(int nThreads, int itera
return docs;
}

/// <summary>
/// LUCENENET specific
/// Is non-static because NewIndexWriterConfig is no longer static.
/// </summary>
public void IndexSerial(Random random, IDictionary<string, Document> docs, Directory dir)
public static void IndexSerial(Random random, IDictionary<string, Document> docs, Directory dir)
{
IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetMergePolicy(NewLogMergePolicy()));

Expand Down Expand Up @@ -559,13 +559,13 @@ public virtual void VerifyEquals(DirectoryReader r1, DirectoryReader r2, string
long[] info1 = new long[r1.NumDocs];
long[] info2 = new long[r2.NumDocs];

for (; ; )
for (;;)
{
BytesRef term1 = null, term2 = null;

// iterate until we get some docs
int len1;
for (; ; )
for (;;)
{
len1 = 0;
if (termsEnum1 is null)
Expand Down Expand Up @@ -608,7 +608,7 @@ public virtual void VerifyEquals(DirectoryReader r1, DirectoryReader r2, string

// iterate until we get some docs
int len2;
for (; ; )
for (;;)
{
len2 = 0;
if (termsEnum2 is null)
Expand Down Expand Up @@ -810,13 +810,6 @@ public static void VerifyEquals(Fields d1, Fields d2)

internal class IndexingThread : ThreadJob
{
private readonly TestStressIndexing2 outerInstance;

public IndexingThread(TestStressIndexing2 outerInstance)
{
this.outerInstance = outerInstance;
}

internal IndexWriter w;
internal int @base;
internal int range;
Expand Down Expand Up @@ -1055,7 +1048,7 @@ public override void Run()
Assert.Fail(e.ToString());
}

UninterruptableMonitor.Enter(this);
UninterruptableMonitor.Enter(this); // LUCENENET: using UninterruptableMonitor instead of lock/synchronized, see docs for type
try
{
int dummy = docs.Count;
Expand All @@ -1067,4 +1060,4 @@ public override void Run()
}
}
}
}
}

0 comments on commit 578184f

Please sign in to comment.