lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [12/20] lucenenet git commit: Lucene.Net.Core.Store.Directory: implemented .NET dispose pattern
Date Sun, 02 Apr 2017 07:06:12 GMT
Lucene.Net.Core.Store.Directory: implemented .NET dispose pattern


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/99e15766
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/99e15766
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/99e15766

Branch: refs/heads/api-work
Commit: 99e1576606ef3c7ca132c5b8c8abee7602ee028d
Parents: 0f71b2b
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Apr 2 11:20:13 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Apr 2 11:58:35 2017 +0700

----------------------------------------------------------------------
 .../Store/CompoundFileDirectory.cs              |  31 ++-
 src/Lucene.Net.Core/Store/Directory.cs          |  11 +-
 src/Lucene.Net.Core/Store/FSDirectory.cs        |   7 +-
 .../Store/FileSwitchDirectory.cs                |   4 +-
 src/Lucene.Net.Core/Store/FilterDirectory.cs    |   7 +-
 .../Store/NRTCachingDirectory.cs                |  23 +-
 src/Lucene.Net.Core/Store/RAMDirectory.cs       |   9 +-
 .../Store/BaseDirectoryWrapper.cs               |  13 +-
 .../Store/MockDirectoryWrapper.cs               | 277 ++++++++++---------
 src/Lucene.Net.Tests/Index/TestFieldsReader.cs  |   7 +-
 .../Store/TestBufferedIndexInput.cs             |   7 +-
 11 files changed, 216 insertions(+), 180 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.Core/Store/CompoundFileDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/CompoundFileDirectory.cs b/src/Lucene.Net.Core/Store/CompoundFileDirectory.cs
