lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [20/32] lucenenet git commit: Adding TestWriterMethods so that it does not rely on external static call
Date Fri, 12 Aug 2016 13:25:33 GMT
Adding TestWriterMethods so that it does not rely on external static call


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

Branch: refs/heads/master
Commit: b9bb484d00225721081efc02782ce9191be8a83a
Parents: c15ab48
Author: Connie Yau <conniey@microsoft.com>
Authored: Sun Jul 31 22:54:23 2016 -0700
Committer: Connie Yau <conniey@microsoft.com>
Committed: Sun Jul 31 22:54:23 2016 -0700

----------------------------------------------------------------------
 src/Lucene.Net.Tests/core/Index/TestCodecs.cs   |  2 +-
 .../core/Index/TestIndexWriterCommit.cs         | 56 +++++++++++++-------
 .../core/Index/TestIndexWriterForceMerge.cs     | 22 +++++++-
 3 files changed, 59 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b9bb484d/src/Lucene.Net.Tests/core/Index/TestCodecs.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestCodecs.cs b/src/Lucene.Net.Tests/core/Index/TestCodecs.cs
index ca0113b..1091e5e 100644
--- a/src/Lucene.Net.Tests/core/Index/TestCodecs.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestCodecs.cs
@@ -890,7 +890,7 @@ namespace Lucene.Net.Index
         [Test]
         public virtual void TestDisableImpersonation()
         {
-            Codec[] oldCodecs = new Codec[] { new Lucene40RWCodec(), new Lucene41RWCodec(),
new Lucene42RWCodec() };
+            Codec[] oldCodecs = new Codec[] { new Lucene40RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE),
new Lucene41RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE), new Lucene42RWCodec(OLD_FORMAT_IMPERSONATION_IS_ACTIVE)
};
             Directory dir = NewDirectory();
             IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
             conf.SetCodec(oldCodecs[Random().Next(oldCodecs.Length)]);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b9bb484d/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs b/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs
