lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [1/3] lucenenet git commit: Removing Apache.NMS dependency.
Date Sat, 23 Apr 2016 22:23:41 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 8e144a0c8 -> 72ec63abf


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6c62d649/src/Lucene.Net.Tests/core/Index/TestMixedDocValuesUpdates.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestMixedDocValuesUpdates.cs b/src/Lucene.Net.Tests/core/Index/TestMixedDocValuesUpdates.cs
index 8930728..5fd7339 100644
--- a/src/Lucene.Net.Tests/core/Index/TestMixedDocValuesUpdates.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestMixedDocValuesUpdates.cs
@@ -1,5 +1,5 @@
-using Apache.NMS.Util;
 using System;
+using System.Threading;
 using System.Collections.Generic;
 using Lucene.Net.Documents;
 
@@ -263,7 +263,7 @@ namespace Lucene.Net.Index
                 writer.AddDocument(doc);
             }
 
-            CountDownLatch done = new CountDownLatch(numThreads);
+            CountdownEvent done = new CountdownEvent(numThreads);
             AtomicInteger numUpdates = new AtomicInteger(AtLeast(100));
 
             // same thread updates a field as well as reopens
@@ -279,7 +279,7 @@ namespace Lucene.Net.Index
             {
                 t.Start();
             }
-            done.@await();
+            done.Wait();
             writer.Dispose();
 
             DirectoryReader reader = DirectoryReader.Open(dir);
@@ -323,12 +323,12 @@ namespace Lucene.Net.Index
 
             private IndexWriter Writer;
             private int NumDocs;
-            private CountDownLatch Done;
+            private CountdownEvent Done;
             private AtomicInteger NumUpdates;
             private string f;
             private string Cf;
 
-            public ThreadAnonymousInnerClassHelper(TestMixedDocValuesUpdates outerInstance,
string str, IndexWriter writer, int numDocs, CountDownLatch done, AtomicInteger numUpdates,
string f, string cf)
+            public ThreadAnonymousInnerClassHelper(TestMixedDocValuesUpdates outerInstance,
string str, IndexWriter writer, int numDocs, CountdownEvent done, AtomicInteger numUpdates,
string f, string cf)
                 : base(str)
             {
                 this.OuterInstance = outerInstance;
@@ -438,7 +438,7 @@ namespace Lucene.Net.Index
                             }
                         }
                     }
-                    Done.countDown();
+                    Done.Signal();
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6c62d649/src/Lucene.Net.Tests/core/Index/TestNumericDocValuesUpdates.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestNumericDocValuesUpdates.cs b/src/Lucene.Net.Tests/core/Index/TestNumericDocValuesUpdates.cs
index bf9d902..b9d592d 100644
--- a/src/Lucene.Net.Tests/core/Index/TestNumericDocValuesUpdates.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestNumericDocValuesUpdates.cs
@@ -1,6 +1,6 @@
-using Apache.NMS.Util;
 using System;
 using System.Collections.Generic;
+using System.Threading;
 using Lucene.Net.Documents;
 
 namespace Lucene.Net.Index
@@ -1140,7 +1140,7 @@ namespace Lucene.Net.Index
                 writer.AddDocument(doc);
             }
 
-            CountDownLatch done = new CountDownLatch(numThreads);
+            CountdownEvent done = new CountdownEvent(numThreads);
             AtomicInteger numUpdates = new AtomicInteger(AtLeast(100));
 
             // same thread updates a field as well as reopens
@@ -1156,7 +1156,7 @@ namespace Lucene.Net.Index
             {
                 t.Start();
             }
-            done.@await();
+            done.Wait();
             writer.Dispose();
 
             DirectoryReader reader = DirectoryReader.Open(dir);
@@ -1194,12 +1194,12 @@ namespace Lucene.Net.Index
 
             private IndexWriter Writer;
             private int NumDocs;
-            private CountDownLatch Done;
+            private CountdownEvent Done;
             private AtomicInteger NumUpdates;
             private string f;
             private string Cf;
 