index 9a07672..7b95e8d 100644
--- a/src/Lucene.Net.Core/Store/CompoundFileDirectory.cs
+++ b/src/Lucene.Net.Core/Store/CompoundFileDirectory.cs
@@ -292,24 +292,27 @@ namespace Lucene.Net.Store
             }
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
             lock (this)
             {
-                if (!IsOpen)
+                if (disposing)
                 {
-                    // allow double close - usually to be consistent with other closeables
-                    return; // already closed
-                }
-                IsOpen = false;
-                if (writer != null)
-                {
-                    Debug.Assert(openForWrite);
-                    writer.Dispose();
-                }
-                else
-                {
-                    IOUtils.Close(handle);
+                    if (!IsOpen)
+                    {
+                        // allow double close - usually to be consistent with other closeables
+                        return; // already closed
+                    }
+                    IsOpen = false;
+                    if (writer != null)
+                    {
+                        Debug.Assert(openForWrite);
+                        writer.Dispose();
+                    }
+                    else
+                    {
+                        IOUtils.Close(handle);
+                    }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.Core/Store/Directory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/Directory.cs b/src/Lucene.Net.Core/Store/Directory.cs
index 2e848c9..6d0331f 100644
--- a/src/Lucene.Net.Core/Store/Directory.cs
+++ b/src/Lucene.Net.Core/Store/Directory.cs
@@ -129,7 +129,16 @@ namespace Lucene.Net.Store
 
         /// <summary>
         /// Disposes the store. </summary>
-        public abstract void Dispose();
+        // LUCENENET specific - implementing proper dispose pattern
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        /// <summary>
+        /// Disposes the store. </summary>
+        protected abstract void Dispose(bool disposing);
 
         /// <summary>
         /// Set the <see cref="Store.LockFactory"/> that this <see cref="Directory"/>
instance should

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.Core/Store/FSDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/FSDirectory.cs b/src/Lucene.Net.Core/Store/FSDirectory.cs
index c3a7086..9c8c1ae 100644
--- a/src/Lucene.Net.Core/Store/FSDirectory.cs
+++ b/src/Lucene.Net.Core/Store/FSDirectory.cs
@@ -400,9 +400,12 @@ namespace Lucene.Net.Store
 
         /// <summary>
         /// Closes the store to future operations. </summary>
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            IsOpen = false;
+            if (disposing)
+            {
+                IsOpen = false;
+            }
         }
 
         /// <summary> the underlying filesystem directory </summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.Core/Store/FileSwitchDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/FileSwitchDirectory.cs b/src/Lucene.Net.Core/Store/FileSwitchDirectory.cs
index 3e40945..cceff73 100644
--- a/src/Lucene.Net.Core/Store/FileSwitchDirectory.cs
+++ b/src/Lucene.Net.Core/Store/FileSwitchDirectory.cs
@@ -70,9 +70,9 @@ namespace Lucene.Net.Store
             }
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            if (doClose)
+            if (disposing && doClose)
             {
                 try
                 {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.Core/Store/FilterDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/FilterDirectory.cs b/src/Lucene.Net.Core/Store/FilterDirectory.cs
index b0ff4b2..fd07bda 100644
--- a/src/Lucene.Net.Core/Store/FilterDirectory.cs
+++ b/src/Lucene.Net.Core/Store/FilterDirectory.cs
@@ -102,9 +102,12 @@ namespace Lucene.Net.Store
             m_input.ClearLock(name);
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            m_input.Dispose();
+            if (disposing)
+            {
+                m_input.Dispose();
+            }
         }
 
         public override void SetLockFactory(LockFactory lockFactory)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.Core/Store/NRTCachingDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/NRTCachingDirectory.cs b/src/Lucene.Net.Core/Store/NRTCachingDirectory.cs
index 8a603a3..ee9f5ba 100644
--- a/src/Lucene.Net.Core/Store/NRTCachingDirectory.cs
+++ b/src/Lucene.Net.Core/Store/NRTCachingDirectory.cs
@@ -331,19 +331,22 @@ namespace Lucene.Net.Store
         /// Dispose this directory, which flushes any cached files
         /// to the delegate and then disposes the delegate.
         /// </summary>
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            // NOTE: technically we shouldn't have to do this, ie,
-            // IndexWriter should have sync'd all files, but we do
-            // it for defensive reasons... or in case the app is
-            // doing something custom (creating outputs directly w/o
-            // using IndexWriter):
-            foreach (string fileName in cache.ListAll())
+            if (disposing)
             {
-                UnCache(fileName);
+                // NOTE: technically we shouldn't have to do this, ie,
+                // IndexWriter should have sync'd all files, but we do
+                // it for defensive reasons... or in case the app is
+                // doing something custom (creating outputs directly w/o
+                // using IndexWriter):
+                foreach (string fileName in cache.ListAll())
+                {
+                    UnCache(fileName);
+                }
+                cache.Dispose();
+                @delegate.Dispose();
             }
-            cache.Dispose();
-            @delegate.Dispose();
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.Core/Store/RAMDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/RAMDirectory.cs b/src/Lucene.Net.Core/Store/RAMDirectory.cs
index fb787d0..ae8651c 100644
--- a/src/Lucene.Net.Core/Store/RAMDirectory.cs
+++ b/src/Lucene.Net.Core/Store/RAMDirectory.cs
@@ -224,10 +224,13 @@ namespace Lucene.Net.Store
 
         /// <summary>
         /// Closes the store to future operations, releasing associated memory. </summary>
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            IsOpen = false;
-            m_fileMap.Clear();
+            if (disposing)
+            {
+                IsOpen = false;
+                m_fileMap.Clear();
+            }
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.TestFramework/Store/BaseDirectoryWrapper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Store/BaseDirectoryWrapper.cs b/src/Lucene.Net.TestFramework/Store/BaseDirectoryWrapper.cs
index b45435d..aa939ec 100644
--- a/src/Lucene.Net.TestFramework/Store/BaseDirectoryWrapper.cs
+++ b/src/Lucene.Net.TestFramework/Store/BaseDirectoryWrapper.cs
@@ -37,14 +37,17 @@ namespace Lucene.Net.Store
         {
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
-            IsOpen = false;
-            if (CheckIndexOnClose_Renamed && DirectoryReader.IndexExists(this))
+            if (disposing)
             {
-                TestUtil.CheckIndex(this, CrossCheckTermVectorsOnClose_Renamed);
+                IsOpen = false;
+                if (CheckIndexOnClose_Renamed && DirectoryReader.IndexExists(this))
+                {
+                    TestUtil.CheckIndex(this, CrossCheckTermVectorsOnClose_Renamed);
+                }
+                base.Dispose(disposing);
             }
-            base.Dispose();
         }
 
         public virtual bool Open

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
index 8f49463..5858a26 100644
--- a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
+++ b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
@@ -902,191 +902,194 @@ namespace Lucene.Net.Store
             }
         }
 