index 3f898e7..3f06879 100644
--- a/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestIndexWriterCommit.cs
@@ -40,6 +40,8 @@ namespace Lucene.Net.Index
     [TestFixture]
     public class TestIndexWriterCommit : LuceneTestCase
     {
+        private static readonly FieldType StoredTextType = new FieldType(TextField.TYPE_NOT_STORED);
+
         /*
          * Simple test for "commit on close": open writer then
          * add a bunch of docs, making sure reader does not see
@@ -53,7 +55,7 @@ namespace Lucene.Net.Index
             IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random())));
             for (int i = 0; i < 14; i++)
             {
-                TestIndexWriter.AddDoc(writer);
+                AddDoc(writer);
             }
             writer.Dispose();
 
@@ -71,7 +73,7 @@ namespace Lucene.Net.Index
             {
                 for (int j = 0; j < 11; j++)
                 {
-                    TestIndexWriter.AddDoc(writer);
+                    AddDoc(writer);
                 }
                 IndexReader r = DirectoryReader.Open(dir);
                 searcher = NewSearcher(r);
@@ -110,7 +112,7 @@ namespace Lucene.Net.Index
             IndexWriter writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random())).SetMaxBufferedDocs(10));
             for (int i = 0; i < 14; i++)
             {
-                TestIndexWriter.AddDoc(writer);
+                AddDoc(writer);
             }
             writer.Dispose();
 
@@ -124,7 +126,7 @@ namespace Lucene.Net.Index
             writer = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random())).SetOpenMode(OpenMode_e.APPEND).SetMaxBufferedDocs(10));
             for (int j = 0; j < 17; j++)
             {
-                TestIndexWriter.AddDoc(writer);
+                AddDoc(writer);
             }
             // Delete all docs:
             writer.DeleteDocuments(searchTerm);
@@ -161,7 +163,7 @@ namespace Lucene.Net.Index
             {
                 for (int j = 0; j < 17; j++)
                 {
-                    TestIndexWriter.AddDoc(writer);
+                    AddDoc(writer);
                 }
                 IndexReader r = DirectoryReader.Open(dir);
                 searcher = NewSearcher(r);
@@ -217,7 +219,7 @@ namespace Lucene.Net.Index
             IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT,
analyzer).SetMaxBufferedDocs(10).SetReaderPooling(false).SetMergePolicy(NewLogMergePolicy(10)));
             for (int j = 0; j < 30; j++)
             {
-                TestIndexWriter.AddDocWithIndex(writer, j);
+                AddDocWithIndex(writer, j);
             }
             writer.Dispose();
             dir.ResetMaxUsedSizeInBytes();
@@ -227,7 +229,7 @@ namespace Lucene.Net.Index
             writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetOpenMode(OpenMode_e.APPEND).SetMaxBufferedDocs(10).SetMergeScheduler(new
SerialMergeScheduler()).SetReaderPooling(false).SetMergePolicy(NewLogMergePolicy(10)));
             for (int j = 0; j < 1470; j++)
             {
-                TestIndexWriter.AddDocWithIndex(writer, j);
+                AddDocWithIndex(writer, j);
             }
             long midDiskUsage = dir.MaxUsedSizeInBytes;
             dir.ResetMaxUsedSizeInBytes();
@@ -303,7 +305,7 @@ namespace Lucene.Net.Index
             IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random())).SetMaxBufferedDocs(10).SetMergePolicy(NewLogMergePolicy(10)));
             for (int j = 0; j < 17; j++)
             {
-                TestIndexWriter.AddDocWithIndex(writer, j);
+                AddDocWithIndex(writer, j);
             }
             writer.Dispose();
 
@@ -370,7 +372,7 @@ namespace Lucene.Net.Index
             for (int i = 0; i < NUM_THREADS; i++)
             {
                 int finalI = i;
-                threads[i] = new ThreadAnonymousInnerClassHelper(dir, w, failed, endTime,
finalI);
+                threads[i] = new ThreadAnonymousInnerClassHelper(dir, w, failed, endTime,
finalI, NewStringField);
                 threads[i].Start();
             }
             for (int i = 0; i < NUM_THREADS; i++)
@@ -384,14 +386,16 @@ namespace Lucene.Net.Index
 
         private class ThreadAnonymousInnerClassHelper : ThreadClass
         {
+            private readonly Func<string, string, Field.Store, Field> NewStringField;
             private Directory Dir;
             private RandomIndexWriter w;
             private AtomicBoolean Failed;
             private long EndTime;
             private int FinalI;
 
-            public ThreadAnonymousInnerClassHelper(Directory dir, RandomIndexWriter w, AtomicBoolean
failed, long endTime, int finalI)
+            public ThreadAnonymousInnerClassHelper(Directory dir, RandomIndexWriter w, AtomicBoolean
failed, long endTime, int finalI, Func<string, string, Field.Store, Field> newStringField)
             {
+                NewStringField = newStringField;
                 this.Dir = dir;
                 this.w = w;
                 this.Failed = failed;
@@ -449,7 +453,7 @@ namespace Lucene.Net.Index
 
             for (int i = 0; i < 23; i++)
             {
-                TestIndexWriter.AddDoc(writer);
+                AddDoc(writer);
             }
 
             DirectoryReader reader = DirectoryReader.Open(dir);
@@ -463,7 +467,7 @@ namespace Lucene.Net.Index
 
             for (int i = 0; i < 17; i++)
             {
-                TestIndexWriter.AddDoc(writer);
+                AddDoc(writer);
             }
             Assert.AreEqual(23, reader2.NumDocs);
             reader2.Dispose();
@@ -573,7 +577,7 @@ namespace Lucene.Net.Index
 
             for (int i = 0; i < 23; i++)
             {
-                TestIndexWriter.AddDoc(writer);
+                AddDoc(writer);
             }
 
             DirectoryReader reader = DirectoryReader.Open(dir);
@@ -596,7 +600,7 @@ namespace Lucene.Net.Index
 
             for (int i = 0; i < 17; i++)
             {
-                TestIndexWriter.AddDoc(writer);
+                AddDoc(writer);
             }
 
             Assert.AreEqual(23, reader3.NumDocs);
@@ -634,7 +638,7 @@ namespace Lucene.Net.Index
 
             for (int i = 0; i < 23; i++)
             {
-                TestIndexWriter.AddDoc(writer);
+                AddDoc(writer);
             }
 
             DirectoryReader reader = DirectoryReader.Open(dir);
@@ -657,7 +661,7 @@ namespace Lucene.Net.Index
             writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new
MockAnalyzer(Random())));
             for (int i = 0; i < 17; i++)
             {
-                TestIndexWriter.AddDoc(writer);
+                AddDoc(writer);
             }
 
             reader = DirectoryReader.Open(dir);
@@ -703,7 +707,7 @@ namespace Lucene.Net.Index
             IndexWriter w = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random())).SetMaxBufferedDocs(2));
             for (int j = 0; j < 17; j++)
             {
-                TestIndexWriter.AddDoc(w);
+                AddDoc(w);
             }
             w.Dispose();
 
@@ -715,7 +719,7 @@ namespace Lucene.Net.Index
             w = new IndexWriter(dir, (IndexWriterConfig)NewIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(Random())).SetMaxBufferedDocs(2));
             for (int j = 0; j < 17; j++)
             {
-                TestIndexWriter.AddDoc(w);
+                AddDoc(w);
             }
             IDictionary<string, string> data = new Dictionary<string, string>();
             data["label"] = "test1";
@@ -732,5 +736,21 @@ namespace Lucene.Net.Index
 
             dir.Dispose();
         }
+
+        private void AddDoc(IndexWriter writer)
+        {
+            Document doc = new Document();
+            doc.Add(NewTextField("content", "aaa", Field.Store.NO));
+            writer.AddDocument(doc);
+        }
+
+        private void AddDocWithIndex(IndexWriter writer, int index)
+        {
+            Document doc = new Document();
+            doc.Add(NewField("content", "aaa " + index, StoredTextType));
+            doc.Add(NewField("id", "" + index, StoredTextType));
+            writer.AddDocument(doc);
+        }
+
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/b9bb484d/src/Lucene.Net.Tests/core/Index/TestIndexWriterForceMerge.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestIndexWriterForceMerge.cs b/src/Lucene.Net.Tests/core/Index/TestIndexWriterForceMerge.cs
index debf331..33f1063 100644
--- a/src/Lucene.Net.Tests/core/Index/TestIndexWriterForceMerge.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestIndexWriterForceMerge.cs
@@ -34,6 +34,8 @@ namespace Lucene.Net.Index
     [TestFixture]
     public class TestIndexWriterForceMerge : LuceneTestCase
     {
+        private static readonly FieldType StoredTextType = new FieldType(TextField.TYPE_NOT_STORED);
+
         [Test]
         public virtual void TestPartialMerge()
         {
@@ -150,13 +152,13 @@ namespace Lucene.Net.Index
 
             for (int j = 0; j < 500; j++)
             {
-                TestIndexWriter.AddDocWithIndex(writer, j);
+                AddDocWithIndex(writer, j);
             }
             int termIndexInterval = writer.Config.TermIndexInterval;
             // force one extra segment w/ different doc store so
             // we see the doc stores get merged
             writer.Commit();
-            TestIndexWriter.AddDocWithIndex(writer, 500);
+            AddDocWithIndex(writer, 500);
             writer.Dispose();
 
             if (VERBOSE)
@@ -233,5 +235,21 @@ namespace Lucene.Net.Index
 
             dir.Dispose();
         }
+
+        private void AddDoc(IndexWriter writer)
+        {
+            Document doc = new Document();
+            doc.Add(NewTextField("content", "aaa", Field.Store.NO));
+            writer.AddDocument(doc);
+        }
+
+        private void AddDocWithIndex(IndexWriter writer, int index)
+        {
+            Document doc = new Document();
+            doc.Add(NewField("content", "aaa " + index, StoredTextType));
+            doc.Add(NewField("id", "" + index, StoredTextType));
+            writer.AddDocument(doc);
+        }
+
     }
 }
\ No newline at end of file


Mime
View raw message