From 7a5aa5cc2cfb67377668de649e85590bde99eae1 Mon Sep 17 00:00:00 2001 From: Itamar Syn-Hershko Date: Mon, 5 Jan 2015 15:14:33 +0200 Subject: [PATCH] Minor cleanups --- .../Lucene3x/Lucene3xSegmentInfoReader.cs | 4 +- src/Lucene.Net.Core/Index/IndexWriter.cs | 4 +- src/Lucene.Net.Core/Index/LogMergePolicy.cs | 18 +-- src/Lucene.Net.Core/Index/SegmentInfos.cs | 135 +++++++++--------- .../Support/CollectionsHelper.cs | 7 - .../Support/Compatibility/Collections.cs | 6 + .../Index/BaseStoredFieldsFormatTestCase.cs | 4 +- .../core/Search/TestSubScorerFreqs.cs | 2 +- .../core/Store/TestDirectory.cs | 2 +- .../core/Store/TestFileSwitchDirectory.cs | 4 +- .../core/Store/TestWindowsMMap.cs | 43 +++--- 11 files changed, 113 insertions(+), 116 deletions(-) diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs index 95194898ba..850104867d 100644 --- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs +++ b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs @@ -44,7 +44,7 @@ public class Lucene3xSegmentInfoReader : SegmentInfoReader { public static void ReadLegacyInfos(SegmentInfos infos, Directory directory, IndexInput input, int format) { - infos.Version_Renamed = input.ReadLong(); // read version + infos.Version = input.ReadLong(); // read version infos.Counter = input.ReadInt(); // read counter Lucene3xSegmentInfoReader reader = new Lucene3xSegmentInfoReader(); for (int i = input.ReadInt(); i > 0; i--) // read segmentInfos @@ -98,7 +98,7 @@ public static void ReadLegacyInfos(SegmentInfos infos, Directory directory, Inde infos.Add(siPerCommit); } - infos.UserData_Renamed = input.ReadStringStringMap(); + infos.UserData = input.ReadStringStringMap(); } public override SegmentInfo Read(Directory directory, string segmentName, IOContext context) diff --git a/src/Lucene.Net.Core/Index/IndexWriter.cs b/src/Lucene.Net.Core/Index/IndexWriter.cs index a393fc59fe..2715a2b696 100644 --- a/src/Lucene.Net.Core/Index/IndexWriter.cs +++ b/src/Lucene.Net.Core/Index/IndexWriter.cs @@ -5654,9 +5654,9 @@ internal virtual bool NrtIsCurrent(SegmentInfos infos) EnsureOpen(); if (infoStream.IsEnabled("IW")) { - infoStream.Message("IW", "nrtIsCurrent: infoVersion matches: " + (infos.Version_Renamed == segmentInfos.Version_Renamed) + "; DW changes: " + DocWriter.AnyChanges() + "; BD changes: " + BufferedUpdatesStream.Any()); + infoStream.Message("IW", "nrtIsCurrent: infoVersion matches: " + (infos.Version == segmentInfos.Version) + "; DW changes: " + DocWriter.AnyChanges() + "; BD changes: " + BufferedUpdatesStream.Any()); } - return infos.Version_Renamed == segmentInfos.Version_Renamed && !DocWriter.AnyChanges() && !BufferedUpdatesStream.Any(); + return infos.Version == segmentInfos.Version && !DocWriter.AnyChanges() && !BufferedUpdatesStream.Any(); } } diff --git a/src/Lucene.Net.Core/Index/LogMergePolicy.cs b/src/Lucene.Net.Core/Index/LogMergePolicy.cs index 39cfad1b6e..d661a250e8 100644 --- a/src/Lucene.Net.Core/Index/LogMergePolicy.cs +++ b/src/Lucene.Net.Core/Index/LogMergePolicy.cs @@ -252,7 +252,7 @@ protected internal virtual bool IsMerged(SegmentInfos infos, int maxNumSegments, private MergeSpecification FindForcedMergesSizeLimit(SegmentInfos infos, int maxNumSegments, int last) { MergeSpecification spec = new MergeSpecification(); - List segments = infos.AsList(); + IList segments = infos.AsList(); int start = last - 1; while (start >= 0) @@ -300,8 +300,8 @@ private MergeSpecification FindForcedMergesSizeLimit(SegmentInfos infos, int max /// private MergeSpecification FindForcedMergesMaxNumSegments(SegmentInfos infos, int maxNumSegments, int last) { - MergeSpecification spec = new MergeSpecification(); - List segments = infos.AsList(); + var spec = new MergeSpecification(); + var segments = infos.AsList(); // First, enroll all "full" merges (size // mergeFactor) to potentially be run concurrently: @@ -454,7 +454,7 @@ public override MergeSpecification FindForcedMerges(SegmentInfos infos, int maxN /// public override MergeSpecification FindForcedDeletesMerges(SegmentInfos segmentInfos) { - List segments = segmentInfos.AsList(); + var segments = segmentInfos.AsList(); int numSegments = segments.Count; if (Verbose()) @@ -462,7 +462,7 @@ public override MergeSpecification FindForcedDeletesMerges(SegmentInfos segmentI Message("findForcedDeleteMerges: " + numSegments + " segments"); } - MergeSpecification spec = new MergeSpecification(); + var spec = new MergeSpecification(); int firstSegmentWithDeletions = -1; IndexWriter w = Writer.Get(); Debug.Assert(w != null); @@ -520,9 +520,9 @@ public override MergeSpecification FindForcedDeletesMerges(SegmentInfos segmentI private class SegmentInfoAndLevel : IComparable { - internal SegmentCommitInfo Info; - internal float Level; - internal int Index; + internal readonly SegmentCommitInfo Info; + internal readonly float Level; + private int Index; public SegmentInfoAndLevel(SegmentCommitInfo info, float level, int index) { @@ -558,7 +558,7 @@ public override MergeSpecification FindMerges(MergeTrigger? mergeTrigger, Segmen // Compute levels, which is just log (base mergeFactor) // of the size of each segment IList levels = new List(); - float norm = (float)Math.Log(MergeFactor_Renamed); + var norm = (float)Math.Log(MergeFactor_Renamed); ICollection mergingSegments = Writer.Get().MergingSegments; diff --git a/src/Lucene.Net.Core/Index/SegmentInfos.cs b/src/Lucene.Net.Core/Index/SegmentInfos.cs index 0b0fcb6f85..72ac8eab03 100644 --- a/src/Lucene.Net.Core/Index/SegmentInfos.cs +++ b/src/Lucene.Net.Core/Index/SegmentInfos.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Text; using System.Threading; +using Lucene.Net.Codecs; +using Lucene.Net.Store; namespace Lucene.Net.Index { @@ -139,18 +141,14 @@ public sealed class SegmentInfos : /*List,*/ ICloneable /// Used to name new segments. public int Counter; - /// - /// Counts how often the index has been changed. - public long Version_Renamed; - - private long Generation_Renamed; // generation of the "segments_N" for the next commit - private long LastGeneration_Renamed; // generation of the "segments_N" file we last successfully read + private long _generation; // generation of the "segments_N" for the next commit + private long _lastGeneration; // generation of the "segments_N" file we last successfully read // or wrote; this is normally the same as generation except if // there was an IOException that had interrupted a commit /// /// Opaque Map<String, String> that user can specify during IndexWriter.commit - public IDictionary UserData_Renamed = CollectionsHelper.EmptyMap(); + private IDictionary _userData = CollectionsHelper.EmptyMap(); private List segments = new List(); @@ -191,7 +189,7 @@ public static long GetLastCommitGeneration(string[] files) return -1; } long max = -1; - foreach (string file in files) + foreach (var file in files) { if (file.StartsWith(IndexFileNames.SEGMENTS) && !file.Equals(IndexFileNames.SEGMENTS_GEN)) { @@ -216,7 +214,7 @@ public static long GetLastCommitGeneration(Directory directory) { return GetLastCommitGeneration(directory.ListAll()); } - catch (NoSuchDirectoryException nsde) + catch (NoSuchDirectoryException) { return -1; } @@ -250,7 +248,7 @@ public string SegmentsFileName { get { - return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", LastGeneration_Renamed); + return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", _lastGeneration); } } @@ -300,10 +298,10 @@ public static void WriteSegmentsGen(Directory dir, long generation) finally { genOutput.Dispose(); - dir.Sync(/*CollectionsHelper.Singleton(*/ new[] { IndexFileNames.SEGMENTS_GEN }/*)*/); + dir.Sync(Collections.Singleton(IndexFileNames.SEGMENTS_GEN)); } } - catch (Exception t) + catch (Exception) { // It's OK if we fail to write this file since it's // used only as one of the retry fallbacks. @@ -311,7 +309,7 @@ public static void WriteSegmentsGen(Directory dir, long generation) { dir.DeleteFile(IndexFileNames.SEGMENTS_GEN); } - catch (Exception t2) + catch (Exception) { // Ignore; this file is only used in a retry // fallback on init. @@ -328,13 +326,13 @@ public string NextSegmentFileName { long nextGeneration; - if (Generation_Renamed == -1) + if (_generation == -1) { nextGeneration = 1; } else { - nextGeneration = Generation_Renamed + 1; + nextGeneration = _generation + 1; } return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", nextGeneration); } @@ -355,9 +353,9 @@ public void Read(Directory directory, string segmentFileName) // Clear any previous segments: this.Clear(); - Generation_Renamed = GenerationFromSegmentsFileName(segmentFileName); + _generation = GenerationFromSegmentsFileName(segmentFileName); - LastGeneration_Renamed = Generation_Renamed; + _lastGeneration = _generation; ChecksumIndexInput input = directory.OpenChecksumInput(segmentFileName, IOContext.READ); try @@ -368,19 +366,19 @@ public void Read(Directory directory, string segmentFileName) { // 4.0+ actualFormat = CodecUtil.CheckHeaderNoMagic(input, "segments", VERSION_40, VERSION_48); - Version_Renamed = input.ReadLong(); + Version = input.ReadLong(); Counter = input.ReadInt(); int numSegments = input.ReadInt(); if (numSegments < 0) { throw new CorruptIndexException("invalid segment count: " + numSegments + " (resource: " + input + ")"); } - for (int seg = 0; seg < numSegments; seg++) + for (var seg = 0; seg < numSegments; seg++) { - string segName = input.ReadString(); - Codec codec = Codec.ForName(input.ReadString()); + var segName = input.ReadString(); + var codec = Codec.ForName(input.ReadString()); //System.out.println("SIS.read seg=" + seg + " codec=" + codec); - SegmentInfo info = codec.SegmentInfoFormat().SegmentInfoReader.Read(directory, segName, IOContext.READ); + var info = codec.SegmentInfoFormat().SegmentInfoReader.Read(directory, segName, IOContext.READ); info.Codec = codec; long delGen = input.ReadLong(); int delCount = input.ReadInt(); @@ -393,7 +391,7 @@ public void Read(Directory directory, string segmentFileName) { fieldInfosGen = input.ReadLong(); } - SegmentCommitInfo siPerCommit = new SegmentCommitInfo(info, delCount, delGen, fieldInfosGen); + var siPerCommit = new SegmentCommitInfo(info, delCount, delGen, fieldInfosGen); if (actualFormat >= VERSION_46) { int numGensUpdatesFiles = input.ReadInt(); @@ -414,7 +412,7 @@ public void Read(Directory directory, string segmentFileName) } Add(siPerCommit); } - UserData_Renamed = input.ReadStringStringMap(); + _userData = input.ReadStringStringMap(); } else { @@ -466,7 +464,7 @@ public void Read(Directory directory, string segmentFileName) /// public void Read(Directory directory) { - Generation_Renamed = LastGeneration_Renamed = -1; + _generation = _lastGeneration = -1; new FindSegmentsFileAnonymousInnerClassHelper(this, directory).Run(); } @@ -475,7 +473,7 @@ private class FindSegmentsFileAnonymousInnerClassHelper : FindSegmentsFile { private readonly SegmentInfos OuterInstance; - private new Directory Directory; + private new readonly Directory Directory; public FindSegmentsFileAnonymousInnerClassHelper(SegmentInfos outerInstance, Directory directory) : base(directory) @@ -503,25 +501,25 @@ private void Write(Directory directory) string segmentsFileName = NextSegmentFileName; // Always advance the generation on write: - if (Generation_Renamed == -1) + if (_generation == -1) { - Generation_Renamed = 1; + _generation = 1; } else { - Generation_Renamed++; + _generation++; } IndexOutput segnOutput = null; bool success = false; - HashSet upgradedSIFiles = new HashSet(); + var upgradedSIFiles = new HashSet(); try { segnOutput = directory.CreateOutput(segmentsFileName, IOContext.DEFAULT); CodecUtil.WriteHeader(segnOutput, "segments", VERSION_48); - segnOutput.WriteLong(Version_Renamed); + segnOutput.WriteLong(Version); segnOutput.WriteInt(Counter); // write counter segnOutput.WriteInt(Size()); // write infos foreach (SegmentCommitInfo siPerCommit in segments) @@ -575,11 +573,11 @@ private void Write(Directory directory) @out.Dispose(); } upgradedSIFiles.Add(markerFileName); - directory.Sync(/*Collections.singletonList(*/new[] { markerFileName }/*)*/); + directory.Sync(/*Collections.SingletonList(*/new[] { markerFileName }/*)*/); } } } - segnOutput.WriteStringStringMap(UserData_Renamed); + segnOutput.WriteStringStringMap(_userData); PendingSegnOutput = segnOutput; success = true; } @@ -597,7 +595,7 @@ private void Write(Directory directory) { directory.DeleteFile(fileName); } - catch (Exception t) + catch (Exception) { // Suppress so we keep throwing the original exception } @@ -609,7 +607,7 @@ private void Write(Directory directory) // the index: directory.DeleteFile(segmentsFileName); } - catch (Exception t) + catch (Exception) { // Suppress so we keep throwing the original exception } @@ -630,7 +628,7 @@ private static bool SegmentWasUpgraded(Directory directory, SegmentInfo si) return true; } } - catch (IOException ioe) + catch (IOException) { // Ignore: if something is wrong w/ the marker file, // we will just upgrade again @@ -705,7 +703,7 @@ public static string Write3xInfo(Directory dir, SegmentInfo si, IOContext contex public object Clone() { - SegmentInfos sis = (SegmentInfos)base.MemberwiseClone(); + var sis = (SegmentInfos)base.MemberwiseClone(); // deep clone, first recreate all collections: sis.segments = new List(Size()); foreach (SegmentCommitInfo info in segments) @@ -714,7 +712,7 @@ public object Clone() // dont directly access segments, use add method!!! sis.Add((SegmentCommitInfo)(info.Clone())); } - sis.UserData_Renamed = new Dictionary(UserData_Renamed); + sis._userData = new Dictionary(_userData); return sis; } @@ -723,16 +721,11 @@ public List Segments get { return segments; } } + /// - /// version number when this SegmentInfos was generated. + /// Counts how often the index has been changed. /// - public long Version - { - get - { - return Version_Renamed; - } - } + public long Version { get; set; } /// /// Returns current generation. @@ -740,7 +733,7 @@ public long Generation { get { - return Generation_Renamed; + return _generation; } } @@ -750,7 +743,7 @@ public long LastGeneration { get { - return LastGeneration_Renamed; + return _lastGeneration; } } @@ -1116,8 +1109,8 @@ public virtual object Run(IndexCommit commit) // Carry over generation numbers from another SegmentInfos internal void UpdateGeneration(SegmentInfos other) { - LastGeneration_Renamed = other.LastGeneration_Renamed; - Generation_Renamed = other.Generation_Renamed; + _lastGeneration = other._lastGeneration; + _generation = other._generation; } internal void RollbackCommit(Directory dir) @@ -1131,7 +1124,7 @@ internal void RollbackCommit(Directory dir) // Must carefully compute fileName from "generation" // since lastGeneration isn't incremented: - string segmentFileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", Generation_Renamed); + string segmentFileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", _generation); // Suppress so we keep throwing the original exception // in our caller IOUtils.DeleteFilesIgnoringExceptions(dir, segmentFileName); @@ -1168,7 +1161,7 @@ internal void PrepareCommit(Directory dir) /// public ICollection Files(Directory dir, bool includeSegmentsFile) { - HashSet files = new HashSet(); + var files = new HashSet(); if (includeSegmentsFile) { string segmentFileName = SegmentsFileName; @@ -1177,10 +1170,10 @@ public ICollection Files(Directory dir, bool includeSegmentsFile) files.Add(segmentFileName); } } - int size = Size(); + var size = Size(); for (int i = 0; i < size; i++) { - SegmentCommitInfo info = Info(i); + var info = Info(i); Debug.Assert(info.Info.Dir == dir); if (info.Info.Dir == dir) { @@ -1243,11 +1236,11 @@ internal void FinishCommit(Directory dir) // logic in SegmentInfos to kick in and load the last // good (previous) segments_N-1 file. - string fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", Generation_Renamed); + var fileName = IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", _generation); success = false; try { - dir.Sync(/*Collections.singleton(*/new[] { fileName }/*)*/); + dir.Sync(Collections.Singleton(fileName)); success = true; } finally @@ -1258,15 +1251,15 @@ internal void FinishCommit(Directory dir) { dir.DeleteFile(fileName); } - catch (Exception t) + catch (Exception) { // Suppress so we keep throwing the original exception } } } - LastGeneration_Renamed = Generation_Renamed; - WriteSegmentsGen(dir, Generation_Renamed); + _lastGeneration = _generation; + WriteSegmentsGen(dir, _generation); } /// @@ -1288,7 +1281,7 @@ internal void Commit(Directory dir) /// Returns readable description of this segment. public string ToString(Directory directory) { - StringBuilder buffer = new StringBuilder(); + var buffer = new StringBuilder(); buffer.Append(SegmentsFileName).Append(": "); int count = Size(); for (int i = 0; i < count; i++) @@ -1311,17 +1304,17 @@ public IDictionary UserData { get { - return UserData_Renamed; + return _userData; } set { if (value == null) { - UserData_Renamed = CollectionsHelper.EmptyMap(); + _userData = CollectionsHelper.EmptyMap(); } else { - UserData_Renamed = value; + _userData = value; } } } @@ -1334,7 +1327,7 @@ public IDictionary UserData internal void Replace(SegmentInfos other) { RollbackSegmentInfos(other.AsList()); - LastGeneration_Renamed = other.LastGeneration_Renamed; + _lastGeneration = other._lastGeneration; } /// @@ -1352,14 +1345,14 @@ public int TotalDocCount() /// public void Changed() { - Version_Renamed++; + Version++; } /// /// applies all changes caused by committing a merge to this SegmentInfos internal void ApplyMergeChanges(MergePolicy.OneMerge merge, bool dropSegment) { - HashSet mergedAway = new HashSet(merge.Segments); + var mergedAway = new HashSet(merge.Segments); bool inserted = false; int newSegIdx = 0; for (int segIdx = 0, cnt = segments.Count; segIdx < cnt; segIdx++) @@ -1398,8 +1391,8 @@ internal void ApplyMergeChanges(MergePolicy.OneMerge merge, bool dropSegment) internal IList CreateBackupSegmentInfos() { - IList list = new List(Size()); - foreach (SegmentCommitInfo info in segments) + var list = new List(Size()); + foreach (var info in segments) { Debug.Assert(info.Info.Codec != null); list.Add((SegmentCommitInfo)(info.Clone())); @@ -1415,9 +1408,9 @@ internal void RollbackSegmentInfos(IList infos) /// /// Returns all contained segments as an unmodifiable view. - public List AsList() + public IList AsList() { - return /*Collections.unmodifiableList*/(segments); + return Collections.UnmodifiableList(segments.ToArray()); } /// @@ -1438,7 +1431,7 @@ public void Add(SegmentCommitInfo si) /// Appends the provided s. public void AddAll(IEnumerable sis) { - foreach (SegmentCommitInfo si in sis) + foreach (var si in sis) { this.Add(si); } diff --git a/src/Lucene.Net.Core/Support/CollectionsHelper.cs b/src/Lucene.Net.Core/Support/CollectionsHelper.cs index ae79001dcf..1a230d35a1 100644 --- a/src/Lucene.Net.Core/Support/CollectionsHelper.cs +++ b/src/Lucene.Net.Core/Support/CollectionsHelper.cs @@ -217,13 +217,6 @@ public static bool CompareStringArrays(System.String[] l1, System.String[] l2) return true; } - public static ISet Singleton(T single) - { - T[] singletonArr = new T[] { single }; - HashSet singleton = new HashSet(singletonArr); - return singleton; - } - /// /// Fills the array with an specific value from an specific index to an specific index. /// diff --git a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs index 8c8a53ee49..5a54f490eb 100644 --- a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs +++ b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Collections.Immutable; +using System.Linq; namespace Lucene.Net { @@ -14,5 +15,10 @@ public static IList EmptyList() { return ImmutableList.Empty; } + + public static IList UnmodifiableList(IEnumerable items) + { + return ImmutableList.Create(items.ToArray()); + } } } diff --git a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs index 7062269cc3..ac3613f7f9 100644 --- a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs +++ b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs @@ -401,9 +401,9 @@ public void TestReadSkip() foreach (Field fld in fields) { string fldName = fld.Name(); - Document sDoc = reader.Document(docID, CollectionsHelper.Singleton(fldName)); + Document sDoc = reader.Document(docID, Collections.Singleton(fldName)); IndexableField sField = sDoc.GetField(fldName); - if (typeof(Field).Equals(fld.GetType())) + if (typeof(Field) == fld.GetType()) { Assert.AreEqual(fld.BinaryValue(), sField.BinaryValue()); Assert.AreEqual(fld.StringValue, sField.StringValue); diff --git a/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs b/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs index ce857e3a16..451108c7ca 100644 --- a/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs +++ b/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs @@ -180,7 +180,7 @@ public virtual void TestBooleanQuery() // Only needed in Java6; Java7+ has a @SafeVarargs annotated Arrays#asList()! // see http://docs.oracle.com/javase/7/docs/api/java/lang/SafeVarargs.html - IEnumerable> occurList = Arrays.AsList(CollectionsHelper.Singleton("MUST"), new HashSet(Arrays.AsList("MUST", "SHOULD"))); + IEnumerable> occurList = Arrays.AsList(Collections.Singleton("MUST"), new HashSet(Arrays.AsList("MUST", "SHOULD"))); foreach (HashSet occur in occurList) { diff --git a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs index 862d3d198d..ecc0b31bfe 100644 --- a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs +++ b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs @@ -385,7 +385,7 @@ public virtual void TestFsyncDoesntCreateNewFiles() // fsync it try { - fsdir.Sync(CollectionsHelper.Singleton("afile")); + fsdir.Sync(Collections.Singleton("afile")); Assert.Fail("didn't get expected exception, instead fsync created new files: " + Arrays.AsList(fsdir.ListAll())); } diff --git a/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs index fb71235f92..4f3b7738be 100644 --- a/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs +++ b/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs @@ -147,8 +147,8 @@ public virtual void TestDirectoryFilter() [Test] public virtual void TestCompoundFileAppendTwice() { - Directory newDir = NewFSSwitchDirectory(CollectionsHelper.Singleton("cfs")); - CompoundFileDirectory csw = new CompoundFileDirectory(newDir, "d.cfs", NewIOContext(Random()), true); + Directory newDir = NewFSSwitchDirectory(Collections.Singleton("cfs")); + var csw = new CompoundFileDirectory(newDir, "d.cfs", NewIOContext(Random()), true); CreateSequenceFile(newDir, "d1", (sbyte)0, 15); IndexOutput @out = csw.CreateOutput("d.xyz", NewIOContext(Random())); @out.WriteInt(0); diff --git a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs index 7425024322..217c851980 100644 --- a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs +++ b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs @@ -74,31 +74,36 @@ public virtual void TestMmapIndex() // sometimes the directory is not cleaned by rmDir, because on Windows it // may take some time until the files are finally dereferenced. So clean the // directory up front, or otherwise new IndexWriter will fail. - DirectoryInfo dirPath = CreateTempDir("testLuceneMmap"); + var dirPath = CreateTempDir("testLuceneMmap"); RmDir(dirPath); - MMapDirectory dir = new MMapDirectory(dirPath, null); + var dir = new MMapDirectory(dirPath, null); // plan to add a set of useful stopwords, consider changing some of the // interior filters. - MockAnalyzer analyzer = new MockAnalyzer(Random()); - // TODO: something about lock timeouts and leftover locks. - IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE)); - writer.Commit(); - IndexReader reader = DirectoryReader.Open(dir); - IndexSearcher searcher = NewSearcher(reader); - - int num = AtLeast(1000); - for (int dx = 0; dx < num; dx++) + using (var analyzer = new MockAnalyzer(Random())) { - string f = RandomField(); - Document doc = new Document(); - doc.Add(NewTextField("data", f, Field.Store.YES)); - writer.AddDocument(doc); - } + // TODO: something about lock timeouts and leftover locks. + using (var writer = new IndexWriter(dir, + new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode( + IndexWriterConfig.OpenMode_e.CREATE))) + { + writer.Commit(); + using (IndexReader reader = DirectoryReader.Open(dir)) + { + var searcher = NewSearcher(reader); + var num = AtLeast(1000); + for (int dx = 0; dx < num; dx++) + { + var f = RandomField(); + var doc = new Document(); + doc.Add(NewTextField("data", f, Field.Store.YES)); + writer.AddDocument(doc); + } + } + } - reader.Dispose(); - writer.Dispose(); - RmDir(dirPath); + RmDir(dirPath); + } } private static void RmDir(DirectoryInfo dir)