-        public override void Dispose()
+        protected override void Dispose(bool disposing)
         {
             lock (this)
             {
-                // files that we tried to delete, but couldn't because readers were open.
-                // all that matters is that we tried! (they will eventually go away)
-                ISet<string> pendingDeletions = new HashSet<string>(OpenFilesDeleted);
-                MaybeYield();
-                if (OpenFiles == null)
-                {
-                    OpenFiles = new Dictionary<string, int>();
-                    OpenFilesDeleted = new HashSet<string>();
-                }
-                if (OpenFiles.Count > 0)
+                if (disposing)
                 {
-                    // print the first one as its very verbose otherwise
-                    Exception cause = null;
-                    IEnumerator<Exception> stacktraces = OpenFileHandles.Values.GetEnumerator();
-                    if (stacktraces.MoveNext())
+                    // files that we tried to delete, but couldn't because readers were open.
+                    // all that matters is that we tried! (they will eventually go away)
+                    ISet<string> pendingDeletions = new HashSet<string>(OpenFilesDeleted);
+                    MaybeYield();
+                    if (OpenFiles == null)
                     {
-                        cause = stacktraces.Current;
+                        OpenFiles = new Dictionary<string, int>();
+                        OpenFilesDeleted = new HashSet<string>();
                     }
-
-                    // RuntimeException instead ofSystem.IO.IOException because
-                    // super() does not throwSystem.IO.IOException currently:
-                    throw new Exception("MockDirectoryWrapper: cannot close: there are still
open files: "
-                        + String.Join(" ,", OpenFiles.ToArray().Select(x => x.Key)), cause);
-                }
-                if (OpenLocks.Count > 0)
-                {
-                    throw new Exception("MockDirectoryWrapper: cannot close: there are still
open locks: "
-                        + String.Join(" ,", OpenLocks.ToArray()));
-                }
-
-                IsOpen = false;
-                if (CheckIndexOnClose)
-                {
-                    RandomIOExceptionRate_Renamed = 0.0;
-                    RandomIOExceptionRateOnOpen_Renamed = 0.0;
-                    if (DirectoryReader.IndexExists(this))
+                    if (OpenFiles.Count > 0)
                     {
-                        if (LuceneTestCase.VERBOSE)
-                        {
-                            Console.WriteLine("\nNOTE: MockDirectoryWrapper: now crush");
-                        }
-                        Crash(); // corrupt any unsynced-files
-                        if (LuceneTestCase.VERBOSE)
+                        // print the first one as its very verbose otherwise
+                        Exception cause = null;
+                        IEnumerator<Exception> stacktraces = OpenFileHandles.Values.GetEnumerator();
+                        if (stacktraces.MoveNext())
                         {
-                            Console.WriteLine("\nNOTE: MockDirectoryWrapper: now run CheckIndex");
+                            cause = stacktraces.Current;
                         }
-                        TestUtil.CheckIndex(this, CrossCheckTermVectorsOnClose);
 
-                        // TODO: factor this out / share w/ TestIW.assertNoUnreferencedFiles
-                        if (AssertNoUnreferencedFilesOnClose)
+                        // RuntimeException instead ofSystem.IO.IOException because
+                        // super() does not throwSystem.IO.IOException currently:
+                        throw new Exception("MockDirectoryWrapper: cannot close: there are
still open files: "
+                            + string.Join(" ,", OpenFiles.ToArray().Select(x => x.Key)),
cause);
+                    }
+                    if (OpenLocks.Count > 0)
+                    {
+                        throw new Exception("MockDirectoryWrapper: cannot close: there are
still open locks: "
+                            + string.Join(" ,", OpenLocks.ToArray()));
+                    }
+
+                    IsOpen = false;
+                    if (CheckIndexOnClose)
+                    {
+                        RandomIOExceptionRate_Renamed = 0.0;
+                        RandomIOExceptionRateOnOpen_Renamed = 0.0;
+                        if (DirectoryReader.IndexExists(this))
                         {
-                            // now look for unreferenced files: discount ones that we tried
to delete but could not
-                            HashSet<string> allFiles = new HashSet<string>(Arrays.AsList(ListAll()));
-                            allFiles.RemoveAll(pendingDeletions);
-                            string[] startFiles = allFiles.ToArray(/*new string[0]*/);
-                            IndexWriterConfig iwc = new IndexWriterConfig(LuceneTestCase.TEST_VERSION_CURRENT,
null);
-                            iwc.SetIndexDeletionPolicy(NoDeletionPolicy.INSTANCE);
-                            (new IndexWriter(m_input, iwc)).Rollback();
-                            string[] endFiles = m_input.ListAll();
-
-                            ISet<string> startSet = new SortedSet<string>(Arrays.AsList(startFiles),
StringComparer.Ordinal);
-                            ISet<string> endSet = new SortedSet<string>(Arrays.AsList(endFiles),
StringComparer.Ordinal);
-
-                            if (pendingDeletions.Contains("segments.gen") && endSet.Contains("segments.gen"))
+                            if (LuceneTestCase.VERBOSE)
                             {
-                                // this is possible if we hit an exception while writing
segments.gen, we try to delete it
-                                // and it ends out in pendingDeletions (but IFD wont remove
this).
-                                startSet.Add("segments.gen");
-                                if (LuceneTestCase.VERBOSE)
-                                {
-                                    Console.WriteLine("MDW: Unreferenced check: Ignoring
segments.gen that we could not delete.");
-                                }
+                                Console.WriteLine("\nNOTE: MockDirectoryWrapper: now crush");
+                            }
+                            Crash(); // corrupt any unsynced-files
+                            if (LuceneTestCase.VERBOSE)
+                            {
+                                Console.WriteLine("\nNOTE: MockDirectoryWrapper: now run
CheckIndex");
                             }
+                            TestUtil.CheckIndex(this, CrossCheckTermVectorsOnClose);
 
-                            // its possible we cannot delete the segments_N on windows if
someone has it open and
-                            // maybe other files too, depending on timing. normally someone
on windows wouldnt have
-                            // an issue (IFD would nuke this stuff eventually), but we pass
NoDeletionPolicy...
-                            foreach (string file in pendingDeletions)
+                            // TODO: factor this out / share w/ TestIW.assertNoUnreferencedFiles
+                            if (AssertNoUnreferencedFilesOnClose)
                             {
-                                if (file.StartsWith("segments", StringComparison.Ordinal)
&& !file.Equals("segments.gen", StringComparison.Ordinal) && endSet.Contains(file,
StringComparer.Ordinal))
+                                // now look for unreferenced files: discount ones that we
tried to delete but could not
+                                HashSet<string> allFiles = new HashSet<string>(Arrays.AsList(ListAll()));
+                                allFiles.RemoveAll(pendingDeletions);
+                                string[] startFiles = allFiles.ToArray(/*new string[0]*/);
+                                IndexWriterConfig iwc = new IndexWriterConfig(LuceneTestCase.TEST_VERSION_CURRENT,
null);
+                                iwc.SetIndexDeletionPolicy(NoDeletionPolicy.INSTANCE);
+                                (new IndexWriter(m_input, iwc)).Rollback();
+                                string[] endFiles = m_input.ListAll();
+
+                                ISet<string> startSet = new SortedSet<string>(Arrays.AsList(startFiles),
StringComparer.Ordinal);
+                                ISet<string> endSet = new SortedSet<string>(Arrays.AsList(endFiles),
StringComparer.Ordinal);
+
+                                if (pendingDeletions.Contains("segments.gen") &&
endSet.Contains("segments.gen"))
                                 {
-                                    startSet.Add(file);
+                                    // this is possible if we hit an exception while writing
segments.gen, we try to delete it
+                                    // and it ends out in pendingDeletions (but IFD wont
remove this).
+                                    startSet.Add("segments.gen");
                                     if (LuceneTestCase.VERBOSE)
                                     {
-                                        Console.WriteLine("MDW: Unreferenced check: Ignoring
segments file: " + file + " that we could not delete.");
+                                        Console.WriteLine("MDW: Unreferenced check: Ignoring
segments.gen that we could not delete.");
                                     }
-                                    SegmentInfos sis = new SegmentInfos();
-                                    try
+                                }
+
+                                // its possible we cannot delete the segments_N on windows
if someone has it open and
+                                // maybe other files too, depending on timing. normally someone
on windows wouldnt have
+                                // an issue (IFD would nuke this stuff eventually), but we
pass NoDeletionPolicy...
+                                foreach (string file in pendingDeletions)
+                                {
+                                    if (file.StartsWith("segments", StringComparison.Ordinal)
&& !file.Equals("segments.gen", StringComparison.Ordinal) && endSet.Contains(file,
StringComparer.Ordinal))
                                     {
-                                        sis.Read(m_input, file);
-                                    }
+                                        startSet.Add(file);
+                                        if (LuceneTestCase.VERBOSE)
+                                        {
+                                            Console.WriteLine("MDW: Unreferenced check: Ignoring
segments file: " + file + " that we could not delete.");
+                                        }
+                                        SegmentInfos sis = new SegmentInfos();
+                                        try
+                                        {
+                                            sis.Read(m_input, file);
+                                        }
 #pragma warning disable 168
-                                    catch (System.IO.IOException ioe)
+                                        catch (System.IO.IOException ioe)
 #pragma warning restore 168
-                                    {
-                                        // OK: likely some of the .si files were deleted
-                                    }
+                                        {
+                                            // OK: likely some of the .si files were deleted
+                                        }
 
-                                    try
-                                    {
-                                        ISet<string> ghosts = new HashSet<string>(sis.Files(m_input,
false));
-                                        foreach (string s in ghosts)
+                                        try
                                         {
-                                            if (endSet.Contains(s) && !startSet.Contains(s))
+                                            ISet<string> ghosts = new HashSet<string>(sis.Files(m_input,
false));
+                                            foreach (string s in ghosts)
                                             {
-                                                Debug.Assert(pendingDeletions.Contains(s));
-                                                if (LuceneTestCase.VERBOSE)
+                                                if (endSet.Contains(s) && !startSet.Contains(s))
                                                 {
-                                                    Console.WriteLine("MDW: Unreferenced
check: Ignoring referenced file: " + s + " " + "from " + file + " that we could not delete.");
+                                                    Debug.Assert(pendingDeletions.Contains(s));
+                                                    if (LuceneTestCase.VERBOSE)
+                                                    {
+                                                        Console.WriteLine("MDW: Unreferenced
check: Ignoring referenced file: " + s + " " + "from " + file + " that we could not delete.");
+                                                    }
+                                                    startSet.Add(s);
                                                 }
-                                                startSet.Add(s);
                                             }
                                         }
-                                    }
-                                    catch (Exception t)
-                                    {
-                                        Console.Error.WriteLine("ERROR processing leftover
segments file " + file + ":");
-                                        Console.WriteLine(t.ToString());
-                                        Console.Write(t.StackTrace);
+                                        catch (Exception t)
+                                        {
+                                            Console.Error.WriteLine("ERROR processing leftover
segments file " + file + ":");
+                                            Console.WriteLine(t.ToString());
+                                            Console.Write(t.StackTrace);
+                                        }
                                     }
                                 }
-                            }
 
-                            startFiles = startSet.ToArray(/*new string[0]*/);
-                            endFiles = endSet.ToArray(/*new string[0]*/);
+                                startFiles = startSet.ToArray(/*new string[0]*/);
+                                endFiles = endSet.ToArray(/*new string[0]*/);
 
-                            if (!Arrays.Equals(startFiles, endFiles))
-                            {
-                                IList<string> removed = new List<string>();
-                                foreach (string fileName in startFiles)
+                                if (!Arrays.Equals(startFiles, endFiles))
                                 {
-                                    if (!endSet.Contains(fileName))
+                                    IList<string> removed = new List<string>();
+                                    foreach (string fileName in startFiles)
                                     {
-                                        removed.Add(fileName);
+                                        if (!endSet.Contains(fileName))
+                                        {
+                                            removed.Add(fileName);
+                                        }
                                     }
-                                }
 
-                                IList<string> added = new List<string>();
-                                foreach (string fileName in endFiles)
-                                {
-                                    if (!startSet.Contains(fileName))
+                                    IList<string> added = new List<string>();
+                                    foreach (string fileName in endFiles)
                                     {
-                                        added.Add(fileName);
+                                        if (!startSet.Contains(fileName))
+                                        {
+                                            added.Add(fileName);
+                                        }
                                     }
-                                }
 
-                                string extras;
-                                if (removed.Count != 0)
-                                {
-                                    extras = "\n\nThese files were removed: " + removed;
-                                }
-                                else
-                                {
-                                    extras = "";
-                                }
+                                    string extras;
+                                    if (removed.Count != 0)
+                                    {
+                                        extras = "\n\nThese files were removed: " + removed;
+                                    }
+                                    else
+                                    {
+                                        extras = "";
+                                    }
 
-                                if (added.Count != 0)
-                                {
-                                    extras += "\n\nThese files were added (waaaaaaaaaat!):
" + added;
-                                }
+                                    if (added.Count != 0)
+                                    {
+                                        extras += "\n\nThese files were added (waaaaaaaaaat!):
" + added;
+                                    }
 
-                                if (pendingDeletions.Count != 0)
-                                {
-                                    extras += "\n\nThese files we had previously tried to
delete, but couldn't: " + pendingDeletions;
+                                    if (pendingDeletions.Count != 0)
+                                    {
+                                        extras += "\n\nThese files we had previously tried
to delete, but couldn't: " + pendingDeletions;
+                                    }
+
+                                    Debug.Assert(false, "unreferenced files: before delete:\n
   " + Arrays.ToString(startFiles) + "\n  after delete:\n    " + Arrays.ToString(endFiles)
+ extras);
                                 }
 
-                                Debug.Assert(false, "unreferenced files: before delete:\n
   " + Arrays.ToString(startFiles) + "\n  after delete:\n    " + Arrays.ToString(endFiles)
+ extras);
+                                DirectoryReader ir1 = DirectoryReader.Open(this);
+                                int numDocs1 = ir1.NumDocs;
+                                ir1.Dispose();
+                                (new IndexWriter(this, new IndexWriterConfig(LuceneTestCase.TEST_VERSION_CURRENT,
null))).Dispose();
+                                DirectoryReader ir2 = DirectoryReader.Open(this);
+                                int numDocs2 = ir2.NumDocs;
+                                ir2.Dispose();
+                                Debug.Assert(numDocs1 == numDocs2, "numDocs changed after
opening/closing IW: before=" + numDocs1 + " after=" + numDocs2);
                             }
-
-                            DirectoryReader ir1 = DirectoryReader.Open(this);
-                            int numDocs1 = ir1.NumDocs;
-                            ir1.Dispose();
-                            (new IndexWriter(this, new IndexWriterConfig(LuceneTestCase.TEST_VERSION_CURRENT,
null))).Dispose();
-                            DirectoryReader ir2 = DirectoryReader.Open(this);
-                            int numDocs2 = ir2.NumDocs;
-                            ir2.Dispose();
-                            Debug.Assert(numDocs1 == numDocs2, "numDocs changed after opening/closing
IW: before=" + numDocs1 + " after=" + numDocs2);
                         }
                     }
+                    m_input.Dispose();
                 }
-                m_input.Dispose();
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.Tests/Index/TestFieldsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Index/TestFieldsReader.cs b/src/Lucene.Net.Tests/Index/TestFieldsReader.cs
index c7b9619..5f03962 100644
--- a/src/Lucene.Net.Tests/Index/TestFieldsReader.cs
+++ b/src/Lucene.Net.Tests/Index/TestFieldsReader.cs
@@ -163,9 +163,12 @@ namespace Lucene.Net.Index
                 FsDir.Sync(names);
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                FsDir.Dispose();
+                if (disposing)
+                {
+                    FsDir.Dispose();
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/99e15766/src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs b/src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs
index 151c5df..4dc0c84 100644
--- a/src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs
+++ b/src/Lucene.Net.Tests/Store/TestBufferedIndexInput.cs
@@ -366,9 +366,12 @@ namespace Lucene.Net.Store
                 return Dir.CreateOutput(name, context);
             }
 
-            public override void Dispose()
+            protected override void Dispose(bool disposing)
             {
-                Dir.Dispose();
+                if (disposing)
+                {
+                    Dir.Dispose();
+                }
             }
 
             public override void DeleteFile(string name)


Mime
View raw message