lucenenet-commits mailing list archives

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


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5e8c8b6/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs b/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs
index 6e92ffc..ba1d3d2 100644
--- a/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestIndexWriterWithThreads.cs
@@ -1,3 +1,4 @@
+using Apache.NMS.Util;
 using System;
 using System.Diagnostics;
 using System.Threading;
@@ -544,13 +545,13 @@ namespace Lucene.Net.Index
         public virtual void TestOpenTwoIndexWritersOnDifferentThreads()
         {
             Directory dir = NewDirectory();
-            CountdownEvent oneIWConstructed = new CountdownEvent(1);
+            CountDownLatch oneIWConstructed = new CountDownLatch(1);
             DelayedIndexAndCloseRunnable thread1 = new DelayedIndexAndCloseRunnable(dir,
oneIWConstructed);
             DelayedIndexAndCloseRunnable thread2 = new DelayedIndexAndCloseRunnable(dir,
oneIWConstructed);
 
             thread1.Start();
             thread2.Start();
-            oneIWConstructed.Wait();
+            oneIWConstructed.@await();
 
             thread1.StartIndexing();
             thread2.StartIndexing();
@@ -584,10 +585,10 @@ namespace Lucene.Net.Index
             internal readonly Directory Dir;
             internal bool Failed = false;
             internal Exception Failure = null;
-            internal readonly CountdownEvent StartIndexing_Renamed = new CountdownEvent(1);
-            internal CountdownEvent IwConstructed;
+            internal readonly CountDownLatch StartIndexing_Renamed = new CountDownLatch(1);
+            internal CountDownLatch IwConstructed;
 
-            public DelayedIndexAndCloseRunnable(Directory dir, CountdownEvent iwConstructed)
+            public DelayedIndexAndCloseRunnable(Directory dir, CountDownLatch iwConstructed)
             {
                 this.Dir = dir;
                 this.IwConstructed = iwConstructed;
@@ -595,7 +596,7 @@ namespace Lucene.Net.Index
 
             public virtual void StartIndexing()
             {
-                this.StartIndexing_Renamed.Signal();
+                this.StartIndexing_Renamed.countDown();
             }
 
             public override void Run()
@@ -606,8 +607,8 @@ namespace Lucene.Net.Index
                     Field field = NewTextField("field", "testData", Field.Store.YES);
                     doc.Add(field);
                     IndexWriter writer = new IndexWriter(Dir, NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random())));
-                    IwConstructed.Signal();
-                    StartIndexing_Renamed.Wait();
+                    IwConstructed.countDown();
+                    StartIndexing_Renamed.@await();
                     writer.AddDocument(doc);
                     writer.Dispose();
                 }
@@ -633,10 +634,11 @@ namespace Lucene.Net.Index
 
             int threadCount = TestUtil.NextInt(Random(), 2, 6);
 
+            AtomicReference<IndexWriter> writerRef = new AtomicReference<IndexWriter>();
             MockAnalyzer analyzer = new MockAnalyzer(Random());
             analyzer.MaxTokenLength = TestUtil.NextInt(Random(), 1, IndexWriter.MAX_TERM_LENGTH);
-            IndexWriter writerRef = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT,
analyzer));
 
+            writerRef.Value = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT,
analyzer));
             LineFileDocs docs = new LineFileDocs(Random());
             ThreadClass[] threads = new ThreadClass[threadCount];
             int iters = AtLeast(100);
@@ -655,7 +657,7 @@ namespace Lucene.Net.Index
             }
 
             Assert.IsTrue(!failed.Get());
-            writerRef.Dispose();
+            writerRef.Value.Dispose();
             d.Dispose();
         }
 
@@ -664,14 +666,14 @@ namespace Lucene.Net.Index
             private readonly TestIndexWriterWithThreads OuterInstance;
 
             private BaseDirectoryWrapper d;
-            private IndexWriter WriterRef;
+            private AtomicReference<IndexWriter> WriterRef;
             private LineFileDocs Docs;
             private int Iters;
             private AtomicBoolean Failed;
             private ReentrantLock RollbackLock;
             private ReentrantLock CommitLock;
 