-            public ThreadAnonymousInnerClassHelper(TestNumericDocValuesUpdates outerInstance,
string str, IndexWriter writer, int numDocs, CountDownLatch done, AtomicInteger numUpdates,
string f, string cf)
+            public ThreadAnonymousInnerClassHelper(TestNumericDocValuesUpdates outerInstance,
string str, IndexWriter writer, int numDocs, CountdownEvent done, AtomicInteger numUpdates,
string f, string cf)
                 : base(str)
             {
                 this.OuterInstance = outerInstance;
@@ -1307,7 +1307,7 @@ namespace Lucene.Net.Index
                             }
                         }
                     }
-                    Done.countDown();
+                    Done.Signal();
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6c62d649/src/Lucene.Net.Tests/core/Search/TestAutomatonQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestAutomatonQuery.cs b/src/Lucene.Net.Tests/core/Search/TestAutomatonQuery.cs
index edbbded..87db2cd 100644
--- a/src/Lucene.Net.Tests/core/Search/TestAutomatonQuery.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestAutomatonQuery.cs
@@ -1,7 +1,7 @@
-using Apache.NMS.Util;
 using Lucene.Net.Documents;
 using Lucene.Net.Support;
 using System;
+using System.Threading;
 
 namespace Lucene.Net.Search
 {
@@ -230,7 +230,7 @@ namespace Lucene.Net.Search
             {
                 queries[i] = new AutomatonQuery(new Term("bogus", "bogus"), AutomatonTestUtil.RandomAutomaton(Random()));
             }
-            CountDownLatch startingGun = new CountDownLatch(1);
+            CountdownEvent startingGun = new CountdownEvent(1);
             int numThreads = TestUtil.NextInt(Random(), 2, 5);
             ThreadClass[] threads = new ThreadClass[numThreads];
             for (int threadID = 0; threadID < numThreads; threadID++)
@@ -239,7 +239,7 @@ namespace Lucene.Net.Search
                 threads[threadID] = thread;
                 thread.Start();
             }
