You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2015/01/06 04:46:17 UTC

[01/18] lucenenet git commit: We can use the CLR's Delete recursive

Repository: lucenenet
Updated Branches:
  refs/heads/master b18ae0aac -> f09cd685e


We can use the CLR's Delete recursive


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

Branch: refs/heads/master
Commit: 6b0841c45bd2d9c3afee42789337f3ec0882482a
Parents: b18ae0a
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 14:45:54 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 14:45:54 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6b0841c4/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
index 649d269..7425024 100644
--- a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
@@ -101,17 +101,13 @@ namespace Lucene.Net.Store
             RmDir(dirPath);
         }
 
-        private void RmDir(DirectoryInfo dir)
+        private static void RmDir(DirectoryInfo dir)
         {
             if (!dir.Exists)
             {
                 return;
             }
-            foreach (FileInfo file in dir.GetFiles())
-            {
-                file.Delete();
-            }
-            dir.Delete();
+            dir.Delete(true);
         }
     }
 }
\ No newline at end of file


[11/18] lucenenet git commit: Better NativeFSLock, phase 2

Posted by sy...@apache.org.
Better NativeFSLock, phase 2

Now properly dispose of unused FileStreams


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

Branch: refs/heads/master
Commit: d71f71434887749e3dfcde0f53ef3967c230b19d
Parents: ca7e09b
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 18:24:55 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 18:24:55 2015 +0200

----------------------------------------------------------------------
 .../Store/NativeFSLockFactory.cs                | 52 ++++++--------------
 src/Lucene.Net.Core/Util/IOUtils.cs             |  2 +-
 2 files changed, 15 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d71f7143/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs b/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
index fd98b94..f7c370e 100644
--- a/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
+++ b/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Concurrent;
+using Lucene.Net.Support;
 using Lucene.Net.Util;
 
 namespace Lucene.Net.Store
@@ -119,18 +120,6 @@ namespace Lucene.Net.Store
         private readonly DirectoryInfo Path;
         private readonly DirectoryInfo LockDir;
 