-            public ThreadAnonymousInnerClassHelper(TestIndexWriterWithThreads outerInstance,
BaseDirectoryWrapper d, IndexWriter writerRef, LineFileDocs docs, int iters, AtomicBoolean
failed, ReentrantLock rollbackLock, ReentrantLock commitLock)
+            public ThreadAnonymousInnerClassHelper(TestIndexWriterWithThreads outerInstance,
BaseDirectoryWrapper d, AtomicReference<IndexWriter> writerRef, LineFileDocs docs, int
iters, AtomicBoolean failed, ReentrantLock rollbackLock, ReentrantLock commitLock)
             {
                 this.OuterInstance = outerInstance;
                 this.d = d;
@@ -701,12 +703,12 @@ namespace Lucene.Net.Index
                                 }
                                 try
                                 {
-                                    WriterRef.Rollback();
+                                    WriterRef.Value.Rollback();
                                     if (VERBOSE)
                                     {
                                         Console.WriteLine("TEST: " + Thread.CurrentThread.Name
+ ": rollback done; now open new writer");
                                     }
-                                    Interlocked.Exchange(ref WriterRef, new IndexWriter(d,
NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))));
+                                    WriterRef.Value = new IndexWriter(d, NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random())));
                                 }
                                 finally
                                 {
@@ -724,15 +726,15 @@ namespace Lucene.Net.Index
                                 {
                                     if (Random().NextBoolean())
                                     {
-                                        WriterRef.PrepareCommit();
+                                        WriterRef.Value.PrepareCommit();
                                     }
-                                    WriterRef.Commit();
+                                    WriterRef.Value.Commit();
                                 }
-                                catch (AlreadyClosedException)
+                                catch (AlreadyClosedException ace)
                                 {
                                     // ok
                                 }
-                                catch (NullReferenceException)
+                                catch (System.NullReferenceException npe)
                                 {
                                     // ok
                                 }
@@ -749,17 +751,17 @@ namespace Lucene.Net.Index
                                 }
                                 try
                                 {
-                                    WriterRef.AddDocument(Docs.NextDoc());
+                                    WriterRef.Value.AddDocument(Docs.NextDoc());
                                 }
-                                catch (AlreadyClosedException)
+                                catch (AlreadyClosedException ace)
                                 {
                                     // ok
                                 }
-                                catch (System.NullReferenceException)
+                                catch (System.NullReferenceException npe)
                                 {
                                     // ok
                                 }
-                                catch (InvalidOperationException)
+                                catch (InvalidOperationException ae)
                                 {
                                     // ok
                                 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5e8c8b6/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 5fd7339..8930728 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);
             }
 
-            CountdownEvent done = new CountdownEvent(numThreads);
+            CountDownLatch done = new CountDownLatch(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.Wait();
+            done.@await();
             writer.Dispose();
 
             DirectoryReader reader = DirectoryReader.Open(dir);
@@ -323,12 +323,12 @@ namespace Lucene.Net.Index
 
             private IndexWriter Writer;
             private int NumDocs;
-            private CountdownEvent Done;
+            private CountDownLatch Done;
             private AtomicInteger NumUpdates;
             private string f;
             private string Cf;
 
-            public ThreadAnonymousInnerClassHelper(TestMixedDocValuesUpdates outerInstance,
string str, IndexWriter writer, int numDocs, CountdownEvent done, AtomicInteger numUpdates,
string f, string cf)
+            public ThreadAnonymousInnerClassHelper(TestMixedDocValuesUpdates outerInstance,
string str, IndexWriter writer, int numDocs, CountDownLatch done, AtomicInteger numUpdates,
string f, string cf)
                 : base(str)
             {
                 this.OuterInstance = outerInstance;
@@ -438,7 +438,7 @@ namespace Lucene.Net.Index
                             }
                         }
                     }
-                    Done.Signal();
+                    Done.countDown();
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5e8c8b6/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 b9d592d..bf9d902 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);
             }
 