-            startingGun.countDown();
+            startingGun.Signal();
             foreach (ThreadClass thread in threads)
             {
                 thread.Join();
@@ -251,9 +251,9 @@ namespace Lucene.Net.Search
             private readonly TestAutomatonQuery OuterInstance;
 
             private AutomatonQuery[] Queries;
-            private CountDownLatch StartingGun;
+            private CountdownEvent StartingGun;
 
-            public ThreadAnonymousInnerClassHelper(TestAutomatonQuery outerInstance, AutomatonQuery[]
queries, CountDownLatch startingGun)
+            public ThreadAnonymousInnerClassHelper(TestAutomatonQuery outerInstance, AutomatonQuery[]
queries, CountdownEvent startingGun)
             {
                 this.OuterInstance = outerInstance;
                 this.Queries = queries;
@@ -262,7 +262,7 @@ namespace Lucene.Net.Search
 
             public override void Run()
             {
-                StartingGun.@await();
+                StartingGun.Wait();
                 for (int i = 0; i < Queries.Length; i++)
                 {
                     Queries[i].GetHashCode();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6c62d649/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs b/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs
index 6c3cc7d..4857fe1 100644
--- a/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestLiveFieldValues.cs
@@ -1,9 +1,9 @@
-using Apache.NMS.Util;
 using Lucene.Net.Documents;
 using Lucene.Net.Support;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
+using System.Threading;
 
 namespace Lucene.Net.Search
 {
@@ -62,7 +62,7 @@ namespace Lucene.Net.Search
                 Console.WriteLine(numThreads + " threads");
             }
 
-            CountDownLatch startingGun = new CountDownLatch(1);
+            CountdownEvent startingGun = new CountdownEvent(1);
             IList<ThreadClass> threads = new List<ThreadClass>();
 
             int iters = AtLeast(1000);
@@ -81,7 +81,7 @@ namespace Lucene.Net.Search
                 thread.Start();
             }
 
-            startingGun.countDown();
+            startingGun.Signal();
 
             foreach (ThreadClass thread in threads)
             {
@@ -134,7 +134,7 @@ namespace Lucene.Net.Search
             private SearcherManager Mgr;
             private int? Missing;
             private LiveFieldValues<IndexSearcher, int?> Rt;
-            private CountDownLatch StartingGun;
+            private CountdownEvent StartingGun;
             private int Iters;
             private int IdCount;
             private double ReopenChance;
@@ -144,7 +144,7 @@ namespace Lucene.Net.Search
             private int ThreadID;
             private Random ThreadRandom;
 
-            public ThreadAnonymousInnerClassHelper(IndexWriter w, SearcherManager mgr, int?
missing, LiveFieldValues<IndexSearcher, int?> rt, CountDownLatch startingGun, int iters,
int idCount, double reopenChance, double deleteChance, double addChance, int t, int threadID,
Random threadRandom)
+            public ThreadAnonymousInnerClassHelper(IndexWriter w, SearcherManager mgr, int?
missing, LiveFieldValues<IndexSearcher, int?> rt, CountdownEvent startingGun, int iters,
int idCount, double reopenChance, double deleteChance, double addChance, int t, int threadID,
Random threadRandom)
             {
                 this.w = w;
                 this.Mgr = mgr;
@@ -168,7 +168,7 @@ namespace Lucene.Net.Search
                     IDictionary<string, int?> values = new Dictionary<string, int?>();
                     IList<string> allIDs = new SynchronizedCollection<string>();
 
-                    StartingGun.@await();
+                    StartingGun.Wait();
                     for (int iter = 0; iter < Iters; iter++)
                     {
                         // Add/update a document

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6c62d649/src/Lucene.Net.Tests/core/Search/TestSameScoresWithThreads.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestSameScoresWithThreads.cs b/src/Lucene.Net.Tests/core/Search/TestSameScoresWithThreads.cs
index 4541437..616ca1d 100644
--- a/src/Lucene.Net.Tests/core/Search/TestSameScoresWithThreads.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestSameScoresWithThreads.cs
@@ -1,6 +1,6 @@
-using Apache.NMS.Util;
 using System;
 using System.Collections.Generic;
+using System.Threading;
 
 namespace Lucene.Net.Search
 {
@@ -89,7 +89,7 @@ namespace Lucene.Net.Search
 
             if (answers.Count > 0)
             {
-                CountDownLatch startingGun = new CountDownLatch(1);
+                CountdownEvent startingGun = new CountdownEvent(1);
                 int numThreads = TestUtil.NextInt(Random(), 2, 5);
                 ThreadClass[] threads = new ThreadClass[numThreads];
                 for (int threadID = 0; threadID < numThreads; threadID++)
@@ -98,7 +98,7 @@ namespace Lucene.Net.Search
                     threads[threadID] = thread;
                     thread.Start();
                 }
-                startingGun.countDown();
+                startingGun.Signal();
                 foreach (ThreadClass thread in threads)
                 {
                     thread.Join();
@@ -114,9 +114,9 @@ namespace Lucene.Net.Search
 
             private IndexSearcher s;
             private IDictionary<BytesRef, TopDocs> Answers;
-            private CountDownLatch StartingGun;
+            private CountdownEvent StartingGun;
 
-            public ThreadAnonymousInnerClassHelper(TestSameScoresWithThreads outerInstance,
IndexSearcher s, IDictionary<BytesRef, TopDocs> answers, CountDownLatch startingGun)
+            public ThreadAnonymousInnerClassHelper(TestSameScoresWithThreads outerInstance,
IndexSearcher s, IDictionary<BytesRef, TopDocs> answers, CountdownEvent startingGun)
             {
                 this.OuterInstance = outerInstance;
                 this.s = s;
@@ -128,7 +128,7 @@ namespace Lucene.Net.Search
             {
                 try
                 {
-                    StartingGun.@await();
+                    StartingGun.Wait();
                     for (int i = 0; i < 20; i++)
                     {
                         IList<KeyValuePair<BytesRef, TopDocs>> shuffled = new
List<KeyValuePair<BytesRef, TopDocs>>(Answers.EntrySet());

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6c62d649/src/Lucene.Net.Tests/core/Search/TestSearcherManager.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestSearcherManager.cs b/src/Lucene.Net.Tests/core/Search/TestSearcherManager.cs
index 5b0122d..aedc8e5 100644
--- a/src/Lucene.Net.Tests/core/Search/TestSearcherManager.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestSearcherManager.cs
@@ -1,4 +1,3 @@
-using Apache.NMS.Util;
 using System;
 using System.Collections.Generic;
 using System.Threading;
@@ -265,8 +264,8 @@ namespace Lucene.Net.Search
             IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random())).SetMergeScheduler(new ConcurrentMergeScheduler()));
             writer.AddDocument(new Document());
             writer.Commit();
-            CountDownLatch awaitEnterWarm = new CountDownLatch(1);
-            CountDownLatch awaitClose = new CountDownLatch(1);
+            CountdownEvent awaitEnterWarm = new CountdownEvent(1);
+            CountdownEvent awaitClose = new CountdownEvent(1);
             AtomicBoolean triedReopen = new AtomicBoolean(false);
             TaskScheduler es = Random().NextBoolean() ? null : Executors.newCachedThreadPool(new
NamedThreadFactory("testIntermediateClose"));
             SearcherFactory factory = new SearcherFactoryAnonymousInnerClassHelper2(this,
awaitEnterWarm, awaitClose, triedReopen, es);
@@ -294,13 +293,13 @@ namespace Lucene.Net.Search
             {
                 Console.WriteLine("THREAD started");
             }
-            awaitEnterWarm.@await();
+            awaitEnterWarmWait();
             if (VERBOSE)
             {
                 Console.WriteLine("NOW call close");
             }
             searcherManager.Dispose();
-            awaitClose.countDown();
+            awaitClose.Signal();
             thread.Join();
             try
             {
@@ -327,12 +326,12 @@ namespace Lucene.Net.Search
         {
             private readonly TestSearcherManager OuterInstance;
 
-            private CountDownLatch AwaitEnterWarm;
-            private CountDownLatch AwaitClose;
+            private CountdownEvent AwaitEnterWarm;
+            private CountdownEvent AwaitClose;
             private AtomicBoolean TriedReopen;
             private TaskScheduler Es;
 
-            public SearcherFactoryAnonymousInnerClassHelper2(TestSearcherManager outerInstance,
CountDownLatch awaitEnterWarm, CountDownLatch awaitClose, AtomicBoolean triedReopen, TaskScheduler
es)
+            public SearcherFactoryAnonymousInnerClassHelper2(TestSearcherManager outerInstance,
CountdownEvent awaitEnterWarm, CountdownEvent awaitClose, AtomicBoolean triedReopen, TaskScheduler
es)
             {
                 this.OuterInstance = outerInstance;
                 this.AwaitEnterWarm = awaitEnterWarm;
@@ -347,8 +346,8 @@ namespace Lucene.Net.Search
                 {
                     if (TriedReopen.Get())
                     {
-                        AwaitEnterWarm.countDown();
-                        AwaitClose.@await();
+                        AwaitEnterWarm.Signal();
+                        AwaitClose.Wait();
                     }
                 }
                 catch (ThreadInterruptedException e)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6c62d649/src/Lucene.Net.Tests/core/Util/TestNamedSPILoader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestNamedSPILoader.cs b/src/Lucene.Net.Tests/core/Util/TestNamedSPILoader.cs
index 5d42841..0dcec35 100644
--- a/src/Lucene.Net.Tests/core/Util/TestNamedSPILoader.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestNamedSPILoader.cs
@@ -1,10 +1,8 @@
+using System;
 using NUnit.Framework;
-using System.Collections.Generic;
 
 namespace Lucene.Net.Util
 {
-    using Codec = Lucene.Net.Codecs.Codec;
-
     /*
      * Licensed to the Apache Software Foundation (ASF) under one or more
      * contributor license agreements.  See the NOTICE file distributed with
@@ -22,37 +20,77 @@ namespace Lucene.Net.Util
      * limitations under the License.
      */
 
-    // TODO: maybe we should test this with mocks, but its easy
-    // enough to test the basics via Codec
     [TestFixture]
     public class TestNamedSPILoader : LuceneTestCase
     {
         [Test]
-        public virtual void TestLookup()
+        public void Lookup_ExistingService_ReturnServiceByName()
         {
-            Codec codec = Codec.ForName("Lucene46");
-            Assert.AreEqual("Lucene46", codec.Name);
+            // Arrange
+            var loader = CreateNamedSPILoaderForCodecClass();
+
+            // Act
+            var codec = loader.Lookup("CustomCodec1");
+
+            // Assert
+            Assert.IsInstanceOf<CustomCodec1>(codec);
+            Assert.AreEqual("CustomCodec1", codec.Name);
         }
 
-        // we want an exception if its not found.
         [Test]
-        public virtual void TestBogusLookup()
+        public void Lookup_NonexistingService_ThrowsException()
         {
-            try
-            {
-                Codec.ForName("dskfdskfsdfksdfdsf");
-                Assert.Fail();
-            }
-            catch (System.ArgumentException expected)
+            // Arrange
+            var loader = CreateNamedSPILoaderForCodecClass();
+
+            // Act
+            var actualException = Assert.Throws<ArgumentException>(() => loader.Lookup("NonexistingCodecName"));
+
+            // Assert
+            const string expectedMessage = "An SPI class of type CustomCodec with name 'NonexistingCodecName'
does not exist. "
+                + "You need to reference the corresponding assembly that contains the class.
"
+                + "The current NamedSPILoader supports the following names: CustomCodec1,
CustomCodec2";
+            Assert.AreEqual(expectedMessage, actualException.Message);
+        }
+
+        [Test]
+        public void AvailableServices_LoaderWithServices_ReturnsListOfNamesOfRegisteredServices()
+        {
+            // Arrange
+            var expectedServices = new [] { "CustomCodec1", "CustomCodec2" };
+            var loader = CreateNamedSPILoaderForCodecClass();
+
+            // Act
+            var actualServices = loader.AvailableServices();
+
+            // Assert
+            Assert.IsNotNull(actualServices);
+            CollectionAssert.IsNotEmpty(actualServices);
+            CollectionAssert.AreEqual(expectedServices, actualServices);
+        }
+
+        private static NamedSPILoader<CustomCodec> CreateNamedSPILoaderForCodecClass()
+        {
+            return new NamedSPILoader<CustomCodec>(typeof(CustomCodec));
+        }
+
+        private abstract class CustomCodec : NamedSPILoader<CustomCodec>.NamedSPI
+        {
+            public string Name
             {
+                get
+                {
+                    return this.GetType().Name;
+                }
             }
         }
 
-        [Test]
-        public virtual void TestAvailableServices()
+        private class CustomCodec1 : CustomCodec
+        {
+        }
+
+        private class CustomCodec2 : CustomCodec
         {
-            ISet<string> codecs = Codec.AvailableCodecs();
-            Assert.IsTrue(codecs.Contains("Lucene46"));
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6c62d649/src/Lucene.Net.Tests/packages.config
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/packages.config b/src/Lucene.Net.Tests/packages.config
index ffa0c4a..967502d 100644
--- a/src/Lucene.Net.Tests/packages.config
+++ b/src/Lucene.Net.Tests/packages.config
@@ -1,6 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
-  <package id="Apache.NMS" version="1.6.0.3083" targetFramework="net40" />
   <package id="NUnit" version="2.6.3" targetFramework="net40" />
-  <package id="SharpZipLib" version="0.86.0" targetFramework="net40" />
 </packages>
\ No newline at end of file


Mime
View raw message