-      /*
-       * The javadocs for FileChannel state that you should have
-       * a single instance of a FileChannel (per JVM) for all
-       * locking against a given file.  To ensure this, we have
-       * a single (static) HashSet that contains the file paths
-       * of all currently locked locks.  This protects against
-       * possible cases where different Directory instances in
-       * one JVM (each with their own NativeFSLockFactory
-       * instance) have set the same lock dir and lock prefix.
-       */
-        private static readonly ConcurrentDictionary<string, WeakReference<FileStream>> LOCKS_HELD = new ConcurrentDictionary<string, WeakReference<FileStream>>();
-
         public NativeFSLock(DirectoryInfo lockDir, string lockFileName)
         {
             this.LockDir = lockDir;
@@ -141,14 +130,14 @@ namespace Lucene.Net.Store
         {
             lock (this)
             {
+                FailureReason = null;
+
                 if (Channel != null)
                 {
                     // Our instance is already locked:
                     return false;
                 }
 
-                //LOCKS_HELD.GetOrAdd(Path.FullName)
-
                 if (!System.IO.Directory.Exists(LockDir.FullName))
                 {
                     try
@@ -160,12 +149,12 @@ namespace Lucene.Net.Store
                         throw new System.IO.IOException("Cannot create directory: " + LockDir.FullName);
                     }
                 }
-                else if (System.IO.File.Exists(LockDir.FullName))
+                else if (File.Exists(LockDir.FullName))
                 {
-                    throw new System.IO.IOException("Found regular file where directory expected: " + LockDir.FullName);
+                    throw new IOException("Found regular file where directory expected: " + LockDir.FullName);
                 }
 
-                bool success = false;
+                var success = false;
                 try
                 {
                     Channel = new FileStream(Path.FullName, FileMode.Create, FileAccess.Write, FileShare.None);
@@ -175,30 +164,26 @@ namespace Lucene.Net.Store
                 catch (IOException e)
                 {
                     FailureReason = e;
+                    IOUtils.CloseWhileHandlingException(Channel);
                     Channel = null;
                 }
                 // LUCENENET: UnauthorizedAccessException does not derive from IOException like in java
-                catch (System.UnauthorizedAccessException e)
+                catch (UnauthorizedAccessException e)
                 {
                     // On Windows, we can get intermittent "Access
                     // Denied" here.  So, we treat this as failure to
                     // acquire the lock, but, store the reason in case
                     // there is in fact a real error case.
                     FailureReason = e;
+                    IOUtils.CloseWhileHandlingException(Channel);
                     Channel = null;
                 }
                 finally
                 {
                     if (!success)
                     {
-                        try
-                        {
-                            IOUtils.CloseWhileHandlingException(Channel);
-                        }
-                        finally
-                        {
-                            Channel = null;
-                        }
+                        IOUtils.CloseWhileHandlingException(Channel);
+                        Channel = null;
                     }
                 }
 
@@ -218,19 +203,10 @@ namespace Lucene.Net.Store
                     }
                     finally
                     {
-                        try
-                        {
-                            Channel.Close();
-                        }
-                        finally
-                        {
-                            Channel = null;
-//                            lock (LOCK_HELD)
-//                            {
-//                                LOCK_HELD.Remove(Path.FullName);
-//                            }
-                        }
+                        IOUtils.CloseWhileHandlingException(Channel);
+                        Channel = null;
                     }
+
                     bool tmpBool;
                     if (File.Exists(Path.FullName))
                     {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/d71f7143/src/Lucene.Net.Core/Util/IOUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/IOUtils.cs b/src/Lucene.Net.Core/Util/IOUtils.cs
index e23d3cd..1c8e952 100644
--- a/src/Lucene.Net.Core/Util/IOUtils.cs
+++ b/src/Lucene.Net.Core/Util/IOUtils.cs
@@ -213,7 +213,7 @@ namespace Lucene.Net.Util
         ///          objects to call <tt>close()</tt> on </param>
         public static void CloseWhileHandlingException(params IDisposable[] objects)
         {
-            foreach (IDisposable o in objects)
+            foreach (var o in objects)
             {
                 try
                 {


[10/18] lucenenet git commit: Some more work on tests

Posted by sy...@apache.org.
Some more work on tests


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

Branch: refs/heads/master
Commit: ca7e09b2e490749a315820e32af10768c0783d40
Parents: 8a999e1
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 17:48:09 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 17:48:09 2015 +0200

----------------------------------------------------------------------
 .../core/Store/TestBufferedIndexInput.cs        | 98 +++++++++-----------
 .../core/Store/TestMultiMMap.cs                 |  1 +
 2 files changed, 46 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ca7e09b2/src/Lucene.Net.Tests/core/Store/TestBufferedIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestBufferedIndexInput.cs b/src/Lucene.Net.Tests/core/Store/TestBufferedIndexInput.cs
index 0cfa402..731bcc5 100644
--- a/src/Lucene.Net.Tests/core/Store/TestBufferedIndexInput.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestBufferedIndexInput.cs
@@ -268,74 +268,66 @@ namespace Lucene.Net.Store
         [Test]
         public virtual void TestSetBufferSize()
         {
-            //File indexDir = CreateTempDir("testSetBufferSize");
-            var indexDir = new DirectoryInfo(Path.Combine(AppSettings.Get("tempDir", ""), "testSetBufferSize"));
-            try
+            var indexDir = CreateTempDir("testSetBufferSize");
+            using (var dir = new MockFSDirectory(indexDir, Random()))
             {
-                using (MockFSDirectory dir = new MockFSDirectory(indexDir, Random()))
+                using (var writer = new IndexWriter(dir,
+                    (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(
+                        IndexWriterConfig.OpenMode_e.CREATE).SetMergePolicy(NewLogMergePolicy(false))))
                 {
-                    using (IndexWriter writer = new IndexWriter(dir,
-                        (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(
-                            IndexWriterConfig.OpenMode_e.CREATE).SetMergePolicy(NewLogMergePolicy(false))))
+                    for (int i = 0; i < 37; i++)
+                    {
+                        var doc = new Document();
+                        doc.Add(NewTextField("content", "aaa bbb ccc ddd" + i, Field.Store.YES));
+                        doc.Add(NewTextField("id", "" + i, Field.Store.YES));
+                        writer.AddDocument(doc);
+                    }
+
+                    dir.AllIndexInputs.Clear();
+                    dir.TweakBufferSizes();
+                    writer.DeleteDocuments(new Term("id", "0"));
+
+                    var aaa = new Term("content", "aaa");
+                    var bbb = new Term("content", "bbb");
+
+                    IndexSearcher searcher;
+                    ScoreDoc[] hits;
+                    using (var reader = DirectoryReader.Open(writer, true))
                     {
-                        for (int i = 0; i < 37; i++)
-                        {
-                            var doc = new Document();
-                            doc.Add(NewTextField("content", "aaa bbb ccc ddd" + i, Field.Store.YES));
-                            doc.Add(NewTextField("id", "" + i, Field.Store.YES));
-                            writer.AddDocument(doc);
-                        }
-
-                        dir.AllIndexInputs.Clear();
+                        searcher = NewSearcher(reader);
+                        hits = searcher.Search(new TermQuery(bbb), null, 1000).ScoreDocs;
                         dir.TweakBufferSizes();
-                        writer.DeleteDocuments(new Term("id", "0"));
-
-                        var aaa = new Term("content", "aaa");
-                        var bbb = new Term("content", "bbb");
-                        
-                        IndexSearcher searcher;
-                        ScoreDoc[] hits;
-                        using (var reader = DirectoryReader.Open(writer, true))
-                        {
-                            searcher = NewSearcher(reader);
-                            hits = searcher.Search(new TermQuery(bbb), null, 1000).ScoreDocs;
-                            dir.TweakBufferSizes();
-                            Assert.AreEqual(36, hits.Length);
-                        }
+                        Assert.AreEqual(36, hits.Length);
+                    }
 
+                    dir.TweakBufferSizes();
+                    writer.DeleteDocuments(new Term("id", "4"));
+                    using (var reader = DirectoryReader.Open(writer, true))
+                    {
+                        searcher = NewSearcher(reader);
+
+                        hits = searcher.Search(new TermQuery(bbb), null, 1000).ScoreDocs;
+                        dir.TweakBufferSizes();
+                        Assert.AreEqual(35, hits.Length);
+                        dir.TweakBufferSizes();
+                        hits = searcher.Search(new TermQuery(new Term("id", "33")), null, 1000).ScoreDocs;
+                        dir.TweakBufferSizes();
+                        Assert.AreEqual(1, hits.Length);
+                        hits = searcher.Search(new TermQuery(aaa), null, 1000).ScoreDocs;
                         dir.TweakBufferSizes();
-                        writer.DeleteDocuments(new Term("id", "4"));
-                        using (var reader = DirectoryReader.Open(writer, true))
-                        {
-                            searcher = NewSearcher(reader);
-
-                            hits = searcher.Search(new TermQuery(bbb), null, 1000).ScoreDocs;
-                            dir.TweakBufferSizes();
-                            Assert.AreEqual(35, hits.Length);
-                            dir.TweakBufferSizes();
-                            hits = searcher.Search(new TermQuery(new Term("id", "33")), null, 1000).ScoreDocs;
-                            dir.TweakBufferSizes();
-                            Assert.AreEqual(1, hits.Length);
-                            hits = searcher.Search(new TermQuery(aaa), null, 1000).ScoreDocs;
-                            dir.TweakBufferSizes();
-                            Assert.AreEqual(35, hits.Length);
-                        }
+                        Assert.AreEqual(35, hits.Length);
                     }
                 }
             }
-            finally
-            {
-                System.IO.Directory.Delete(indexDir.FullName, true);
-            }
         }
 
         private class MockFSDirectory : BaseDirectory
         {
-            internal IList<IndexInput> AllIndexInputs = new List<IndexInput>();
+            internal readonly IList<IndexInput> AllIndexInputs = new List<IndexInput>();
 
-            internal Random Rand;
+            private Random Rand;
 
-            internal Directory Dir;
+            private Directory Dir;
 
             public MockFSDirectory(DirectoryInfo path, Random rand)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ca7e09b2/src/Lucene.Net.Tests/core/Store/TestMultiMMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestMultiMMap.cs b/src/Lucene.Net.Tests/core/Store/TestMultiMMap.cs
index aa7807c..3ec109f 100644
--- a/src/Lucene.Net.Tests/core/Store/TestMultiMMap.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestMultiMMap.cs
@@ -47,6 +47,7 @@ namespace Lucene.Net.Store
         public override void SetUp()
         {
             base.SetUp();
+            // LUCENENET TODO: what?!?!?!?!?!
             AssumeTrue("test requires a jre that supports unmapping", MMapDirectory.UNMAP_SUPPORTED);
         }
 


[16/18] lucenenet git commit: Lets catch more failing tests

Posted by sy...@apache.org.
Lets catch more failing tests


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

Branch: refs/heads/master
Commit: 309ebc724b7e5f511ae8b03033651df04db3c3b8
Parents: 3b37fac
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 19:10:53 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 19:10:53 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Store/NIOFSDirectory.cs                 | 7 ++++---
 src/Lucene.Net.Tests/core/Store/TestDirectory.cs            | 2 +-
 src/Lucene.Net.Tests/core/Store/TestLockFactory.cs          | 2 +-
 src/Lucene.Net.Tests/core/Store/TestMockDirectoryWrapper.cs | 4 ++--
 4 files changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/309ebc72/src/Lucene.Net.Core/Store/NIOFSDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/NIOFSDirectory.cs b/src/Lucene.Net.Core/Store/NIOFSDirectory.cs
index d31c59e..682c8a8 100644
--- a/src/Lucene.Net.Core/Store/NIOFSDirectory.cs
+++ b/src/Lucene.Net.Core/Store/NIOFSDirectory.cs
@@ -1,3 +1,4 @@
+using System.Threading;
 using Lucene.Net.Support;
 using System;
 using System.Diagnostics;
@@ -98,9 +99,9 @@ namespace Lucene.Net.Store
         {
             private readonly NIOFSDirectory OuterInstance;
 
-            private Lucene.Net.Store.IOContext Context;
-            private FileInfo Path;
-            private FileStream Descriptor;
+            private readonly IOContext Context;
+            private readonly FileInfo Path;
+            private readonly FileStream Descriptor;
 
             public IndexInputSlicerAnonymousInnerClassHelper(NIOFSDirectory outerInstance, Lucene.Net.Store.IOContext context, FileInfo path, FileStream descriptor)
                 : base(outerInstance)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/309ebc72/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
index 9ea4097..8d4df01 100644
--- a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
@@ -161,7 +161,7 @@ namespace Lucene.Net.Store
 
         // Test that different instances of FSDirectory can coexist on the same
         // path, can read, write, and lock files.
-        [Test]
+        [Test, Timeout(int.MaxValue)]
         public virtual void TestDirectInstantiation()
         {
             DirectoryInfo path = CreateTempDir("testDirectInstantiation");

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/309ebc72/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs b/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
index a3230ff..674c8b6 100644
--- a/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
@@ -194,7 +194,7 @@ namespace Lucene.Net.Store
         }
 
         // Verify: NativeFSLockFactory works correctly
-        [Test]
+        [Test, Timeout(int.MaxValue)]
         public virtual void TestNativeFSLockFactory()
         {
             var f = new NativeFSLockFactory(CreateTempDir("testNativeFsLockFactory"));

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/309ebc72/src/Lucene.Net.Tests/core/Store/TestMockDirectoryWrapper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestMockDirectoryWrapper.cs b/src/Lucene.Net.Tests/core/Store/TestMockDirectoryWrapper.cs
index 932740b..6cfd723 100644
--- a/src/Lucene.Net.Tests/core/Store/TestMockDirectoryWrapper.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestMockDirectoryWrapper.cs
@@ -65,11 +65,11 @@ namespace Lucene.Net.Store
             dir.Dispose();
         }
 
-        [Test]
+        [Test, Repeat(100)]
         public virtual void TestDiskFull()
         {
             // test writeBytes
-            MockDirectoryWrapper dir = NewMockDirectory();
+            var dir = NewMockDirectory();
             dir.MaxSizeInBytes = 3;
             var bytes = new byte[] { 1, 2 };
             IndexOutput @out = dir.CreateOutput("foo", IOContext.DEFAULT);


[07/18] lucenenet git commit: Nicer failures

Posted by sy...@apache.org.
Nicer failures


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

Branch: refs/heads/master
Commit: c7473a53dfd83720117abd6f352d5fe881f8232e
Parents: 36582a3
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 17:42:05 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 17:42:05 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/c7473a53/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 b202c99..c4f8089 100644
--- a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
+++ b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
@@ -909,11 +909,12 @@ namespace Lucene.Net.Store
 
                     // RuntimeException instead ofSystem.IO.IOException because
                     // super() does not throwSystem.IO.IOException currently:
-                    throw new Exception("MockDirectoryWrapper: cannot close: there are still open files: " + OpenFiles, cause);
+                    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: " + OpenLocks);
+                    throw new Exception("MockDirectoryWrapper: cannot close: there are still open locks: " + OpenLocks.ToArray());
                 }
 
                 IsOpen = false;


[02/18] lucenenet git commit: Minor cleanups

Posted by sy...@apache.org.
Minor cleanups


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

Branch: refs/heads/master
Commit: 7a5aa5cc2cfb67377668de649e85590bde99eae1
Parents: 6b0841c
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 15:14:33 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 15:14:33 2015 +0200

----------------------------------------------------------------------
 .../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(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
index 9519489..8501048 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
@@ -44,7 +44,7 @@ namespace Lucene.Net.Codecs.Lucene3x
     {
         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 @@ namespace Lucene.Net.Codecs.Lucene3x
                 infos.Add(siPerCommit);
             }
 
-            infos.UserData_Renamed = input.ReadStringStringMap();
+            infos.UserData = input.ReadStringStringMap();
         }
 
         public override SegmentInfo Read(Directory directory, string segmentName, IOContext context)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Index/IndexWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/IndexWriter.cs b/src/Lucene.Net.Core/Index/IndexWriter.cs
index a393fc5..2715a2b 100644
--- a/src/Lucene.Net.Core/Index/IndexWriter.cs
+++ b/src/Lucene.Net.Core/Index/IndexWriter.cs
@@ -5654,9 +5654,9 @@ namespace Lucene.Net.Index
                 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();
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Index/LogMergePolicy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/LogMergePolicy.cs b/src/Lucene.Net.Core/Index/LogMergePolicy.cs
index 39cfad1..d661a25 100644
--- a/src/Lucene.Net.Core/Index/LogMergePolicy.cs
+++ b/src/Lucene.Net.Core/Index/LogMergePolicy.cs
@@ -252,7 +252,7 @@ namespace Lucene.Net.Index
         private MergeSpecification FindForcedMergesSizeLimit(SegmentInfos infos, int maxNumSegments, int last)
         {
             MergeSpecification spec = new MergeSpecification();
-            List<SegmentCommitInfo> segments = infos.AsList();
+            IList<SegmentCommitInfo> segments = infos.AsList();
 
             int start = last - 1;
             while (start >= 0)
@@ -300,8 +300,8 @@ namespace Lucene.Net.Index
         /// </summary>
         private MergeSpecification FindForcedMergesMaxNumSegments(SegmentInfos infos, int maxNumSegments, int last)
         {
-            MergeSpecification spec = new MergeSpecification();
-            List<SegmentCommitInfo> 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 @@ namespace Lucene.Net.Index
         /// </summary>
         public override MergeSpecification FindForcedDeletesMerges(SegmentInfos segmentInfos)
         {
-            List<SegmentCommitInfo> segments = segmentInfos.AsList();
+            var segments = segmentInfos.AsList();
             int numSegments = segments.Count;
 
             if (Verbose())
@@ -462,7 +462,7 @@ namespace Lucene.Net.Index
                 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 @@ namespace Lucene.Net.Index
 
         private class SegmentInfoAndLevel : IComparable<SegmentInfoAndLevel>
         {
-            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 @@ namespace Lucene.Net.Index
             // Compute levels, which is just log (base mergeFactor)
             // of the size of each segment
             IList<SegmentInfoAndLevel> levels = new List<SegmentInfoAndLevel>();
-            float norm = (float)Math.Log(MergeFactor_Renamed);
+            var norm = (float)Math.Log(MergeFactor_Renamed);
 
             ICollection<SegmentCommitInfo> mergingSegments = Writer.Get().MergingSegments;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Index/SegmentInfos.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/SegmentInfos.cs b/src/Lucene.Net.Core/Index/SegmentInfos.cs
index 0b0fcb6..72ac8ea 100644
--- a/src/Lucene.Net.Core/Index/SegmentInfos.cs
+++ b/src/Lucene.Net.Core/Index/SegmentInfos.cs
@@ -4,6 +4,8 @@ using System.Diagnostics;
 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 @@ namespace Lucene.Net.Index
         /// Used to name new segments. </summary>
         public int Counter;
 
-        /// <summary>
-        /// Counts how often the index has been changed. </summary>
-        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
 
         /// <summary>
         /// Opaque Map&lt;String, String&gt; that user can specify during IndexWriter.commit </summary>
-        public IDictionary<string, string> UserData_Renamed = CollectionsHelper.EmptyMap<string, string>();
+        private IDictionary<string, string> _userData = CollectionsHelper.EmptyMap<string, string>();
 
         private List<SegmentCommitInfo> segments = new List<SegmentCommitInfo>();
 
@@ -191,7 +189,7 @@ namespace Lucene.Net.Index
                 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 @@ namespace Lucene.Net.Index
             {
                 return GetLastCommitGeneration(directory.ListAll());
             }
-            catch (NoSuchDirectoryException nsde)
+            catch (NoSuchDirectoryException)
             {
                 return -1;
             }
@@ -250,7 +248,7 @@ namespace Lucene.Net.Index
         {
             get
             {
-                return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", LastGeneration_Renamed);
+                return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, "", _lastGeneration);
             }
         }
 
@@ -300,10 +298,10 @@ namespace Lucene.Net.Index
                 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 @@ namespace Lucene.Net.Index
                 {
                     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 @@ namespace Lucene.Net.Index
             {
                 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 @@ namespace Lucene.Net.Index
             // 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 @@ namespace Lucene.Net.Index
                 {
                     // 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 @@ namespace Lucene.Net.Index
                         {
                             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 @@ namespace Lucene.Net.Index
                         }
                         Add(siPerCommit);
                     }
-                    UserData_Renamed = input.ReadStringStringMap();
+                    _userData = input.ReadStringStringMap();
                 }
                 else
                 {
@@ -466,7 +464,7 @@ namespace Lucene.Net.Index
         /// </summary>
         public void Read(Directory directory)
         {
-            Generation_Renamed = LastGeneration_Renamed = -1;
+            _generation = _lastGeneration = -1;
 
             new FindSegmentsFileAnonymousInnerClassHelper(this, directory).Run();
         }
@@ -475,7 +473,7 @@ namespace Lucene.Net.Index
         {
             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 @@ namespace Lucene.Net.Index
             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<string> upgradedSIFiles = new HashSet<string>();
+            var upgradedSIFiles = new HashSet<string>();
 
             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 @@ namespace Lucene.Net.Index
                                 @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 @@ namespace Lucene.Net.Index
                         {
                             directory.DeleteFile(fileName);
                         }
-                        catch (Exception t)
+                        catch (Exception)
                         {
                             // Suppress so we keep throwing the original exception
                         }
@@ -609,7 +607,7 @@ namespace Lucene.Net.Index
                         // the index:
                         directory.DeleteFile(segmentsFileName);
                     }
-                    catch (Exception t)
+                    catch (Exception)
                     {
                         // Suppress so we keep throwing the original exception
                     }
@@ -630,7 +628,7 @@ namespace Lucene.Net.Index
                     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 @@ namespace Lucene.Net.Index
 
         public object Clone()
         {
-            SegmentInfos sis = (SegmentInfos)base.MemberwiseClone();
+            var sis = (SegmentInfos)base.MemberwiseClone();
             // deep clone, first recreate all collections:
             sis.segments = new List<SegmentCommitInfo>(Size());
             foreach (SegmentCommitInfo info in segments)
@@ -714,7 +712,7 @@ namespace Lucene.Net.Index
                 // dont directly access segments, use add method!!!
                 sis.Add((SegmentCommitInfo)(info.Clone()));
             }
-            sis.UserData_Renamed = new Dictionary<string, string>(UserData_Renamed);
+            sis._userData = new Dictionary<string, string>(_userData);
             return sis;
         }
 
@@ -723,16 +721,11 @@ namespace Lucene.Net.Index
             get { return segments; }
         }
 
+
         /// <summary>
-        /// version number when this SegmentInfos was generated.
+        /// Counts how often the index has been changed.
         /// </summary>
-        public long Version
-        {
-            get
-            {
-                return Version_Renamed;
-            }
-        }
+        public long Version { get; set; }
 
         /// <summary>
         /// Returns current generation. </summary>
@@ -740,7 +733,7 @@ namespace Lucene.Net.Index
         {
             get
             {
-                return Generation_Renamed;
+                return _generation;
             }
         }
 
@@ -750,7 +743,7 @@ namespace Lucene.Net.Index
         {
             get
             {
-                return LastGeneration_Renamed;
+                return _lastGeneration;
             }
         }
 
@@ -1116,8 +1109,8 @@ namespace Lucene.Net.Index
         // 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 @@ namespace Lucene.Net.Index
 
                 // 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 @@ namespace Lucene.Net.Index
         /// </summary>
         public ICollection<string> Files(Directory dir, bool includeSegmentsFile)
         {
-            HashSet<string> files = new HashSet<string>();
+            var files = new HashSet<string>();
             if (includeSegmentsFile)
             {
                 string segmentFileName = SegmentsFileName;
@@ -1177,10 +1170,10 @@ namespace Lucene.Net.Index
                     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 @@ namespace Lucene.Net.Index
             // 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 @@ namespace Lucene.Net.Index
                     {
                         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);
         }
 
         /// <summary>
@@ -1288,7 +1281,7 @@ namespace Lucene.Net.Index
         /// Returns readable description of this segment. </summary>
         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 @@ namespace Lucene.Net.Index
         {
             get
             {
-                return UserData_Renamed;
+                return _userData;
             }
             set
             {
                 if (value == null)
                 {
-                    UserData_Renamed = CollectionsHelper.EmptyMap<string, string>();
+                    _userData = CollectionsHelper.EmptyMap<string, string>();
                 }
                 else
                 {
-                    UserData_Renamed = value;
+                    _userData = value;
                 }
             }
         }
@@ -1334,7 +1327,7 @@ namespace Lucene.Net.Index
         internal void Replace(SegmentInfos other)
         {
             RollbackSegmentInfos(other.AsList());
-            LastGeneration_Renamed = other.LastGeneration_Renamed;
+            _lastGeneration = other._lastGeneration;
         }
 
         /// <summary>
@@ -1352,14 +1345,14 @@ namespace Lucene.Net.Index
         /// </summary>
         public void Changed()
         {
-            Version_Renamed++;
+            Version++;
         }
 
         /// <summary>
         /// applies all changes caused by committing a merge to this SegmentInfos </summary>
         internal void ApplyMergeChanges(MergePolicy.OneMerge merge, bool dropSegment)
         {
-            HashSet<SegmentCommitInfo> mergedAway = new HashSet<SegmentCommitInfo>(merge.Segments);
+            var mergedAway = new HashSet<SegmentCommitInfo>(merge.Segments);
             bool inserted = false;
             int newSegIdx = 0;
             for (int segIdx = 0, cnt = segments.Count; segIdx < cnt; segIdx++)
@@ -1398,8 +1391,8 @@ namespace Lucene.Net.Index
 
         internal IList<SegmentCommitInfo> CreateBackupSegmentInfos()
         {
-            IList<SegmentCommitInfo> list = new List<SegmentCommitInfo>(Size());
-            foreach (SegmentCommitInfo info in segments)
+            var list = new List<SegmentCommitInfo>(Size());
+            foreach (var info in segments)
             {
                 Debug.Assert(info.Info.Codec != null);
                 list.Add((SegmentCommitInfo)(info.Clone()));
@@ -1415,9 +1408,9 @@ namespace Lucene.Net.Index
 
         /// <summary>
         /// Returns all contained segments as an <b>unmodifiable</b> <seealso cref="List"/> view. </summary>
-        public List<SegmentCommitInfo> AsList()
+        public IList<SegmentCommitInfo> AsList()
         {
-            return /*Collections.unmodifiableList*/(segments);
+            return Collections.UnmodifiableList<SegmentCommitInfo>(segments.ToArray());
         }
 
         /// <summary>
@@ -1438,7 +1431,7 @@ namespace Lucene.Net.Index
         /// Appends the provided <seealso cref="SegmentCommitInfo"/>s. </summary>
         public void AddAll(IEnumerable<SegmentCommitInfo> sis)
         {
-            foreach (SegmentCommitInfo si in sis)
+            foreach (var si in sis)
             {
                 this.Add(si);
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Support/CollectionsHelper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/CollectionsHelper.cs b/src/Lucene.Net.Core/Support/CollectionsHelper.cs
index ae79001..1a230d3 100644
--- a/src/Lucene.Net.Core/Support/CollectionsHelper.cs
+++ b/src/Lucene.Net.Core/Support/CollectionsHelper.cs
@@ -217,13 +217,6 @@ namespace Lucene.Net.Support
             return true;
         }
 
-        public static ISet<T> Singleton<T>(T single)
-        {
-            T[] singletonArr = new T[] { single };
-            HashSet<T> singleton = new HashSet<T>(singletonArr);
-            return singleton;
-        }
-
         /// <summary>
         /// Fills the array with an specific value from an specific index to an specific index.
         /// </summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
index 8c8a53e..5a54f49 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 @@ namespace Lucene.Net
         {
             return ImmutableList<T>.Empty;
         }
+
+        public static IList<T> UnmodifiableList<T>(IEnumerable<T> items)
+        {
+            return ImmutableList.Create<T>(items.ToArray());
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
index 7062269..ac3613f 100644
--- a/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Index/BaseStoredFieldsFormatTestCase.cs
@@ -401,9 +401,9 @@ namespace Lucene.Net.Index
             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);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs b/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs
index ce857e3..451108c 100644
--- a/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestSubScorerFreqs.cs
@@ -180,7 +180,7 @@ namespace Lucene.Net.Search
 
             // 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<ISet<string>> occurList = Arrays.AsList(CollectionsHelper.Singleton("MUST"), new HashSet<string>(Arrays.AsList("MUST", "SHOULD")));
+            IEnumerable<ISet<string>> occurList = Arrays.AsList(Collections.Singleton("MUST"), new HashSet<string>(Arrays.AsList("MUST", "SHOULD")));
 
             foreach (HashSet<string> occur in occurList)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
index 862d3d1..ecc0b31 100644
--- a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
@@ -385,7 +385,7 @@ namespace Lucene.Net.Store
                 // 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()));
                 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs
index fb71235..4f3b773 100644
--- a/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestFileSwitchDirectory.cs
@@ -147,8 +147,8 @@ namespace Lucene.Net.Store
         [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);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7a5aa5cc/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
index 7425024..217c851 100644
--- a/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestWindowsMMap.cs
@@ -74,31 +74,36 @@ namespace Lucene.Net.Store
             // 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)


[05/18] lucenenet git commit: Fix more sbyte -> byte conversion remnants, making more tests green

Posted by sy...@apache.org.
Fix more sbyte -> byte conversion remnants, making more tests green


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

Branch: refs/heads/master
Commit: 4b6eafe3dc63378a9d584a753f2e9785288fa6e2
Parents: 4560053
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 16:07:40 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 16:07:40 2015 +0200

----------------------------------------------------------------------
 .../Codecs/Lucene42/Lucene42DocValuesProducer.cs    |  4 +---
 src/Lucene.Net.Core/Store/DataInput.cs              | 12 +++---------
 src/Lucene.Net.Core/Util/Fst/FST.cs                 | 16 ++++++++--------
 src/Lucene.Net.Core/Util/Fst/Util.cs                |  2 +-
 src/Lucene.Net.Tests/core/Store/TestCopyBytes.cs    |  2 +-
 src/Lucene.Net.Tests/core/Store/TestHugeRamFile.cs  |  4 ++--
 6 files changed, 16 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4b6eafe3/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs b/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
index b635128..b3e7ca0 100644
--- a/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
+++ b/src/Lucene.Net.Core/Codecs/Lucene42/Lucene42DocValuesProducer.cs
@@ -167,9 +167,7 @@ namespace Lucene.Net.Codecs.Lucene42
                 int fieldType = meta.ReadByte();
                 if (fieldType == NUMBER)
                 {
-                    NumericEntry entry = new NumericEntry();
-                    entry.Offset = meta.ReadLong();
-                    entry.Format = meta.ReadSByte();
+                    var entry = new NumericEntry {Offset = meta.ReadLong(), Format = (sbyte)meta.ReadByte()};
                     switch (entry.Format)
                     {
                         case DELTA_COMPRESSED:

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4b6eafe3/src/Lucene.Net.Core/Store/DataInput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/DataInput.cs b/src/Lucene.Net.Core/Store/DataInput.cs
index 60e3b9f..58aef31 100644
--- a/src/Lucene.Net.Core/Store/DataInput.cs
+++ b/src/Lucene.Net.Core/Store/DataInput.cs
@@ -52,12 +52,6 @@ namespace Lucene.Net.Store
         /// <seealso cref= DataOutput#writeByte(byte) </seealso>
         public abstract byte ReadByte();
 
-        public sbyte ReadSByte()
-        {
-            // helper method to account for java's byte being signed
-            return (sbyte)ReadByte();
-        }
-
         /// <summary>
         /// Reads a specified number of bytes into an array at the specified offset. </summary>
         /// <param name="b"> the array to read bytes into </param>
@@ -247,8 +241,8 @@ namespace Lucene.Net.Store
         /// <seealso cref= DataOutput#writeString(String) </seealso>
         public virtual string ReadString()
         {
-            int length = ReadVInt();
-            byte[] bytes = new byte[length];
+            var length = ReadVInt();
+            var bytes = new byte[length];
             ReadBytes(bytes, 0, length);
 
             //return new string(bytes, 0, length, IOUtils.CHARSET_UTF_8);
@@ -323,7 +317,7 @@ namespace Lucene.Net.Store
             Debug.Assert(SkipBuffer.Length == SKIP_BUFFER_SIZE);
             for (long skipped = 0; skipped < numBytes; )
             {
-                int step = (int)Math.Min(SKIP_BUFFER_SIZE, numBytes - skipped);
+                var step = (int)Math.Min(SKIP_BUFFER_SIZE, numBytes - skipped);
                 ReadBytes(SkipBuffer, 0, step, false);
                 skipped += step;
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4b6eafe3/src/Lucene.Net.Core/Util/Fst/FST.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Fst/FST.cs b/src/Lucene.Net.Core/Util/Fst/FST.cs
index 17ec300..f01f91a 100644
--- a/src/Lucene.Net.Core/Util/Fst/FST.cs
+++ b/src/Lucene.Net.Core/Util/Fst/FST.cs
@@ -271,7 +271,7 @@ namespace Lucene.Net.Util.Fst
             {
                 emptyOutput = default(T);
             }
-            sbyte t = @in.ReadSByte();
+            var t = @in.ReadByte();
             switch (t)
             {
                 case 0:
@@ -930,7 +930,7 @@ namespace Lucene.Net.Util.Fst
             {
                 @in.Position = GetNodeAddress(follow.Target);
                 arc.Node = follow.Target;
-                sbyte b = @in.ReadSByte();
+                var b = (sbyte)@in.ReadByte();
                 if (b == ARCS_AS_FIXED_ARRAY)
                 {
                     // array: jump straight to end
@@ -979,7 +979,7 @@ namespace Lucene.Net.Util.Fst
                         {
                             ReadUnpackedNodeTarget(@in);
                         }
-                        arc.Flags = @in.ReadSByte();
+                        arc.Flags = (sbyte)@in.ReadByte();
                     }
                     // Undo the byte flags we read:
                     @in.SkipBytes(-1);
@@ -1130,7 +1130,7 @@ namespace Lucene.Net.Util.Fst
                 long pos = GetNodeAddress(arc.NextArc);
                 @in.Position = pos;
 
-                sbyte b = @in.ReadSByte();
+                var b = (sbyte)@in.ReadByte();
                 if (b == ARCS_AS_FIXED_ARRAY)
                 {
                     //System.out.println("    nextArc fixed array");
@@ -1195,7 +1195,7 @@ namespace Lucene.Net.Util.Fst
                 // arcs are packed
                 @in.Position = arc.NextArc;
             }
-            arc.Flags = @in.ReadSByte();
+            arc.Flags = (sbyte)@in.ReadByte();
             arc.Label = ReadLabel(@in);
 
             if (arc.Flag(BIT_ARC_HAS_OUTPUT))
@@ -2166,17 +2166,17 @@ namespace Lucene.Net.Util.Fst
         internal const sbyte ARCS_AS_FIXED_ARRAY = BIT_ARC_HAS_FINAL_OUTPUT;
 
         /// <summary>
-        /// <see cref="UnCompiledNode"/>
+        /// <see cref="Builder{T}.UnCompiledNode{S}"/>
         /// </summary>
         public const int FIXED_ARRAY_SHALLOW_DISTANCE = 3;
 
         /// <summary>
-        /// <see cref="UnCompiledNode"/>
+        /// <see cref="Builder{T}.UnCompiledNode{S}"/>
         /// </summary>
         public const int FIXED_ARRAY_NUM_ARCS_SHALLOW = 5;
 
         /// <summary>
-        /// <see cref="UnCompiledNode"/>
+        /// <see cref="Builder{T}.UnCompiledNode{S}"/>
         /// </summary>
         public const int FIXED_ARRAY_NUM_ARCS_DEEP = 10;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4b6eafe3/src/Lucene.Net.Core/Util/Fst/Util.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Fst/Util.cs b/src/Lucene.Net.Core/Util/Fst/Util.cs
index 46260e9..96d97c3 100644
--- a/src/Lucene.Net.Core/Util/Fst/Util.cs
+++ b/src/Lucene.Net.Core/Util/Fst/Util.cs
@@ -189,7 +189,7 @@ namespace Lucene.Net.Util.Fst
                             mid = (int)((uint)(low + high) >> 1);
                             @in.Position = arc.PosArcsStart;
                             @in.SkipBytes(arc.BytesPerArc * mid);
-                            sbyte flags = @in.ReadSByte();
+                            var flags = (sbyte)@in.ReadByte();
                             fst.ReadLabel(@in);
                             long minArcOutput;
                             if ((flags & FST<long>.BIT_ARC_HAS_OUTPUT) != 0)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4b6eafe3/src/Lucene.Net.Tests/core/Store/TestCopyBytes.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestCopyBytes.cs b/src/Lucene.Net.Tests/core/Store/TestCopyBytes.cs
index d8cd1df..34b5044 100644
--- a/src/Lucene.Net.Tests/core/Store/TestCopyBytes.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestCopyBytes.cs
@@ -99,7 +99,7 @@ namespace Lucene.Net.Store
                 {
                     if (Random().NextBoolean())
                     {
-                        sbyte v = in2.ReadSByte();
+                        var v = in2.ReadByte();
                         Assert.AreEqual(Value(upto), v);
                         upto++;
                     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4b6eafe3/src/Lucene.Net.Tests/core/Store/TestHugeRamFile.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestHugeRamFile.cs b/src/Lucene.Net.Tests/core/Store/TestHugeRamFile.cs
index 12bb083..e5e405e 100644
--- a/src/Lucene.Net.Tests/core/Store/TestHugeRamFile.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestHugeRamFile.cs
@@ -114,8 +114,8 @@ namespace Lucene.Net.Store
                 @in.Seek(loc);
                 for (int i = 0; i < m; i++)
                 {
-                    sbyte bt = @in.ReadSByte();
-                    sbyte expected = (sbyte)(1 + j + (i & 0x0003F));
+                    var bt = (sbyte)@in.ReadByte();
+                    var expected = (sbyte)(1 + j + (i & 0x0003F));
                     Assert.AreEqual(expected, bt, "must read same value that was written! j=" + j + " i=" + i);
                 }
             }


[04/18] lucenenet git commit: Strengthening tests and adding TODO

Posted by sy...@apache.org.
Strengthening tests and adding TODO


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

Branch: refs/heads/master
Commit: 45600538e109ee8b136ce50843b2c87ef7c5def1
Parents: 26de7b8
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 16:00:08 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 16:00:08 2015 +0200

----------------------------------------------------------------------
 .../core/Store/TestNRTCachingDirectory.cs       | 32 +++++++++-----------
 1 file changed, 15 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/45600538/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs
index 6d34509..177bd44 100644
--- a/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs
@@ -138,28 +138,26 @@ namespace Lucene.Net.Store
         }
 
         // LUCENE-3382 -- make sure we get exception if the directory really does not exist.
-        [Test]
+        [Test, Timeout(int.MaxValue)]
         public virtual void TestNoDir()
         {
-            //Directory tempDir = CreateTempDir("doesnotexist");
-
-            string tempDir = Path.GetTempPath();
-            if (tempDir == null)
-                throw new IOException("java.io.tmpdir undefined, cannot run test");
-            DirectoryInfo TempDir = new DirectoryInfo(Path.Combine(tempDir, "RAMDirIndex"));
+            // LUCENENET TODO mysterious failure - FSDirectory recreates the folder by design, not sure why this passes for Java Lucene
 
-            System.IO.Directory.Delete(TempDir.FullName, true);
-            Directory dir = new NRTCachingDirectory(NewFSDirectory(TempDir), 2.0, 25.0);
-            try
-            {
-                DirectoryReader.Open(dir);
-                Assert.Fail("did not hit expected exception");
-            }
-            catch (NoSuchDirectoryException nsde)
+            var tempDir = CreateTempDir("doesnotexist").FullName;
+            System.IO.Directory.Delete(tempDir, true);
+            using (Directory dir = new NRTCachingDirectory(NewFSDirectory(new DirectoryInfo(tempDir)), 2.0, 25.0))
             {
-                // expected
+                try
+                {
+                    Assert.False(System.IO.Directory.Exists(tempDir));
+                    DirectoryReader.Open(dir);
+                    Assert.Fail("did not hit expected exception");
+                }
+                catch (NoSuchDirectoryException)
+                {
+                    // expected
+                }
             }
-            dir.Dispose();
         }
 
         // LUCENE-3382 test that we can add a file, and then when we call list() we get it back


[13/18] lucenenet git commit: Fix possible endless recursive call

Posted by sy...@apache.org.
Fix possible endless recursive call


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

Branch: refs/heads/master
Commit: b0bbd9e0b85ec9ddb457a82f6d720ffbe1bb91a9
Parents: dae38d4
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 18:39:56 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 18:39:56 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Store/BaseDirectory.cs         |  2 --
 src/Lucene.Net.Core/Store/CompoundFileDirectory.cs |  8 ++++----
 src/Lucene.Net.Core/Store/Directory.cs             | 11 ++++-------
 src/Lucene.Net.Core/Store/FSDirectory.cs           |  5 +----
 src/Lucene.Net.Core/Store/RAMDirectory.cs          |  2 +-
 5 files changed, 10 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b0bbd9e0/src/Lucene.Net.Core/Store/BaseDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/BaseDirectory.cs b/src/Lucene.Net.Core/Store/BaseDirectory.cs
index 4fc9d75..120c072 100644
--- a/src/Lucene.Net.Core/Store/BaseDirectory.cs
+++ b/src/Lucene.Net.Core/Store/BaseDirectory.cs
@@ -25,8 +25,6 @@ namespace Lucene.Net.Store
     /// </summary>
     public abstract class BaseDirectory : Directory
     {
-        volatile protected internal bool IsOpen = true;
-
         /// <summary>
         /// Holds the LockFactory instance (implements locking for
         /// this Directory instance).

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b0bbd9e0/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 cbb42f9..061048f 100644
--- a/src/Lucene.Net.Core/Store/CompoundFileDirectory.cs
+++ b/src/Lucene.Net.Core/Store/CompoundFileDirectory.cs
@@ -99,7 +99,7 @@ namespace Lucene.Net.Store
             this.Directory_Renamed = directory;
             this.FileName = fileName;
             this.ReadBufferSize = BufferedIndexInput.BufferSize(context);
-            this.IsOpen = false;
+            this.isOpen = false;
             this.OpenForWrite = openForWrite;
             if (!openForWrite)
             {
@@ -117,14 +117,14 @@ namespace Lucene.Net.Store
                         IOUtils.CloseWhileHandlingException(Handle);
                     }
                 }
-                this.IsOpen = true;
+                this.isOpen = true;
                 Writer = null;
             }
             else
             {
                 Debug.Assert(!(directory is CompoundFileDirectory), "compound file inside of compound file: " + fileName);
                 this.Entries = SENTINEL;
-                this.IsOpen = true;
+                this.isOpen = true;
                 Writer = new CompoundFileWriter(directory, fileName);
                 Handle = null;
             }
@@ -301,7 +301,7 @@ namespace Lucene.Net.Store
                     // allow double close - usually to be consistent with other closeables
                     return; // already closed
                 }
-                IsOpen = false;
+                isOpen = false;
                 if (Writer != null)
                 {
                     Debug.Assert(OpenForWrite);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b0bbd9e0/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 7c341a1..82f2582 100644
--- a/src/Lucene.Net.Core/Store/Directory.cs
+++ b/src/Lucene.Net.Core/Store/Directory.cs
@@ -323,9 +323,9 @@ namespace Lucene.Net.Store
         /// </summary>
         private sealed class SlicedIndexInput : BufferedIndexInput
         {
-            internal IndexInput @base;
-            internal long FileOffset;
-            internal long Length_Renamed;
+            private IndexInput @base;
+            private long FileOffset;
+            private long Length_Renamed;
 
             internal SlicedIndexInput(string sliceDescription, IndexInput @base, long fileOffset, long length)
                 : this(sliceDescription, @base, fileOffset, length, BufferedIndexInput.BUFFER_SIZE)
@@ -385,9 +385,6 @@ namespace Lucene.Net.Store
             }
         }
 
-        public virtual bool IsOpen
-        {
-            get { return IsOpen; }
-        }
+        public virtual bool IsOpen { get { return isOpen; }}
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b0bbd9e0/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 4e70822..0eb6c3f 100644
--- a/src/Lucene.Net.Core/Store/FSDirectory.cs
+++ b/src/Lucene.Net.Core/Store/FSDirectory.cs
@@ -434,10 +434,7 @@ namespace Lucene.Net.Store
         /// Closes the store to future operations. </summary>
         public override void Dispose()
         {
-            lock (this)
-            {
-                IsOpen = false;
-            }
+            isOpen = false;
         }
 
         /// <returns> the underlying filesystem directory </returns>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b0bbd9e0/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 83da12a..7ced79b 100644
--- a/src/Lucene.Net.Core/Store/RAMDirectory.cs
+++ b/src/Lucene.Net.Core/Store/RAMDirectory.cs
@@ -252,7 +252,7 @@ namespace Lucene.Net.Store
         /// Closes the store to future operations, releasing associated memory. </summary>
         public override void Dispose()
         {
-            IsOpen = false;
+            isOpen = false;
             FileMap.Clear();
         }
     }


[18/18] lucenenet git commit: TODOs

Posted by sy...@apache.org.
TODOs


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

Branch: refs/heads/master
Commit: f09cd685e2a7caed4c2350408ea43ffd8665076f
Parents: a098c0b
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Tue Jan 6 02:59:26 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Tue Jan 6 02:59:26 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Index/IndexReader.cs                | 9 +++++----
 src/Lucene.Net.Tests/core/Index/TestIndexReaderClose.cs | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f09cd685/src/Lucene.Net.Core/Index/IndexReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/IndexReader.cs b/src/Lucene.Net.Core/Index/IndexReader.cs
index f0fd9fa..9679453 100644
--- a/src/Lucene.Net.Core/Index/IndexReader.cs
+++ b/src/Lucene.Net.Core/Index/IndexReader.cs
@@ -78,7 +78,7 @@ namespace Lucene.Net.Index
         private bool ClosedByChild = false;
         private readonly AtomicInteger refCount = new AtomicInteger(1);
 
-        internal IndexReader()
+        protected IndexReader()
         {
             if (!(this is CompositeReader || this is AtomicReader))
             {
@@ -148,6 +148,7 @@ namespace Lucene.Net.Index
             {
                 foreach (ReaderClosedListener listener in ReaderClosedListeners)
                 {
+                    // LUCENENET TODO
                     /*try
                     {*/
                     listener.OnClose(this);
@@ -328,7 +329,7 @@ namespace Lucene.Net.Index
         /// <summary>
         /// {@inheritDoc}
         /// <p>For caching purposes, {@code IndexReader} subclasses are not allowed
-        /// to implement equals/hashCode, so methods are declared final.
+        /// to implement equals/hashCode, so methods are declared sealed.
         /// To lookup instances from caches use <seealso cref="#getCoreCacheKey"/> and
         /// <seealso cref="#getCombinedCoreAndDeletesKey"/>.
         /// </summary>
@@ -514,7 +515,7 @@ namespace Lucene.Net.Index
         // IndexableField
         public Document Document(int docID)
         {
-            DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor();
+            var visitor = new DocumentStoredFieldVisitor();
             Document(docID, visitor);
             return visitor.Document;
         }
@@ -526,7 +527,7 @@ namespace Lucene.Net.Index
         /// </summary>
         public Document Document(int docID, ISet<string> fieldsToLoad)
         {
-            DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(fieldsToLoad);
+            var visitor = new DocumentStoredFieldVisitor(fieldsToLoad);
             Document(docID, visitor);
             return visitor.Document;
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f09cd685/src/Lucene.Net.Tests/core/Index/TestIndexReaderClose.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestIndexReaderClose.cs b/src/Lucene.Net.Tests/core/Index/TestIndexReaderClose.cs
index 8c785bd..e1d0bef 100644
--- a/src/Lucene.Net.Tests/core/Index/TestIndexReaderClose.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestIndexReaderClose.cs
@@ -35,7 +35,7 @@ namespace Lucene.Net.Index
         [Test]
         public virtual void TestCloseUnderException()
         {
-            int iters = 1000 + 1 + Random().Next(20);
+            int iters = 1000 + 1 + Random().Next(20); // LUCENENET TODO why so many times? maybe switch to nightly?
             for (int j = 0; j < iters; j++)
             {
                 Directory dir = NewDirectory();


[12/18] lucenenet git commit: Tests

Posted by sy...@apache.org.
Tests


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

Branch: refs/heads/master
Commit: dae38d464346d4935f83acbf1390afd0d88a68fe
Parents: d71f714
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 18:25:04 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 18:25:04 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs | 3 ++-
 src/Lucene.Net.Tests/core/Store/TestLockFactory.cs         | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/dae38d46/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 c4f8089..e7e292f 100644
--- a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
+++ b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
@@ -914,7 +914,8 @@ namespace Lucene.Net.Store
                 }
                 if (OpenLocks.Count > 0)
                 {
-                    throw new Exception("MockDirectoryWrapper: cannot close: there are still open locks: " + OpenLocks.ToArray());
+                    throw new Exception("MockDirectoryWrapper: cannot close: there are still open locks: "
+                        + String.Join(" ,", OpenLocks.ToArray()));
                 }
 
                 IsOpen = false;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/dae38d46/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs b/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
index b74a4c7..a3230ff 100644
--- a/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
@@ -149,7 +149,7 @@ namespace Lucene.Net.Store
         // Verify: do stress test, by opening IndexReaders and
         // IndexWriters over & over in 2 threads and making sure
         // no unexpected exceptions are raised:
-        [Test, Nightly, Timeout(int.MaxValue)]
+        [Test/*, Nightly, Timeout(int.MaxValue)*/]
         public virtual void TestStressLocks()
         {
             _testStressLocks(null, CreateTempDir("index.TestLockFactory6"));
@@ -159,7 +159,7 @@ namespace Lucene.Net.Store
         // IndexWriters over & over in 2 threads and making sure
         // no unexpected exceptions are raised, but use
         // NativeFSLockFactory:
-        [Test, Nightly, Timeout(int.MaxValue)]
+        [Test/*, Nightly, Timeout(int.MaxValue)*/]
         public virtual void TestStressLocksNativeFSLockFactory()
         {
             DirectoryInfo dir = CreateTempDir("index.TestLockFactory7");


[09/18] lucenenet git commit: Fix NativeFSLock, round 1

Posted by sy...@apache.org.
Fix NativeFSLock, round 1

We should be making locks properly based on the characteristics of the CLR and Windows

All relevant unit tests are now green


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

Branch: refs/heads/master
Commit: 8a999e1f6629ffa16d51bf7ebef8f303d5c7ca3f
Parents: cb2dfdc
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 17:47:48 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 17:47:48 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Store/Lock.cs               |   7 +-
 .../Store/NativeFSLockFactory.cs                | 246 ++++---------------
 .../Util/LuceneTestCase.cs                      |   1 -
 .../core/Store/TestLockFactory.cs               |  27 +-
 4 files changed, 62 insertions(+), 219 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8a999e1f/src/Lucene.Net.Core/Store/Lock.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/Lock.cs b/src/Lucene.Net.Core/Store/Lock.cs
index a0682c8..722d9fc 100644
--- a/src/Lucene.Net.Core/Store/Lock.cs
+++ b/src/Lucene.Net.Core/Store/Lock.cs
@@ -32,9 +32,7 @@ namespace Lucene.Net.Store
     ///   }.run();
     /// </pre>
     /// </summary>
-    /// <seealso cref= Directory#makeLock(String)
-    ///
-    /// @lucene.internal </seealso>
+    /// <seealso cref="Directory#makeLock(String)"/>
     public abstract class Lock : IDisposable
     {
         /// <summary>
@@ -61,7 +59,7 @@ namespace Lucene.Net.Store
         /// with the "root cause" Exception as to why the lock was
         /// not obtained.
         /// </summary>
-        protected internal Exception FailureReason;
+        public Exception FailureReason { get; protected set; }
 
         /// <summary>
         /// Attempts to obtain an exclusive lock within amount of
@@ -121,6 +119,7 @@ namespace Lucene.Net.Store
 
         public virtual void Dispose()
         {
+            Release();
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8a999e1f/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs b/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
index e21210a..fd98b94 100644
--- a/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
+++ b/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
@@ -1,6 +1,9 @@
+using System;
+using System.Collections.Concurrent;
+using Lucene.Net.Util;
+
 namespace Lucene.Net.Store
 {
-    using System.Collections.Generic;
     using System.IO;
 
     /*
@@ -112,13 +115,11 @@ namespace Lucene.Net.Store
 
     internal class NativeFSLock : Lock
     {
-        private System.IO.FileStream f;
         private FileStream Channel;
-        private bool @lock;
-        private DirectoryInfo Path;
-        private DirectoryInfo LockDir;
+        private readonly DirectoryInfo Path;
+        private readonly DirectoryInfo LockDir;
 
-        /*
+      /*
        * The javadocs for FileChannel state that you should have
        * a single instance of a FileChannel (per JVM) for all
        * locking against a given file.  To ensure this, we have
@@ -128,7 +129,7 @@ namespace Lucene.Net.Store
        * one JVM (each with their own NativeFSLockFactory
        * instance) have set the same lock dir and lock prefix.
        */
-        private static HashSet<string> LOCK_HELD = new HashSet<string>();
+        private static readonly ConcurrentDictionary<string, WeakReference<FileStream>> LOCKS_HELD = new ConcurrentDictionary<string, WeakReference<FileStream>>();
 
         public NativeFSLock(DirectoryInfo lockDir, string lockFileName)
         {
@@ -136,32 +137,19 @@ namespace Lucene.Net.Store
             Path = new DirectoryInfo(System.IO.Path.Combine(lockDir.FullName, lockFileName));
         }
 
-        private bool LockExists()
-        {
-            lock (this)
-            {
-                return @lock != false;
-            }
-        }
-
         public override bool Obtain()
         {
             lock (this)
             {
-                if (LockExists())
+                if (Channel != null)
                 {
                     // Our instance is already locked:
                     return false;
                 }
 
-                // Ensure that lockDir exists and is a directory.
-                bool tmpBool;
-                if (System.IO.File.Exists(LockDir.FullName))
-                    tmpBool = true;
-                else
-                    tmpBool = System.IO.Directory.Exists(LockDir.FullName);
+                //LOCKS_HELD.GetOrAdd(Path.FullName)
 
-                if (!tmpBool)
+                if (!System.IO.Directory.Exists(LockDir.FullName))
                 {
                     try
                     {
@@ -172,192 +160,57 @@ namespace Lucene.Net.Store
                         throw new System.IO.IOException("Cannot create directory: " + LockDir.FullName);
                     }
                 }
-                else if (!System.IO.Directory.Exists(LockDir.FullName))
+                else if (System.IO.File.Exists(LockDir.FullName))
                 {
                     throw new System.IO.IOException("Found regular file where directory expected: " + LockDir.FullName);
                 }
 
-                string canonicalPath = Path.FullName;
-
-                bool markedHeld = false;
-
+                bool success = false;
                 try
                 {
-                    // Make sure nobody else in-process has this lock held
-                    // already, and, mark it held if not:
-
-                    lock (LOCK_HELD)
-                    {
-                        if (LOCK_HELD.Contains(canonicalPath))
-                        {
-                            // Someone else in this JVM already has the lock:
-                            return false;
-                        }
-                        else
-                        {
-                            // This "reserves" the fact that we are the one
-                            // thread trying to obtain this lock, so we own
-                            // the only instance of a channel against this
-                            // file:
-                            LOCK_HELD.Add(canonicalPath);
-                            markedHeld = true;
-                        }
-                    }
-
-                    try
-                    {
-                        f = new System.IO.FileStream(Path.FullName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
-                    }
-                    catch (System.IO.IOException e)
-                    {
-                        // On Windows, we can get intermittent "Access
-                        // Denied" here.  So, we treat this as failure to
-                        // acquire the lock, but, store the reason in case
-                        // there is in fact a real error case.
-                        FailureReason = e;
-                        f = null;
-                    }
-                    // lucene.net: UnauthorizedAccessException does not derive from IOException like in java
-                    catch (System.UnauthorizedAccessException e)
-                    {
-                        // On Windows, we can get intermittent "Access
-                        // Denied" here.  So, we treat this as failure to
-                        // acquire the lock, but, store the reason in case
-                        // there is in fact a real error case.
-                        FailureReason = e;
-                        f = null;
-                    }
-
-                    if (f != null)
+                    Channel = new FileStream(Path.FullName, FileMode.Create, FileAccess.Write, FileShare.None);
+                    Channel.Lock(0, Channel.Length);
+                    success = true;
+                }
+                catch (IOException e)
+                {
+                    FailureReason = e;
+                    Channel = null;
+                }
+                // LUCENENET: UnauthorizedAccessException does not derive from IOException like in java
+                catch (System.UnauthorizedAccessException e)
+                {
+                    // On Windows, we can get intermittent "Access
+                    // Denied" here.  So, we treat this as failure to
+                    // acquire the lock, but, store the reason in case
+                    // there is in fact a real error case.
+                    FailureReason = e;
+                    Channel = null;
+                }
+                finally
+                {
+                    if (!success)
                     {
                         try
                         {
-                            Channel = f;
-                            @lock = false;
-                            try
-                            {
-                                Channel.Lock(0, Channel.Length);
-                                @lock = true;
-                            }
-                            catch (System.IO.IOException e)
-                            {
-                                // At least on OS X, we will sometimes get an
-                                // intermittent "Permission Denied" IOException,
-                                // which seems to simply mean "you failed to get
-                                // the lock".  But other IOExceptions could be
-                                // "permanent" (eg, locking is not supported via
-                                // the filesystem).  So, we record the failure
-                                // reason here; the timeout obtain (usually the
-                                // one calling us) will use this as "root cause"
-                                // if it fails to get the lock.
-                                FailureReason = e;
-                            }
-                            // lucene.net: UnauthorizedAccessException does not derive from IOException like in java
-                            catch (System.UnauthorizedAccessException e)
-                            {
-                                // At least on OS X, we will sometimes get an
-                                // intermittent "Permission Denied" IOException,
-                                // which seems to simply mean "you failed to get
-                                // the lock".  But other IOExceptions could be
-                                // "permanent" (eg, locking is not supported via
-                                // the filesystem).  So, we record the failure
-                                // reason here; the timeout obtain (usually the
-                                // one calling us) will use this as "root cause"
-                                // if it fails to get the lock.
-                                FailureReason = e;
-                            }
-                            finally
-                            {
-                                if (@lock == false)
-                                {
-                                    try
-                                    {
-                                        Channel.Close();
-                                    }
-                                    finally
-                                    {
-                                        Channel = null;
-                                    }
-                                }
-                            }
+                            IOUtils.CloseWhileHandlingException(Channel);
                         }
                         finally
                         {
-                            if (Channel == null)
-                            {
-                                try
-                                {
-                                    f.Close();
-                                }
-                                finally
-                                {
-                                    f = null;
-                                }
-                            }
-                        }
-                    }
-                }
-                finally
-                {
-                    if (markedHeld && !LockExists())
-                    {
-                        lock (LOCK_HELD)
-                        {
-                            if (LOCK_HELD.Contains(canonicalPath))
-                            {
-                                LOCK_HELD.Remove(canonicalPath);
-                            }
+                            Channel = null;
                         }
                     }
                 }
-                return LockExists();
-            }
-
-            /*
 
-              Channel = FileChannel.open(Path.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
-              bool success = false;
-              try
-              {
-                @lock = Channel.TryLock();
-                success = @lock != null;
-              }
-              catch (System.IO.IOException | OverlappingFileLockException e)
-              {
-                // At least on OS X, we will sometimes get an
-                // intermittent "Permission Denied" System.IO.IOException,
-                // which seems to simply mean "you failed to get
-                // the lock".  But other System.IO.IOExceptions could be
-                // "permanent" (eg, locking is not supported via
-                // the filesystem).  So, we record the failure
-                // reason here; the timeout obtain (usually the
-                // one calling us) will use this as "root cause"
-                // if it fails to get the lock.
-                FailureReason = e;
-              }
-              finally
-              {
-                if (!success)
-                {
-                  try
-                  {
-                    IOUtils.CloseWhileHandlingException(Channel);
-                  }
-                  finally
-                  {
-                    Channel = null;
-                  }
-                }
-              }
-              return @lock != null;
-            }*/
+                return Channel != null;
+            }
         }
 
         public override void Release()
         {
             lock (this)
             {
-                if (LockExists())
+                if (Channel != null)
                 {
                     try
                     {
@@ -365,7 +218,6 @@ namespace Lucene.Net.Store
                     }
                     finally
                     {
-                        @lock = false;
                         try
                         {
                             Channel.Close();
@@ -373,18 +225,10 @@ namespace Lucene.Net.Store
                         finally
                         {
                             Channel = null;
-                            try
-                            {
-                                f.Close();
-                            }
-                            finally
-                            {
-                                f = null;
-                                lock (LOCK_HELD)
-                                {
-                                    LOCK_HELD.Remove(Path.FullName);
-                                }
-                            }
+//                            lock (LOCK_HELD)
+//                            {
+//                                LOCK_HELD.Remove(Path.FullName);
+//                            }
                         }
                     }
                     bool tmpBool;
@@ -419,7 +263,7 @@ namespace Lucene.Net.Store
                     // The test for is isLocked is not directly possible with native file locks:
 
                     // First a shortcut, if a lock reference in this instance is available
-                    if (LockExists())
+                    if (Channel != null)
                     {
                         return true;
                     }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8a999e1f/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
index 9d829ea..66bf0ca 100644
--- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
@@ -638,7 +638,6 @@ namespace Lucene.Net.Util
         {
             get
             {
-                //return ClassNameRule.TestClass;
                 return typeof(LuceneTestCase);
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8a999e1f/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs b/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
index d779d39..b74a4c7 100644
--- a/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestLockFactory.cs
@@ -197,22 +197,21 @@ namespace Lucene.Net.Store
         [Test]
         public virtual void TestNativeFSLockFactory()
         {
-            //NativeFSLockFactory f = new NativeFSLockFactory(CreateTempDir(LuceneTestCase.TestClass.SimpleName));
-            NativeFSLockFactory f = new NativeFSLockFactory(AppSettings.Get("tempDir", Path.GetTempPath()));
+            var f = new NativeFSLockFactory(CreateTempDir("testNativeFsLockFactory"));
 
             f.LockPrefix = "test";
-            Lock l = f.MakeLock("commit");
-            Lock l2 = f.MakeLock("commit");
+            var l = f.MakeLock("commit");
+            var l2 = f.MakeLock("commit");
 
-            Assert.IsTrue(l.Obtain(), "failed to obtain lock");
+            Assert.IsTrue(l.Obtain(), "failed to obtain lock, got exception: {0}", l.FailureReason);
             Assert.IsTrue(!l2.Obtain(), "succeeded in obtaining lock twice");
             l.Dispose();
 
-            Assert.IsTrue(l2.Obtain(), "failed to obtain 2nd lock after first one was freed");
+            Assert.IsTrue(l2.Obtain(), "failed to obtain 2nd lock after first one was freed, got exception: {0}", l2.FailureReason);
             l2.Dispose();
 
             // Make sure we can obtain first one again, test isLocked():
-            Assert.IsTrue(l.Obtain(), "failed to obtain lock");
+            Assert.IsTrue(l.Obtain(), "failed to obtain lock, got exception: {0}", l.FailureReason);
             Assert.IsTrue(l.Locked);
             Assert.IsTrue(l2.Locked);
             l.Dispose();
@@ -224,14 +223,16 @@ namespace Lucene.Net.Store
         [Test]
         public virtual void TestNativeFSLockFactoryLockExists()
         {
-            DirectoryInfo tempDir = new DirectoryInfo(AppSettings.Get("tempDir", Path.GetTempPath()));
-            FileInfo lockFile = new FileInfo(/*tempDir, */"test.lock");
-            lockFile.Create();
+            DirectoryInfo tempDir = CreateTempDir("testNativeFsLockFactory");
 
-            Lock l = (new NativeFSLockFactory(tempDir)).MakeLock("test.lock");
-            Assert.IsTrue(l.Obtain(), "failed to obtain lock");
+            // Touch the lock file
+            var lockFile = new FileInfo(Path.Combine(tempDir.FullName, "test.lock"));
+            using (lockFile.Create()){};
+
+            var l = (new NativeFSLockFactory(tempDir)).MakeLock("test.lock");
+            Assert.IsTrue(l.Obtain(), "failed to obtain lock, got exception: {0}", l.FailureReason);
             l.Dispose();
-            Assert.IsFalse(l.Locked, "failed to release lock");
+            Assert.IsFalse(l.Locked, "failed to release lock, got exception: {0}", l.FailureReason);
             if (lockFile.Exists)
             {
                 lockFile.Delete();


[14/18] lucenenet git commit: NativeFSLocks in Java are de facto singletons

Posted by sy...@apache.org.
NativeFSLocks in Java are de facto singletons

We need to mimick that behavior otherwise IW.IsLocked and IW.Unlock aren't going to work

There may be holes in this current implementation since we may be storing Lock instances of failed locks, but lets go with this for now


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

Branch: refs/heads/master
Commit: fbabfe9ecedd10837136d0aa37011dbfacebfc67
Parents: b0bbd9e
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 19:05:40 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 19:05:40 2015 +0200

----------------------------------------------------------------------
 .../Store/NativeFSLockFactory.cs                | 21 +++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fbabfe9e/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs b/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
index f7c370e..0baf36c 100644
--- a/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
+++ b/src/Lucene.Net.Core/Store/NativeFSLockFactory.cs
@@ -96,16 +96,18 @@ namespace Lucene.Net.Store
             LockDir = lockDir;
         }
 
+        // LUCENENET NativeFSLocks in Java are infact singletons; this is how we mimick that to track instances and make sure
+        // IW.Unlock and IW.IsLocked works correctly
+        internal readonly ConcurrentDictionary<string, NativeFSLock> _locks = new ConcurrentDictionary<string, NativeFSLock>(); 
+
         public override Lock MakeLock(string lockName)
         {
-            lock (this)
+            if (LockPrefix_Renamed != null)
             {
-                if (LockPrefix_Renamed != null)
-                {
-                    lockName = LockPrefix_Renamed + "-" + lockName;
-                }
-                return new NativeFSLock(LockDir_Renamed, lockName);
+                lockName = LockPrefix_Renamed + "-" + lockName;
             }
+
+            return _locks.GetOrAdd(lockName, (s) => new NativeFSLock(this, LockDir_Renamed, s));
         }
 
         public override void ClearLock(string lockName)
@@ -118,10 +120,12 @@ namespace Lucene.Net.Store
     {
         private FileStream Channel;
         private readonly DirectoryInfo Path;
+        private readonly NativeFSLockFactory _creatingInstance;
         private readonly DirectoryInfo LockDir;
 
-        public NativeFSLock(DirectoryInfo lockDir, string lockFileName)
+        public NativeFSLock(NativeFSLockFactory creatingInstance, DirectoryInfo lockDir, string lockFileName)
         {
+            _creatingInstance = creatingInstance;
             this.LockDir = lockDir;
             Path = new DirectoryInfo(System.IO.Path.Combine(lockDir.FullName, lockFileName));
         }
@@ -200,6 +204,9 @@ namespace Lucene.Net.Store
                     try
                     {
                         Channel.Unlock(0, Channel.Length);
+
+                        NativeFSLock _;
+                        _creatingInstance._locks.TryRemove(Path.FullName, out _);
                     }
                     finally
                     {


[03/18] lucenenet git commit: Cleanup temporary files after test run

Posted by sy...@apache.org.
Cleanup temporary files after test run

And a few other minor cleanups


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

Branch: refs/heads/master
Commit: 26de7b85a6c45b13cb425174144ba3cafb96299c
Parents: 7a5aa5c
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 15:42:09 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 15:42:09 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Index/SegmentInfos.cs       |  4 +-
 .../Index/StandardDirectoryReader.cs            |  8 +-
 .../Util/LuceneTestCase.cs                      | 90 +++++++++-----------
 3 files changed, 45 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/26de7b85/src/Lucene.Net.Core/Index/SegmentInfos.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/SegmentInfos.cs b/src/Lucene.Net.Core/Index/SegmentInfos.cs
index 72ac8ea..c4e29ca 100644
--- a/src/Lucene.Net.Core/Index/SegmentInfos.cs
+++ b/src/Lucene.Net.Core/Index/SegmentInfos.cs
@@ -348,7 +348,7 @@ namespace Lucene.Net.Index
         /// <exception cref="IOException"> if there is a low-level IO error </exception>
         public void Read(Directory directory, string segmentFileName)
         {
-            bool success = false;
+            var success = false;
 
             // Clear any previous segments:
             this.Clear();
@@ -357,7 +357,7 @@ namespace Lucene.Net.Index
 
             _lastGeneration = _generation;
 
-            ChecksumIndexInput input = directory.OpenChecksumInput(segmentFileName, IOContext.READ);
+            var input = directory.OpenChecksumInput(segmentFileName, IOContext.READ);
             try
             {
                 int format = input.ReadInt();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/26de7b85/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs b/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs
index c256d7b..72e4b26 100644
--- a/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs
+++ b/src/Lucene.Net.Core/Index/StandardDirectoryReader.cs
@@ -55,8 +55,8 @@ namespace Lucene.Net.Index
 
         private class FindSegmentsFileAnonymousInnerClassHelper : SegmentInfos.FindSegmentsFile
         {
-            private new Directory Directory;
-            private int TermInfosIndexDivisor;
+            private new readonly Directory Directory;
+            private readonly int TermInfosIndexDivisor;
 
             public FindSegmentsFileAnonymousInnerClassHelper(Directory directory, int termInfosIndexDivisor)
                 : base(directory)
@@ -67,9 +67,9 @@ namespace Lucene.Net.Index
 
             protected internal override object DoBody(string segmentFileName)
             {
-                SegmentInfos sis = new SegmentInfos();
+                var sis = new SegmentInfos();
                 sis.Read(Directory, segmentFileName);
-                SegmentReader[] readers = new SegmentReader[sis.Size()];
+                var readers = new SegmentReader[sis.Size()];
                 for (int i = sis.Size() - 1; i >= 0; i--)
                 {
                     System.IO.IOException prior = null;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/26de7b85/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
index 42ce3ee..9d829ea 100644
--- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
@@ -15,6 +15,7 @@
 * limitations under the License.
 */
 
+using System.Collections.Concurrent;
 using System.Runtime.CompilerServices;
 using Lucene.Net.Documents;
 using Lucene.Net.Index;
@@ -293,11 +294,11 @@ namespace Lucene.Net.Util
         /// </summary>
         public static bool VERBOSE = RandomizedTest.SystemPropertyAsBoolean("tests.verbose",
 #if DEBUG
-            true
+ true
 #else
             false
 #endif
-            );
+);
 
         /// <summary>
         /// TODO: javadoc? </summary>
@@ -438,10 +439,11 @@ namespace Lucene.Net.Util
         /// </summary>
         private static TestRuleSetupAndRestoreClassEnv ClassEnvRule;
 
+        // LUCENENET TODO
         /// <summary>
         /// Suite failure marker (any error in the test or suite scope).
         /// </summary>
-        //public static TestRuleMarkFailure SuiteFailureMarker;
+        public static /*TestRuleMarkFailure*/ bool SuiteFailureMarker = true; // Means: was successful
 
         /// <summary>
         /// Ignore tests after hitting a designated number of initial failures. this
@@ -576,6 +578,7 @@ namespace Lucene.Net.Util
             /* LUCENE TO-DO: Not sure how to convert these
                 ParentChainCallRule.TeardownCalled = true;
                 */
+            CleanupTemporaryFiles();
         }
 
         // -----------------------------------------------------------------
@@ -1369,7 +1372,7 @@ namespace Lucene.Net.Util
 
             Type clazz = CommandLineUtil.LoadDirectoryClass(clazzName);
             // If it is a FSDirectory type, try its ctor(File)
-            if (clazz.IsSubclassOf(typeof (FSDirectory)))
+            if (clazz.IsSubclassOf(typeof(FSDirectory)))
             {
                 DirectoryInfo dir = CreateTempDir("index-" + clazzName);
                 dir.Create(); // ensure it's created so we 'have' it.
@@ -1377,7 +1380,7 @@ namespace Lucene.Net.Util
             }
 
             // try empty ctor
-            return (Directory) Activator.CreateInstance(clazz);
+            return (Directory)Activator.CreateInstance(clazz);
         }
 
         /// <summary>
@@ -2597,7 +2600,7 @@ namespace Lucene.Net.Util
         /// A queue of temporary resources to be removed after the
         /// suite completes. </summary>
         /// <seealso cref= #registerToRemoveAfterSuite(File) </seealso>
-        private static List<FileSystemInfo> CleanupQueue = new List<FileSystemInfo>();
+        private static readonly ConcurrentQueue<string> CleanupQueue = new ConcurrentQueue<string>();
 
         /// <summary>
         /// Register temporary folder for removal after the suite completes.
@@ -2612,10 +2615,7 @@ namespace Lucene.Net.Util
                 return;
             }
 
-            lock (CleanupQueue)
-            {
-                CleanupQueue.Add(f);
-            }
+            CleanupQueue.Enqueue(f.FullName);
         }
 
         [MethodImpl(MethodImplOptions.NoInlining)]
@@ -2627,59 +2627,47 @@ namespace Lucene.Net.Util
             return string.Format("{0}+{1}", this.GetType().Name, sf.GetMethod().Name);
         }
 
-        /*private static class TemporaryFilesCleanupRule : TestRuleAdapter
+        private void CleanupTemporaryFiles()
         {
-            protected void Before()
-            {
-                base.Before();
-                Debug.Assert(TempDirBase == null);
-            }
+            // Drain cleanup queue and clear it.
+            var tempDirBasePath = (TempDirBase != null ? TempDirBase.FullName : null);
+            TempDirBase = null;
 
-            protected void AfterAlways(IList<Exception> errors)
+            // Only check and throw an IOException on un-removable files if the test
+            // was successful. Otherwise just report the path of temporary files
+            // and leave them there.
+            if (LuceneTestCase.SuiteFailureMarker /*.WasSuccessful()*/)
             {
-                // Drain cleanup queue and clear it.
-                DirectoryInfo[] everything;
-                string tempDirBasePath;
-                lock (CleanupQueue)
-                {
-                    tempDirBasePath = (TempDirBase != null ? TempDirBase.FullName : null);
-                    TempDirBase = null;
-
-                    CleanupQueue.Reverse();
-                    everything = new DirectoryInfo[CleanupQueue.Count];
-                    CleanupQueue.ToArray(everything);
-                    CleanupQueue.Clear();
-                }
-
-                // Only check and throw an IOException on un-removable files if the test
-                // was successful. Otherwise just report the path of temporary files
-                // and leave them there.
-                if (LuceneTestCase.SuiteFailureMarker.WasSuccessful())
+                string f;
+                while (CleanupQueue.TryDequeue(out f))
                 {
                     try
                     {
-                        TestUtil.Rm(everything);
+                        if (System.IO.Directory.Exists(f))
+                            System.IO.Directory.Delete(f, true);
+                        else if (System.IO.File.Exists(f))
+                            File.Delete(f);
                     }
-                    catch (IOException e)
+                    catch (IOException)
                     {
-                        Type suiteClass = RandomizedContext.Current.GetTargetType;
-                        if (suiteClass.isAnnotationPresent(typeof(SuppressTempFileChecks)))
-                        {
-                            Console.Error.WriteLine("WARNING: Leftover undeleted temporary files (bugUrl: " + suiteClass.GetAnnotation(typeof(SuppressTempFileChecks)).bugUrl() + "): " + e.Message);
-                            return;
-                        }
-                        throw e;
+                        //                    Type suiteClass = RandomizedContext.Current.GetTargetType;
+                        //                    if (suiteClass.IsAnnotationPresent(typeof(SuppressTempFileChecks)))
+                        //                    {
+                        //                        Console.Error.WriteLine("WARNING: Leftover undeleted temporary files (bugUrl: " + suiteClass.GetAnnotation(typeof(SuppressTempFileChecks)).bugUrl() + "): " + e.Message);
+                        //                        return;
+                        //                    }
+                        throw;
                     }
                 }
-                else
+            }
+            else
+            {
+                if (tempDirBasePath != null)
                 {
-                    if (tempDirBasePath != null)
-                    {
-                        Console.Error.WriteLine("NOTE: leaving temporary files on disk at: " + tempDirBasePath);
-                    }
+                    Console.Error.WriteLine("NOTE: leaving temporary files on disk at: " + tempDirBasePath);
                 }
             }
-        }*/
+        }
     }
 
     /*internal class ReaderClosedListenerAnonymousInnerClassHelper : IndexReader.ReaderClosedListener
@@ -2708,7 +2696,7 @@ namespace Lucene.Net.Util
 
         public virtual int Compare(object arg0, object arg1)
         {
-            return ((IndexableField)arg0).Name().CompareTo(((IndexableField)arg1).Name());
+            return System.String.Compare(((IndexableField)arg0).Name(), ((IndexableField)arg1).Name(), System.StringComparison.Ordinal);
         }
     }
 }
\ No newline at end of file


[06/18] lucenenet git commit: Remove debugging code

Posted by sy...@apache.org.
Remove debugging code


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

Branch: refs/heads/master
Commit: 36582a3b80cf9392162df4bc9265d71777b99d68
Parents: 4b6eafe3
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 16:14:53 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 16:14:53 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/36582a3b/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs
index 177bd44..651eeb8 100644
--- a/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestNRTCachingDirectory.cs
@@ -138,7 +138,7 @@ namespace Lucene.Net.Store
         }
 
         // LUCENE-3382 -- make sure we get exception if the directory really does not exist.
-        [Test, Timeout(int.MaxValue)]
+        [Test]
         public virtual void TestNoDir()
         {
             // LUCENENET TODO mysterious failure - FSDirectory recreates the folder by design, not sure why this passes for Java Lucene


[17/18] lucenenet git commit: Fixing test

Posted by sy...@apache.org.
Fixing test


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

Branch: refs/heads/master
Commit: a098c0b5d3f6b896baf1eea7b52af3debf891ae3
Parents: 309ebc7
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Tue Jan 6 02:32:10 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Tue Jan 6 02:32:10 2015 +0200

----------------------------------------------------------------------
 .../core/Codecs/Compressing/AbstractTestCompressionMode.cs        | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a098c0b5/src/Lucene.Net.Tests/core/Codecs/Compressing/AbstractTestCompressionMode.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Codecs/Compressing/AbstractTestCompressionMode.cs b/src/Lucene.Net.Tests/core/Codecs/Compressing/AbstractTestCompressionMode.cs
index d1f08ce..37f00e2 100644
--- a/src/Lucene.Net.Tests/core/Codecs/Compressing/AbstractTestCompressionMode.cs
+++ b/src/Lucene.Net.Tests/core/Codecs/Compressing/AbstractTestCompressionMode.cs
@@ -1,4 +1,5 @@
 using System;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Codecs.Compressing
 {
@@ -173,7 +174,7 @@ namespace Lucene.Net.Codecs.Compressing
         public virtual void TestLUCENE5201()
         {
             sbyte[] data = { 14, 72, 14, 85, 3, 72, 14, 85, 3, 72, 14, 72, 14, 72, 14, 85, 3, 72, 14, 72, 14, 72, 14, 72, 14, 72, 14, 72, 14, 85, 3, 72, 14, 85, 3, 72, 14, 85, 3, 72, 14, 85, 3, 72, 14, 85, 3, 72, 14, 85, 3, 72, 14, 50, 64, 0, 46, -1, 0, 0, 0, 29, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 50, 64, 0, 47, -105, 0, 0, 0, 30, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, -97, 6, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68
 , -113, 0, 120, 64, 0, 48, 4, 0, 0, 0, 31, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 72, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 18, 72, 30, 72, 22, 72, 31, 72, 43, 72, 19, 72, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 72, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 18, 72, 30, 72, 22, 72, 31, 72, 43, 72, 19, 72, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 72, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 18, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 24, 32, 34, 124, 0, 120, 64, 0, 48, 80, 0, 0, 0, 31, 30, 72, 22, 72, 31, 72, 43, 72, 19, 72, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 72, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 
 18, 72, 30, 72, 22, 72, 31, 72, 43, 72, 19, 72, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 72, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 18, 72, 30, 72, 22, 72, 31, 72, 43, 72, 19, 72, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 72, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 18, 72, 30, 72, 22, 72, 31, 72, 43, 72, 19, 72, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 72, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 18, 72, 30, 72, 22, 72, 31, 72, 43, 72, 19, 72, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 72, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 18, 72, 30, 72, 22, 72, 31, 72, 43, 72, 19, 72, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 7
 2, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 18, 72, 30, 72, 22, 72, 31, 72, 43, 72, 19, 72, 34, 72, 29, 72, 37, 72, 35, 72, 45, 72, 23, 72, 46, 72, 20, 72, 40, 72, 33, 72, 25, 72, 39, 72, 38, 72, 26, 72, 28, 72, 42, 72, 24, 72, 27, 72, 36, 72, 41, 72, 32, 72, 18, 72, 30, 72, 22, 72, 31, 72, 43, 72, 19, 50, 64, 0, 49, 20, 0, 0, 0, 32, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 50, 64, 0, 50, 53, 0, 0, 0, 34, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0
 , 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 50, 64, 0, 51, 85, 0, 0, 0, 36, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, -97, 5, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 50, -64, 0, 51, -45, 0, 0, 0, 37, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, -9
 7, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -113, 0, 2, 3, -97, 6, 0, 68, -113, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 2, 3, 85, 8, -113, 0, 68, -97, 3, 0, 120, 64, 0, 52, -88, 0, 0, 0, 39, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 72, 13, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 72, 13, 72, 13, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 72, 13, 72, 13, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 85, 5, 72, 13, 72, 13, 85, 5, 72, 13, 72, 13, 85, 5, 72, 13, 72, 13, 85, 5, 72, 13, -19, -24, -101, -35 };
-            Test((byte[])(Array)data, 9, data.Length - 9);
+            Test(data.ToByteArray(), 9, data.Length - 9);
         }
     }
 }
\ No newline at end of file


[08/18] lucenenet git commit: Clean redundant Dir delete

Posted by sy...@apache.org.
Clean redundant Dir delete


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

Branch: refs/heads/master
Commit: cb2dfdcb6a839019fa34d2e9d8e45c1fe50c2d16
Parents: c7473a5
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 17:42:25 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 17:42:25 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Tests/core/Store/TestDirectory.cs | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cb2dfdcb/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
index ecc0b31..c518c04 100644
--- a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
@@ -253,8 +253,6 @@ namespace Lucene.Net.Store
                 dir.Dispose();
                 Assert.IsFalse(dir.IsOpen);
             }
-
-            System.IO.Directory.Delete(path.FullName, true);
         }
 
         // LUCENE-1464


[15/18] lucenenet git commit: Cleanup

Posted by sy...@apache.org.
Cleanup


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

Branch: refs/heads/master
Commit: 3b37fac9965653f2730a5c457a1580ab414e5fa9
Parents: fbabfe9
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Jan 5 19:06:08 2015 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Jan 5 19:06:08 2015 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Index/SegmentInfos.cs        |  2 +-
 src/Lucene.Net.Core/Store/BaseDirectory.cs       | 12 ++++++------
 src/Lucene.Net.Core/Store/FileSwitchDirectory.cs |  2 +-
 src/Lucene.Net.Tests/core/Store/TestDirectory.cs |  2 +-
 4 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3b37fac9/src/Lucene.Net.Core/Index/SegmentInfos.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/SegmentInfos.cs b/src/Lucene.Net.Core/Index/SegmentInfos.cs
index c4e29ca..9ce4466 100644
--- a/src/Lucene.Net.Core/Index/SegmentInfos.cs
+++ b/src/Lucene.Net.Core/Index/SegmentInfos.cs
@@ -824,7 +824,7 @@ namespace Lucene.Net.Index
 
             /// <summary>
             /// Sole constructor. </summary>
-            public FindSegmentsFile(Directory directory)
+            protected FindSegmentsFile(Directory directory)
             {
                 this.Directory = directory;
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3b37fac9/src/Lucene.Net.Core/Store/BaseDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/BaseDirectory.cs b/src/Lucene.Net.Core/Store/BaseDirectory.cs
index 120c072..7db2d6b 100644
--- a/src/Lucene.Net.Core/Store/BaseDirectory.cs
+++ b/src/Lucene.Net.Core/Store/BaseDirectory.cs
@@ -29,7 +29,7 @@ namespace Lucene.Net.Store
         /// Holds the LockFactory instance (implements locking for
         /// this Directory instance).
         /// </summary>
-        protected internal LockFactory LockFactory_Renamed;
+        protected internal LockFactory _lockFactory;
 
         /// <summary>
         /// Sole constructor. </summary>
@@ -40,14 +40,14 @@ namespace Lucene.Net.Store
 
         public override Lock MakeLock(string name)
         {
-            return LockFactory_Renamed.MakeLock(name);
+            return _lockFactory.MakeLock(name);
         }
 
         public override void ClearLock(string name)
         {
-            if (LockFactory_Renamed != null)
+            if (_lockFactory != null)
             {
-                LockFactory_Renamed.ClearLock(name);
+                _lockFactory.ClearLock(name);
             }
         }
 
@@ -56,12 +56,12 @@ namespace Lucene.Net.Store
             set
             {
                 Debug.Assert(value != null);
-                this.LockFactory_Renamed = value;
+                this._lockFactory = value;
                 value.LockPrefix = this.LockID;
             }
             get
             {
-                return this.LockFactory_Renamed;
+                return this._lockFactory;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3b37fac9/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 d986444..0e4468f 100644
--- a/src/Lucene.Net.Core/Store/FileSwitchDirectory.cs
+++ b/src/Lucene.Net.Core/Store/FileSwitchDirectory.cs
@@ -46,7 +46,7 @@ namespace Lucene.Net.Store
             this.PrimaryDir_Renamed = primaryDir;
             this.SecondaryDir_Renamed = secondaryDir;
             this.DoClose = doClose;
-            this.LockFactory_Renamed = primaryDir.LockFactory;
+            this._lockFactory = primaryDir.LockFactory;
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/3b37fac9/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
index c518c04..9ea4097 100644
--- a/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
+++ b/src/Lucene.Net.Tests/core/Store/TestDirectory.cs
@@ -172,7 +172,7 @@ namespace Lucene.Net.Store
                 largeBuffer[i] = (byte)i; // automatically loops with modulo
             }
 
-            FSDirectory[] dirs = new FSDirectory[] { new SimpleFSDirectory(path, null), new NIOFSDirectory(path, null), new MMapDirectory(path, null) };
+            var dirs = new FSDirectory[] { new SimpleFSDirectory(path, null), new NIOFSDirectory(path, null), new MMapDirectory(path, null) };
 
             for (int i = 0; i < dirs.Length; i++)
             {