-            CountdownEvent done = new CountdownEvent(numThreads);
+            CountDownLatch done = new CountDownLatch(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.Wait();
+            done.@await();
             writer.Dispose();
 
             DirectoryReader reader = DirectoryReader.Open(dir);
@@ -1194,12 +1194,12 @@ namespace Lucene.Net.Index
 
             private IndexWriter Writer;
             private int NumDocs;
-            private CountdownEvent Done;
+            private CountDownLatch Done;
             private AtomicInteger NumUpdates;
             private string f;
             private string Cf;
 
-            public ThreadAnonymousInnerClassHelper(TestNumericDocValuesUpdates outerInstance,
string str, IndexWriter writer, int numDocs, CountdownEvent done, AtomicInteger numUpdates,
string f, string cf)
+            public ThreadAnonymousInnerClassHelper(TestNumericDocValuesUpdates outerInstance,
string str, IndexWriter writer, int numDocs, CountDownLatch done, AtomicInteger numUpdates,
string f, string cf)
                 : base(str)
             {
                 this.OuterInstance = outerInstance;
@@ -1307,7 +1307,7 @@ namespace Lucene.Net.Index
                             }
                         }
                     }
-                    Done.Signal();
+                    Done.countDown();
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5e8c8b6/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 87db2cd..edbbded 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()));
             }
