diff --git a/src/Lucene.Net.TestFramework/Support/TestFramework/Assert.cs b/src/Lucene.Net.TestFramework/Support/TestFramework/Assert.cs
index 5e717c59d4..567504d98f 100644
--- a/src/Lucene.Net.TestFramework/Support/TestFramework/Assert.cs
+++ b/src/Lucene.Net.TestFramework/Support/TestFramework/Assert.cs
@@ -930,7 +930,7 @@ public static void IsTrue(bool condition)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void NotNull(object anObject)
{
- if (!(anObject is null))
+ if (anObject is not null)
_NUnit.Assert.NotNull(anObject);
}
//
@@ -973,7 +973,7 @@ public static void NotNull(object anObject, string message, params object[] args
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Null(object anObject, string message, params object[] args)
{
- if (!(anObject is null))
+ if (anObject is not null)
_NUnit.Assert.Null(anObject, message, args);
}
//
@@ -988,7 +988,7 @@ public static void Null(object anObject, string message, params object[] args)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Null(object anObject)
{
- if (!(anObject is null))
+ if (anObject is not null)
_NUnit.Assert.Null(anObject);
}
diff --git a/src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs b/src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs
index 775404ed74..5e3af6de64 100644
--- a/src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs
+++ b/src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs
@@ -5,6 +5,9 @@
using NUnit.Framework;
using System;
using System.Text.RegularExpressions;
+#if !FEATURE_RANDOM_NEXTINT64_NEXTSINGLE
+using RandomizedTesting.Generators;
+#endif
namespace Lucene.Net.Index
{
diff --git a/src/Lucene.Net.Tests/Index/TestFieldInfos.cs b/src/Lucene.Net.Tests/Index/TestFieldInfos.cs
index ea9fb2db09..0a45fd82b9 100644
--- a/src/Lucene.Net.Tests/Index/TestFieldInfos.cs
+++ b/src/Lucene.Net.Tests/Index/TestFieldInfos.cs
@@ -73,7 +73,7 @@ public virtual FieldInfos ReadFieldInfos(Directory dir, string filename)
[Test]
public virtual void Test()
{
- string name = "testFile";
+ const string name = "testFile";
Directory dir = NewDirectory();
FieldInfos fieldInfos = CreateAndWriteFieldInfos(dir, name);
@@ -104,7 +104,7 @@ public virtual void Test()
[Test]
public virtual void TestReadOnly()
{
- string name = "testFile";
+ const string name = "testFile";
Directory dir = NewDirectory();
FieldInfos fieldInfos = CreateAndWriteFieldInfos(dir, name);
FieldInfos readOnly = ReadFieldInfos(dir, name);
@@ -122,4 +122,4 @@ private void AssertReadOnly(FieldInfos readOnly, FieldInfos modifiable)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Index/TestFieldsReader.cs b/src/Lucene.Net.Tests/Index/TestFieldsReader.cs
index 0bca5172b5..23c6030f1a 100644
--- a/src/Lucene.Net.Tests/Index/TestFieldsReader.cs
+++ b/src/Lucene.Net.Tests/Index/TestFieldsReader.cs
@@ -44,10 +44,6 @@ public class TestFieldsReader : LuceneTestCase
private static Document testDoc;
private static FieldInfos.Builder fieldInfos = null;
- ///
- /// LUCENENET specific
- /// Is non-static because NewIndexWriterConfig is no longer static.
- ///
[OneTimeSetUp]
public override void BeforeClass()
{
@@ -283,4 +279,4 @@ public virtual void TestExceptions()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Index/TestFlex.cs b/src/Lucene.Net.Tests/Index/TestFlex.cs
index 0e0d839041..e1a63912e0 100644
--- a/src/Lucene.Net.Tests/Index/TestFlex.cs
+++ b/src/Lucene.Net.Tests/Index/TestFlex.cs
@@ -39,13 +39,16 @@ public virtual void TestNonFlex()
const int DOC_COUNT = 177;
- IndexWriter w = new IndexWriter(d, (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))).SetMaxBufferedDocs(7).SetMergePolicy(NewLogMergePolicy()));
+ IndexWriter w = new IndexWriter(d,
+ new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(7)
+ .SetMergePolicy(NewLogMergePolicy()));
for (int iter = 0; iter < 2; iter++)
{
if (iter == 0)
{
- Documents.Document doc = new Documents.Document();
+ Document doc = new Document();
doc.Add(NewTextField("field1", "this is field1", Field.Store.NO));
doc.Add(NewTextField("field2", "this is field2", Field.Store.NO));
doc.Add(NewTextField("field3", "aaa", Field.Store.NO));
@@ -75,8 +78,9 @@ public virtual void TestNonFlex()
public virtual void TestTermOrd()
{
Directory d = NewDirectory();
- IndexWriter w = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetCodec(TestUtil.AlwaysPostingsFormat(new Lucene41PostingsFormat())));
- Documents.Document doc = new Documents.Document();
+ IndexWriter w = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetCodec(TestUtil.AlwaysPostingsFormat(new Lucene41PostingsFormat())));
+ Document doc = new Document();
doc.Add(NewTextField("f", "a b c", Field.Store.NO));
w.AddDocument(doc);
w.ForceMerge(1);
@@ -96,4 +100,4 @@ public virtual void TestTermOrd()
d.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Index/TestFlushByRamOrCountsPolicy.cs b/src/Lucene.Net.Tests/Index/TestFlushByRamOrCountsPolicy.cs
index 2e39dde683..ad49c21b04 100644
--- a/src/Lucene.Net.Tests/Index/TestFlushByRamOrCountsPolicy.cs
+++ b/src/Lucene.Net.Tests/Index/TestFlushByRamOrCountsPolicy.cs
@@ -43,9 +43,8 @@ namespace Lucene.Net.Index
// LUCENENET specific - Specify to unzip the line file docs
[UseTempLineDocsFile]
[Timeout(900_000)] // 15 minutes
- public class TestFlushByRamOrCountsPolicy : LuceneTestCase
+ public class TestFlushByRamOrCountsPolicy : LuceneTestCase
{
-
private static LineFileDocs lineDocFile;
[OneTimeSetUp]
@@ -95,7 +94,8 @@ protected internal virtual void RunFlushByRam(int numThreads, double maxRamMB, b
MockAnalyzer analyzer = new MockAnalyzer(Random);
analyzer.MaxTokenLength = TestUtil.NextInt32(Random, 1, IndexWriter.MAX_TERM_LENGTH);
- IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetFlushPolicy(flushPolicy);
+ IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer)
+ .SetFlushPolicy(flushPolicy);
int numDWPT = 1 + AtLeast(2);
DocumentsWriterPerThreadPool threadPool = new DocumentsWriterPerThreadPool(numDWPT);
iwc.SetIndexerThreadPool(threadPool);
@@ -156,7 +156,8 @@ public virtual void TestFlushDocCount()
AtomicInt32 numDocs = new AtomicInt32(numDocumentsToIndex);
Directory dir = NewDirectory();
MockDefaultFlushPolicy flushPolicy = new MockDefaultFlushPolicy();
- IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetFlushPolicy(flushPolicy);
+ IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetFlushPolicy(flushPolicy);
int numDWPT = 1 + AtLeast(2);
DocumentsWriterPerThreadPool threadPool = new DocumentsWriterPerThreadPool(numDWPT);
@@ -500,4 +501,4 @@ internal static void FindPending(DocumentsWriterFlushControl flushControl, IList
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Index/TestForTooMuchCloning.cs b/src/Lucene.Net.Tests/Index/TestForTooMuchCloning.cs
index 92498313da..7315fb482a 100644
--- a/src/Lucene.Net.Tests/Index/TestForTooMuchCloning.cs
+++ b/src/Lucene.Net.Tests/Index/TestForTooMuchCloning.cs
@@ -49,7 +49,9 @@ public virtual void Test()
MockDirectoryWrapper dir = NewMockDirectory();
TieredMergePolicy tmp = new TieredMergePolicy();
tmp.MaxMergeAtOnce = 2;
- RandomIndexWriter w = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergePolicy(tmp));
+ RandomIndexWriter w = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(2)
+ .SetMergePolicy(tmp));
const int numDocs = 20;
for (int docs = 0; docs < numDocs; docs++)
{
@@ -84,4 +86,4 @@ public virtual void Test()
dir.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Index/TestForceMergeForever.cs b/src/Lucene.Net.Tests/Index/TestForceMergeForever.cs
index 528abe14bf..0d6ff1ced8 100644
--- a/src/Lucene.Net.Tests/Index/TestForceMergeForever.cs
+++ b/src/Lucene.Net.Tests/Index/TestForceMergeForever.cs
@@ -38,7 +38,7 @@ public class TestForceMergeForever : LuceneTestCase
private class MyIndexWriter : IndexWriter
{
internal AtomicInt32 mergeCount = new AtomicInt32();
- internal bool first;
+ private bool first;
public MyIndexWriter(Directory dir, IndexWriterConfig conf)
: base(dir, conf)
@@ -97,7 +97,7 @@ public virtual void Test()
AtomicBoolean doStop = new AtomicBoolean();
w.Config.SetMaxBufferedDocs(2);
- ThreadJob t = new ThreadAnonymousClass(this, w, numStartDocs, docs, doStop);
+ ThreadJob t = new ThreadAnonymousClass(w, numStartDocs, docs, doStop);
t.Start();
w.ForceMerge(1);
doStop.Value = true;
@@ -110,16 +110,13 @@ public virtual void Test()
private sealed class ThreadAnonymousClass : ThreadJob
{
- private readonly TestForceMergeForever outerInstance;
-
private readonly MyIndexWriter w;
private readonly int numStartDocs;
private readonly LineFileDocs docs;
private readonly AtomicBoolean doStop;
- public ThreadAnonymousClass(TestForceMergeForever outerInstance, Lucene.Net.Index.TestForceMergeForever.MyIndexWriter w, int numStartDocs, LineFileDocs docs, AtomicBoolean doStop)
+ public ThreadAnonymousClass(MyIndexWriter w, int numStartDocs, LineFileDocs docs, AtomicBoolean doStop)
{
- this.outerInstance = outerInstance;
this.w = w;
this.numStartDocs = numStartDocs;
this.docs = docs;
@@ -144,4 +141,4 @@ public override void Run()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs
index 8cf738904c..6143581c95 100644
--- a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs
+++ b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs
@@ -2,7 +2,6 @@
using J2N.Threading;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.TokenAttributes;
-using Lucene.Net.Attributes;
using Lucene.Net.Codecs;
using Lucene.Net.Codecs.SimpleText;
using Lucene.Net.Diagnostics;
@@ -10,7 +9,6 @@
using Lucene.Net.Index.Extensions;
using Lucene.Net.Search;
using Lucene.Net.Support;
-using Lucene.Net.Support.Threading;
using Lucene.Net.Util;
using NUnit.Framework;
using RandomizedTesting.Generators;
@@ -184,7 +182,7 @@ private static void AddDocWithIndex(IndexWriter writer, int index)
public static void AssertNoUnreferencedFiles(Directory dir, string message)
{
string[] startFiles = dir.ListAll();
- (new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)))).Rollback();
+ new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))).Rollback();
string[] endFiles = dir.ListAll();
Array.Sort(startFiles, StringComparer.Ordinal);
@@ -296,7 +294,7 @@ public virtual void TestIndexNoDocuments()
public virtual void TestManyFields()
{
Directory dir = NewDirectory();
- IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(10));
+ IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(10));
for (int j = 0; j < 100; j++)
{
Document doc = new Document();
@@ -329,9 +327,10 @@ public virtual void TestManyFields()
[Test]
public virtual void TestSmallRAMBuffer()
{
-
Directory dir = NewDirectory();
- IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetRAMBufferSizeMB(0.000001).SetMergePolicy(NewLogMergePolicy(10)));
+ IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetRAMBufferSizeMB(0.000001)
+ .SetMergePolicy(NewLogMergePolicy(10)));
int lastNumFile = dir.ListAll().Length;
for (int j = 0; j < 9; j++)
{
@@ -371,8 +370,8 @@ public virtual void TestChangingRAMBuffer()
lastFlushCount = flushCount;
}
else if (j < 10)
- // No new files should be created
{
+ // No new files should be created
Assert.AreEqual(flushCount, lastFlushCount);
}
else if (10 == j)
@@ -518,7 +517,7 @@ public virtual void TestChangingRAMBuffer2()
public virtual void TestDiverseDocs()
{
Directory dir = NewDirectory();
- IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetRAMBufferSizeMB(0.5));
+ IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetRAMBufferSizeMB(0.5));
int n = AtLeast(1);
for (int i = 0; i < n; i++)
{
@@ -576,7 +575,7 @@ public virtual void TestDiverseDocs()
public virtual void TestEnablingNorms()
{
Directory dir = NewDirectory();
- IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(10));
+ IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(10));
// Enable norms for only 1 doc, pre flush
FieldType customType = new FieldType(TextField.TYPE_STORED);
customType.OmitNorms = true;
@@ -605,7 +604,9 @@ public virtual void TestEnablingNorms()
Assert.AreEqual(10, hits.Length);
reader.Dispose();
- writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetOpenMode(OpenMode.CREATE).SetMaxBufferedDocs(10));
+ writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetOpenMode(OpenMode.CREATE)
+ .SetMaxBufferedDocs(10));
// Enable norms for only 1 doc, post flush
for (int j = 0; j < 27; j++)
{
@@ -639,7 +640,7 @@ public virtual void TestEnablingNorms()
public virtual void TestHighFreqTerm()
{
Directory dir = NewDirectory();
- IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetRAMBufferSizeMB(0.01));
+ IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetRAMBufferSizeMB(0.01));
// Massive doc that has 128 K a's
StringBuilder b = new StringBuilder(1024 * 1024);
for (int i = 0; i < 4096; i++)
@@ -719,7 +720,9 @@ public virtual void TestNullLockFactory()
public virtual void TestFlushWithNoMerging()
{
Directory dir = NewDirectory();
- IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy(10)));
+ IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(2)
+ .SetMergePolicy(NewLogMergePolicy(10)));
Document doc = new Document();
FieldType customType = new FieldType(TextField.TYPE_STORED);
customType.StoreTermVectors = true;
@@ -795,7 +798,9 @@ public virtual void TestMaxThreadPriority()
try
{
Directory dir = NewDirectory();
- IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy());
+ IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(2)
+ .SetMergePolicy(NewLogMergePolicy());
((LogMergePolicy)conf.MergePolicy).MergeFactor = 2;
IndexWriter iw = new IndexWriter(dir, conf);
Document document = new Document();
@@ -831,7 +836,7 @@ public virtual void TestVariableSchema()
//lmp.setMergeFactor(2);
//lmp.setNoCFSRatio(0.0);
Document doc = new Document();
- string contents = "aa bb cc dd ee ff gg hh ii jj kk";
+ const string contents = "aa bb cc dd ee ff gg hh ii jj kk";
FieldType customType = new FieldType(TextField.TYPE_STORED);
FieldType type = null;
@@ -1018,7 +1023,7 @@ public virtual void TestDoBeforeAfterFlush()
[Test]
public virtual void TestNegativePositions()
{
- TokenStream tokens = new TokenStreamAnonymousClass(this);
+ TokenStream tokens = new TokenStreamAnonymousClass();
Directory dir = NewDirectory();
IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)));
@@ -1039,11 +1044,8 @@ public virtual void TestNegativePositions()
private sealed class TokenStreamAnonymousClass : TokenStream
{
- private readonly TestIndexWriter outerInstance;
-
- public TokenStreamAnonymousClass(TestIndexWriter outerInstance)
+ public TokenStreamAnonymousClass()
{
- this.outerInstance = outerInstance;
termAtt = AddAttribute();
posIncrAtt = AddAttribute();
terms = new JCG.List { "a", "b", "c" }.GetEnumerator();
@@ -1115,7 +1117,7 @@ public virtual void TestPositionIncrementGapEmptyField()
public virtual void TestDeadlock()
{
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));
Document doc = new Document();
FieldType customType = new FieldType(TextField.TYPE_STORED);
@@ -1151,8 +1153,6 @@ public virtual void TestDeadlock()
private class IndexerThreadInterrupt : ThreadJob
{
- private readonly TestIndexWriter outerInstance;
-
internal volatile bool failed;
internal volatile bool finish;
@@ -1160,9 +1160,8 @@ private class IndexerThreadInterrupt : ThreadJob
internal readonly Random random;
internal readonly Directory adder;
- internal IndexerThreadInterrupt(TestIndexWriter outerInstance)
+ internal IndexerThreadInterrupt()
{
- this.outerInstance = outerInstance;
this.random = new J2N.Randomizer(Random.NextInt64());
// make a little directory for addIndexes
// LUCENE-2239: won't work with NIOFS/MMAP
@@ -1444,7 +1443,7 @@ public override void Run()
///
/// Safely gets the ToString() of an exception while ignoring any System.Threading.ThreadInterruptedException and retrying.
///
- private string GetToStringFrom(Exception exception)
+ private static string GetToStringFrom(Exception exception)
{
// Clear interrupt state:
try
@@ -1471,8 +1470,8 @@ private string GetToStringFrom(Exception exception)
[Ignore("Lucene.NET does not support Thread.Interrupt(). See https://github.com/apache/lucenenet/issues/526.")]
public virtual void TestThreadInterruptDeadlock()
{
- IndexerThreadInterrupt t = new IndexerThreadInterrupt(this);
- t.IsBackground = (true);
+ IndexerThreadInterrupt t = new IndexerThreadInterrupt();
+ t.IsBackground = true;
t.Start();
// Force class loader to load ThreadInterruptedException
@@ -1512,19 +1511,19 @@ public virtual void TestThreadInterruptDeadlock()
[Ignore("Lucene.NET does not support Thread.Interrupt(). See https://github.com/apache/lucenenet/issues/526.")]
public virtual void TestTwoThreadsInterruptDeadlock()
{
- IndexerThreadInterrupt t1 = new IndexerThreadInterrupt(this);
- t1.IsBackground = (true);
+ IndexerThreadInterrupt t1 = new IndexerThreadInterrupt();
+ t1.IsBackground = true;
t1.Start();
- IndexerThreadInterrupt t2 = new IndexerThreadInterrupt(this);
- t2.IsBackground = (true);
+ IndexerThreadInterrupt t2 = new IndexerThreadInterrupt();
+ t2.IsBackground = true;
t2.Start();
// Force class loader to load ThreadInterruptedException
// up front... else we can see a false failure if 2nd
// interrupt arrives while class loader is trying to
// init this class (in servicing a first interrupt):
- Assert.IsTrue((new Util.ThreadInterruptedException(new System.Threading.ThreadInterruptedException())).InnerException is System.Threading.ThreadInterruptedException);
+ Assert.IsTrue(new Util.ThreadInterruptedException(new System.Threading.ThreadInterruptedException()).InnerException is System.Threading.ThreadInterruptedException);
// issue 300 interrupts to child thread
int numInterrupts = AtLeast(300);
@@ -1684,7 +1683,9 @@ public virtual void TestDeleteUnusedFiles()
mergePolicy.NoCFSRatio = 1.0;
mergePolicy.MaxCFSSegmentSizeMB = double.PositiveInfinity;
- IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(mergePolicy).SetUseCompoundFile(true));
+ IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMergePolicy(mergePolicy)
+ .SetUseCompoundFile(true));
Document doc = new Document();
doc.Add(NewTextField("field", "go", Field.Store.NO));
w.AddDocument(doc);
@@ -1776,7 +1777,8 @@ public virtual void TestDeleteUnsedFiles2()
// Validates that iw.DeleteUnusedFiles() also deletes unused index commits
// in case a deletion policy which holds onto commits is used.
Directory dir = NewDirectory();
- IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetIndexDeletionPolicy(new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy())));
+ IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetIndexDeletionPolicy(new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy())));
SnapshotDeletionPolicy sdp = (SnapshotDeletionPolicy)writer.Config.IndexDeletionPolicy;
// First commit
@@ -1818,7 +1820,7 @@ public virtual void TestEmptyFSDirWithNoLock()
// then IndexWriter ctor succeeds. Previously (LUCENE-2386) it failed
// when listAll() was called in IndexFileDeleter.
Directory dir = NewFSDirectory(CreateTempDir("emptyFSDirNoLock"), NoLockFactory.GetNoLockFactory());
- (new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)))).Dispose();
+ new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))).Dispose();
dir.Dispose();
}
@@ -1832,7 +1834,10 @@ public virtual void TestEmptyDirRollback()
// indexed, flushed (but not committed) and then IW rolls back, then no
// files are left in the Directory.
Directory dir = NewDirectory();
- IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergePolicy(NewLogMergePolicy()).SetUseCompoundFile(false));
+ IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(2)
+ .SetMergePolicy(NewLogMergePolicy())
+ .SetUseCompoundFile(false));
string[] files = dir.ListAll();
// Creating over empty dir should not create any files,
@@ -1893,7 +1898,8 @@ public virtual void TestNoSegmentFile()
{
BaseDirectoryWrapper dir = NewDirectory();
dir.SetLockFactory(NoLockFactory.GetNoLockFactory());
- 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));
Document doc = new Document();
FieldType customType = new FieldType(TextField.TYPE_STORED);
@@ -1903,7 +1909,9 @@ public virtual void TestNoSegmentFile()
doc.Add(NewField("c", "val", customType));
w.AddDocument(doc);
w.AddDocument(doc);
- IndexWriter w2 = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetOpenMode(OpenMode.CREATE));
+ IndexWriter w2 = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMaxBufferedDocs(2)
+ .SetOpenMode(OpenMode.CREATE));
w2.Dispose();
// If we don't do that, the test fails on Windows
@@ -2193,9 +2201,7 @@ public virtual void TestWhetherDeleteAllDeletesWriteLock()
new RandomIndexWriter(Random, d, NewIndexWriterConfig(TEST_VERSION_CURRENT, null).SetWriteLockTimeout(100));
Assert.Fail("should not be able to create another writer");
}
-#pragma warning disable 168
- catch (LockObtainFailedException lofe)
-#pragma warning restore 168
+ catch (LockObtainFailedException /*lofe*/)
{
// expected
}
@@ -2299,7 +2305,7 @@ public virtual void TestPrepareCommitThenRollback2()
[Test]
public virtual void TestDontInvokeAnalyzerForUnAnalyzedFields()
{
- Analyzer analyzer = new AnalyzerAnonymousClass(this);
+ Analyzer analyzer = new AnalyzerAnonymousClass();
Directory dir = NewDirectory();
IndexWriter w = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
Document doc = new Document();
@@ -2320,13 +2326,6 @@ public virtual void TestDontInvokeAnalyzerForUnAnalyzedFields()
private sealed class AnalyzerAnonymousClass : Analyzer
{
- private readonly TestIndexWriter outerInstance;
-
- public AnalyzerAnonymousClass(TestIndexWriter outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
protected internal override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
{
throw IllegalStateException.Create("don't invoke me!");
@@ -2443,7 +2442,7 @@ public virtual void TestOtherFiles2()
@out.WriteByte((byte)42);
@out.Dispose();
- (new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)))).Dispose();
+ new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))).Dispose();
Assert.IsTrue(SlowFileExists(dir, "_a.frq"));
@@ -2653,7 +2652,7 @@ public RandomFailingFieldEnumerable(IList> docList,
public virtual IEnumerator> GetEnumerator()
{
- return new EnumeratorAnonymousClass(this, docList.GetEnumerator());
+ return new EnumeratorAnonymousClass(docList.GetEnumerator());
}
IEnumerator IEnumerable.GetEnumerator()
@@ -2663,12 +2662,10 @@ IEnumerator IEnumerable.GetEnumerator()
private sealed class EnumeratorAnonymousClass : IEnumerator>
{
- private readonly RandomFailingFieldEnumerable outerInstance;
private readonly IEnumerator> docIter;
- public EnumeratorAnonymousClass(RandomFailingFieldEnumerable outerInstance, IEnumerator> docIter)
+ public EnumeratorAnonymousClass(IEnumerator> docIter)
{
- this.outerInstance = outerInstance;
this.docIter = docIter;
}
@@ -2729,11 +2726,11 @@ public virtual void TestCorruptFirstCommit()
{
if ((i & 1) == 0)
{
- (new IndexWriter(dir, iwc)).Dispose();
+ new IndexWriter(dir, iwc).Dispose();
}
else
{
- (new IndexWriter(dir, iwc)).Rollback();
+ new IndexWriter(dir, iwc).Rollback();
}
if (mode != 0)
{
@@ -2821,7 +2818,7 @@ public virtual void TestMergeAllDeleted()
Directory dir = NewDirectory();
IndexWriterConfig iwc = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random));
SetOnce iwRef = new SetOnce();
- iwc.SetInfoStream(new TestPointInfoStream(iwc.InfoStream, new TestPointAnonymousClass(this, iwRef)));
+ iwc.SetInfoStream(new TestPointInfoStream(iwc.InfoStream, new TestPointAnonymousClass(iwRef)));
IndexWriter evilWriter = new IndexWriter(dir, iwc);
iwRef.Set(evilWriter);
for (int i = 0; i < 1000; i++)
@@ -2840,13 +2837,10 @@ public virtual void TestMergeAllDeleted()
private sealed class TestPointAnonymousClass : ITestPoint
{
- private readonly TestIndexWriter outerInstance;
-
private SetOnce iwRef;
- public TestPointAnonymousClass(TestIndexWriter outerInstance, SetOnce iwRef)
+ public TestPointAnonymousClass(SetOnce iwRef)
{
- this.outerInstance = outerInstance;
this.iwRef = iwRef;
}
diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterReader.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterReader.cs
index a0e8334f78..617a12bc5e 100644
--- a/src/Lucene.Net.Tests/Index/TestIndexWriterReader.cs
+++ b/src/Lucene.Net.Tests/Index/TestIndexWriterReader.cs
@@ -1,4 +1,5 @@
-using Lucene.Net.Search;
+using Lucene.Net.Attributes;
+using Lucene.Net.Search;
using Lucene.Net.Util;
#if FEATURE_INDEXWRITER_TESTS
using J2N.Threading;
@@ -307,6 +308,7 @@ public virtual void TestAddIndexes()
}
[Test]
+ [LuceneNetSpecific]
public virtual void ExposeCompTermVR()
{
bool doFullMerge = false;
@@ -369,7 +371,7 @@ public virtual void TestDeleteFromIndexWriter()
bool doFullMerge = true;
Directory dir1 = GetAssertNoDeletesDirectory(NewDirectory());
- IndexWriter writer = new IndexWriter(dir1, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetReaderTermsIndexDivisor(2));
+ IndexWriter writer = new IndexWriter(dir1, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetReaderTermsIndexDivisor(2));
// create the index
CreateIndexNoClose(!doFullMerge, "index1", writer);
writer.Flush(false, true);
@@ -506,7 +508,6 @@ internal virtual void JoinThreads()
}
}
-
internal virtual void Close(bool doWait)
{
didClose = true;
@@ -696,9 +697,10 @@ public virtual void DoTestIndexWriterReopenSegment(bool doFullMerge)
* //} //writer.DeleteDocuments(term); td.Dispose(); return doc; }
*/
- public void CreateIndex(Random random, Directory dir1, string indexName, bool multiSegment)
+ public static void CreateIndex(Random random, Directory dir1, string indexName, bool multiSegment)
{
- IndexWriter w = new IndexWriter(dir1, NewIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetMergePolicy(new LogDocMergePolicy()));
+ IndexWriter w = new IndexWriter(dir1, NewIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(random))
+ .SetMergePolicy(new LogDocMergePolicy()));
for (int i = 0; i < 100; i++)
{
w.AddDocument(DocHelper.CreateDocument(i, indexName, 4));
@@ -757,8 +759,7 @@ public virtual void TestMergeWarmer()
((LogMergePolicy)writer.Config.MergePolicy).MergeFactor = 2;
- //int num = AtLeast(100);
- int num = 101;
+ int num = AtLeast(100);
for (int i = 0; i < num; i++)
{
writer.AddDocument(DocHelper.CreateDocument(i, "test", 4));
@@ -769,8 +770,7 @@ public virtual void TestMergeWarmer()
Console.WriteLine("Count {0}", warmer.warmCount);
int count = warmer.warmCount;
- var newDocument = DocHelper.CreateDocument(17, "test", 4);
- writer.AddDocument(newDocument);
+ writer.AddDocument(DocHelper.CreateDocument(17, "test", 4));
writer.ForceMerge(1);
Assert.IsTrue(warmer.warmCount > count);
@@ -886,7 +886,7 @@ public virtual void TestDuringAddIndexes()
for (int i = 0; i < threads.Length; i++)
{
threads[i] = new ThreadAnonymousClass(writer, dirs, endTime, excs);
- threads[i].IsBackground = (true);
+ threads[i].IsBackground = true;
threads[i].Start();
}
@@ -983,7 +983,8 @@ private Directory GetAssertNoDeletesDirectory(Directory directory)
public virtual void TestDuringAddDelete()
{
Directory dir1 = NewDirectory();
- var writer = new IndexWriter(dir1, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(NewLogMergePolicy(2)));
+ var writer = new IndexWriter(dir1, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetMergePolicy(NewLogMergePolicy(2)));
// create the index
CreateIndexNoClose(false, "test", writer);
@@ -1000,7 +1001,7 @@ public virtual void TestDuringAddDelete()
for (int i = 0; i < numThreads; i++)
{
threads[i] = new ThreadAnonymousClass2(writer, endTime, excs);
- threads[i].IsBackground = (true);
+ threads[i].IsBackground = true;
threads[i].Start();
}
@@ -1189,7 +1190,7 @@ public override void Warm(AtomicReader r)
IndexSearcher s = NewSearcher(r);
TopDocs hits = s.Search(new TermQuery(new Term("foo", "bar")), 10);
Assert.AreEqual(20, hits.TotalHits);
- didWarm.Value = (true);
+ didWarm.Value = true;
}
}
@@ -1230,7 +1231,7 @@ public override void Message(string component, string message)
{
if ("SMSW".Equals(component, StringComparison.Ordinal))
{
- didWarm.Value = (true);
+ didWarm.Value = true;
}
}
@@ -1247,7 +1248,8 @@ public virtual void TestNoTermsIndex()
// they're picked.
AssumeFalse("PreFlex codec does not support ReaderTermsIndexDivisor!", "Lucene3x".Equals(Codec.Default.Name, StringComparison.Ordinal));
- IndexWriterConfig conf = (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetReaderTermsIndexDivisor(-1);
+ IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random))
+ .SetReaderTermsIndexDivisor(-1);
// Don't proceed if picked Codec is in the list of illegal ones.
string format = TestUtil.GetPostingsFormat("f");
@@ -1345,14 +1347,12 @@ public virtual void TestNRTOpenExceptions()
// other NRT reader, since it is already marked closed!
for (int i = 0; i < 2; i++)
{
- shouldFail.Value = (true);
+ shouldFail.Value = true;
try
{
writer.GetReader().Dispose();
}
-#pragma warning disable 168
- catch (FakeIOException e)
-#pragma warning restore 168
+ catch (FakeIOException /*e*/)
{
// expected
if (Verbose)
@@ -1384,9 +1384,9 @@ public override void Eval(MockDirectoryWrapper dir)
if (Verbose)
{
Console.WriteLine("TEST: now fail; exc:");
- Console.WriteLine((new Exception()).StackTrace);
+ Console.WriteLine(new Exception().StackTrace);
}
- shouldFail.Value = (false);
+ shouldFail.Value = false;
throw new FakeIOException();
}
}