Skip to content

Commit

Permalink
Test review of TestRollingUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Mar 10, 2024
1 parent ab67dbb commit c86c513
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/Lucene.Net.Tests/Index/TestRollingUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ public virtual void TestRollingUpdates_Mem()
LineFileDocs docs = new LineFileDocs(random, DefaultCodecSupportsDocValues);

//provider.register(new MemoryCodec());
if ((!"Lucene3x".Equals(Codec.Default.Name, StringComparison.Ordinal)) && LuceneTestCase.Random.NextBoolean())
if ((!"Lucene3x".Equals(Codec.Default.Name, StringComparison.Ordinal)) && Random.NextBoolean())
{
Codec.Default =
TestUtil.AlwaysPostingsFormat(new MemoryPostingsFormat(LuceneTestCase.Random.nextBoolean(), random.NextSingle()));
TestUtil.AlwaysPostingsFormat(new MemoryPostingsFormat(Random.nextBoolean(), random.NextSingle()));
}

MockAnalyzer analyzer = new MockAnalyzer(LuceneTestCase.Random);
analyzer.MaxTokenLength = TestUtil.NextInt32(LuceneTestCase.Random, 1, IndexWriter.MAX_TERM_LENGTH);
MockAnalyzer analyzer = new MockAnalyzer(Random);
analyzer.MaxTokenLength = TestUtil.NextInt32(Random, 1, IndexWriter.MAX_TERM_LENGTH);

IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
int SIZE = AtLeast(20);
int id = 0;
IndexReader r = null;
IndexSearcher s = null;
int numUpdates = (int)(SIZE * (2 + (TestNightly ? 200 * LuceneTestCase.Random.NextDouble() : 5 * LuceneTestCase.Random.NextDouble())));
int numUpdates = (int)(SIZE * (2 + (TestNightly ? 200 * Random.NextDouble() : 5 * Random.NextDouble())));
if (Verbose)
{
Console.WriteLine("TEST: numUpdates=" + numUpdates);
Expand All @@ -72,7 +72,7 @@ public virtual void TestRollingUpdates_Mem()
// TODO: sometimes update ids not in order...
for (int docIter = 0; docIter < numUpdates; docIter++)
{
Documents.Document doc = docs.NextDoc();
Document doc = docs.NextDoc();
string myID = "" + id;
if (id == SIZE - 1)
{
Expand Down Expand Up @@ -128,14 +128,14 @@ public virtual void TestRollingUpdates_Mem()
w.AddDocument(doc);
}

if (docIter >= SIZE && LuceneTestCase.Random.Next(50) == 17)
if (docIter >= SIZE && Random.Next(50) == 17)
{
if (r != null)
{
r.Dispose();
}

bool applyDeletions = LuceneTestCase.Random.NextBoolean();
bool applyDeletions = Random.NextBoolean();

if (Verbose)
{
Expand Down Expand Up @@ -198,13 +198,14 @@ public virtual void TestUpdateSameDoc()
LineFileDocs docs = new LineFileDocs(Random);
for (int r = 0; r < 3; r++)
{
IndexWriter w = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2));
IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2));
int numUpdates = AtLeast(20);
int numThreads = TestUtil.NextInt32(Random, 2, 6);
IndexingThread[] threads = new IndexingThread[numThreads];
for (int i = 0; i < numThreads; i++)
{
threads[i] = new IndexingThread(docs, w, numUpdates, NewStringField);
threads[i] = new IndexingThread(docs, w, numUpdates);
threads[i].Start();
}

Expand All @@ -229,20 +230,11 @@ internal class IndexingThread : ThreadJob
internal readonly IndexWriter writer;
internal readonly int num;

private readonly Func<string, string, Field.Store, Field> newStringField;

/// <param name="newStringField">
/// LUCENENET specific
/// Passed in because <see cref="LuceneTestCase.NewStringField(string, string, Field.Store)"/>
/// is no longer static.
/// </param>
public IndexingThread(LineFileDocs docs, IndexWriter writer, int num, Func<string, string, Field.Store, Field> newStringField)
: base()
public IndexingThread(LineFileDocs docs, IndexWriter writer, int num)
{
this.docs = docs;
this.writer = writer;
this.num = num;
this.newStringField = newStringField;
}

public override void Run()
Expand All @@ -252,8 +244,8 @@ public override void Run()
DirectoryReader open = null;
for (int i = 0; i < num; i++)
{
Documents.Document doc = new Documents.Document(); // docs.NextDoc();
doc.Add(newStringField("id", "test", Field.Store.NO));
Document doc = new Document(); // docs.NextDoc();
doc.Add(NewStringField("id", "test", Field.Store.NO));
writer.UpdateDocument(new Term("id", "test"), doc);
if (Random.Next(3) == 0)
{
Expand Down Expand Up @@ -282,4 +274,4 @@ public override void Run()
}
}
}
}
}

0 comments on commit c86c513

Please sign in to comment.