-            CountdownEvent startingGun = new CountdownEvent(1);
+            CountDownLatch startingGun = new CountDownLatch(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.Signal();
+            startingGun.countDown();
             foreach (ThreadClass thread in threads)
             {
                 thread.Join();
@@ -251,9 +251,9 @@ namespace Lucene.Net.Search
             private readonly TestAutomatonQuery OuterInstance;
 
             private AutomatonQuery[] Queries;
-            private CountdownEvent StartingGun;
+            private CountDownLatch StartingGun;
 
-            public ThreadAnonymousInnerClassHelper(TestAutomatonQuery outerInstance, AutomatonQuery[]
queries, CountdownEvent startingGun)
+            public ThreadAnonymousInnerClassHelper(TestAutomatonQuery outerInstance, AutomatonQuery[]
queries, CountDownLatch startingGun)
             {
                 this.OuterInstance = outerInstance;
                 this.Queries = queries;
@@ -262,7 +262,7 @@ namespace Lucene.Net.Search
 
             public override void Run()
             {
-                StartingGun.Wait();
+                StartingGun.@await();
                 for (int i = 0; i < Queries.Length; i++)
                 {
                     Queries[i].GetHashCode();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5e8c8b6/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 4857fe1..6c3cc7d 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");
             }
 
-            CountdownEvent startingGun = new CountdownEvent(1);
+            CountDownLatch startingGun = new CountDownLatch(1);
             IList<ThreadClass> threads = new List<ThreadClass>();
 
             int iters = AtLeast(1000);
@@ -81,7 +81,7 @@ namespace Lucene.Net.Search
                 thread.Start();
             }
 
-            startingGun.Signal();
+            startingGun.countDown();
 
             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 CountdownEvent StartingGun;
+            private CountDownLatch 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, CountdownEvent 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, CountDownLatch 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.Wait();
+                    StartingGun.@await();
                     for (int iter = 0; iter < Iters; iter++)
                     {
                         // Add/update a document

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5e8c8b6/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 616ca1d..4541437 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)
             {
-                CountdownEvent startingGun = new CountdownEvent(1);
+                CountDownLatch startingGun = new CountDownLatch(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.Signal();
+                startingGun.countDown();
                 foreach (ThreadClass thread in threads)
                 {
                     thread.Join();
@@ -114,9 +114,9 @@ namespace Lucene.Net.Search
 
             private IndexSearcher s;
             private IDictionary<BytesRef, TopDocs> Answers;
-            private CountdownEvent StartingGun;
+            private CountDownLatch StartingGun;
 
-            public ThreadAnonymousInnerClassHelper(TestSameScoresWithThreads outerInstance,
IndexSearcher s, IDictionary<BytesRef, TopDocs> answers, CountdownEvent startingGun)
+            public ThreadAnonymousInnerClassHelper(TestSameScoresWithThreads outerInstance,
IndexSearcher s, IDictionary<BytesRef, TopDocs> answers, CountDownLatch startingGun)
             {
                 this.OuterInstance = outerInstance;
                 this.s = s;
@@ -128,7 +128,7 @@ namespace Lucene.Net.Search
             {
                 try
                 {
-                    StartingGun.Wait();
+                    StartingGun.@await();
                     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/a5e8c8b6/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 aedc8e5..5b0122d 100644
--- a/src/Lucene.Net.Tests/core/Search/TestSearcherManager.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestSearcherManager.cs
@@ -1,3 +1,4 @@
+using Apache.NMS.Util;
 using System;
 using System.Collections.Generic;
 using System.Threading;
@@ -264,8 +265,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();
-            CountdownEvent awaitEnterWarm = new CountdownEvent(1);
-            CountdownEvent awaitClose = new CountdownEvent(1);
+            CountDownLatch awaitEnterWarm = new CountDownLatch(1);
+            CountDownLatch awaitClose = new CountDownLatch(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);
@@ -293,13 +294,13 @@ namespace Lucene.Net.Search
             {
                 Console.WriteLine("THREAD started");
             }
-            awaitEnterWarmWait();
+            awaitEnterWarm.@await();
             if (VERBOSE)
             {
                 Console.WriteLine("NOW call close");
             }
             searcherManager.Dispose();
-            awaitClose.Signal();
+            awaitClose.countDown();
             thread.Join();
             try
             {
@@ -326,12 +327,12 @@ namespace Lucene.Net.Search
         {
             private readonly TestSearcherManager OuterInstance;
 
-            private CountdownEvent AwaitEnterWarm;
-            private CountdownEvent AwaitClose;
+            private CountDownLatch AwaitEnterWarm;
+            private CountDownLatch AwaitClose;
             private AtomicBoolean TriedReopen;
             private TaskScheduler Es;
 
-            public SearcherFactoryAnonymousInnerClassHelper2(TestSearcherManager outerInstance,
CountdownEvent awaitEnterWarm, CountdownEvent awaitClose, AtomicBoolean triedReopen, TaskScheduler
es)
+            public SearcherFactoryAnonymousInnerClassHelper2(TestSearcherManager outerInstance,
CountDownLatch awaitEnterWarm, CountDownLatch awaitClose, AtomicBoolean triedReopen, TaskScheduler
es)
             {
                 this.OuterInstance = outerInstance;
                 this.AwaitEnterWarm = awaitEnterWarm;
@@ -346,8 +347,8 @@ namespace Lucene.Net.Search
                 {
                     if (TriedReopen.Get())
                     {
-                        AwaitEnterWarm.Signal();
-                        AwaitClose.Wait();
+                        AwaitEnterWarm.countDown();
+                        AwaitClose.@await();
                     }
                 }
                 catch (ThreadInterruptedException e)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5e8c8b6/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 0dcec35..5d42841 100644
--- a/src/Lucene.Net.Tests/core/Util/TestNamedSPILoader.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestNamedSPILoader.cs
@@ -1,8 +1,10 @@
-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
@@ -20,77 +22,37 @@ 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 void Lookup_ExistingService_ReturnServiceByName()
-        {
-            // Arrange
-            var loader = CreateNamedSPILoaderForCodecClass();
-
-            // Act
-            var codec = loader.Lookup("CustomCodec1");
-
-            // Assert
-            Assert.IsInstanceOf<CustomCodec1>(codec);
-            Assert.AreEqual("CustomCodec1", codec.Name);
-        }
-
-        [Test]
-        public void Lookup_NonexistingService_ThrowsException()
+        public virtual void TestLookup()
         {
-            // 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);
+            Codec codec = Codec.ForName("Lucene46");
+            Assert.AreEqual("Lucene46", codec.Name);
         }
 
+        // we want an exception if its not found.
         [Test]
-        public void AvailableServices_LoaderWithServices_ReturnsListOfNamesOfRegisteredServices()
+        public virtual void TestBogusLookup()
         {
-            // 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
+            try
+            {
+                Codec.ForName("dskfdskfsdfksdfdsf");
+                Assert.Fail();
+            }
+            catch (System.ArgumentException expected)
             {
-                get
-                {
-                    return this.GetType().Name;
-                }
             }
         }
 
-        private class CustomCodec1 : CustomCodec
-        {
-        }
-
-        private class CustomCodec2 : CustomCodec
+        [Test]
+        public virtual void TestAvailableServices()
         {
+            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/a5e8c8b6/src/Lucene.Net.Tests/packages.config
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/packages.config b/src/Lucene.Net.Tests/packages.config
index 967502d..ffa0c4a 100644
--- a/src/Lucene.Net.Tests/packages.config
+++ b/src/Lucene.Net.Tests/packages.config
@@ -1,4 +1,6 @@
 <?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