You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2016/10/23 13:02:25 UTC

[39/50] [abbrv] lucenenet git commit: Fixed issues with tests polluting each other's state by setting FieldCache.InfoStream in the setup of the FieldCache specific tests and tearing them down properly rather than leaving the state around for other tests.

Fixed issues with tests polluting each other's state by setting FieldCache.InfoStream in the setup of the FieldCache specific tests and tearing them down properly rather than leaving the state around for other tests.


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

Branch: refs/heads/master
Commit: 4a8a6f18e9315439cf769a9ded7b6989683ccbee
Parents: 77d1948
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Sun Oct 23 16:54:47 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Sun Oct 23 19:36:47 2016 +0700

----------------------------------------------------------------------
 .../core/Search/TestFieldCache.cs               | 54 +++++++++++-----
 .../core/Search/TestFieldCacheRangeFilter.cs    | 64 ++++++++++++------
 src/Lucene.Net.Tests/core/Search/TestSort.cs    | 68 +++++++++++++-------
 .../core/Util/TestFieldCacheSanityChecker.cs    | 47 +++++++++-----
 4 files changed, 159 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4a8a6f18/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs b/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs
index 9c71e78..d45f364 100644
--- a/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs
@@ -11,24 +11,23 @@ using System.Threading;
 
 namespace Lucene.Net.Search
 {
-
     /*
-    /// Copyright 2004 The Apache Software Foundation
-    /// 
-    /// Licensed under the Apache License, Version 2.0 (the "License");
-    /// you may not use this file except in compliance with the License.
-    /// You may obtain a copy of the License at
-    /// 
-    ///     http://www.apache.org/licenses/LICENSE-2.0
-    /// 
-    /// Unless required by applicable law or agreed to in writing, software
-    /// distributed under the License is distributed on an "AS IS" BASIS,
-    /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    /// See the License for the specific language governing permissions and
-    /// limitations under the License.
+    * Licensed to the Apache Software Foundation (ASF) under one or more
+    * contributor license agreements.  See the NOTICE file distributed with
+    * this work for additional information regarding copyright ownership.
+    * The ASF licenses this file to You under the Apache License, Version 2.0
+    * (the "License"); you may not use this file except in compliance with
+    * the License.  You may obtain a copy of the License at
+    *
+    *     http://www.apache.org/licenses/LICENSE-2.0
+    *
+    * Unless required by applicable law or agreed to in writing, software
+    * distributed under the License is distributed on an "AS IS" BASIS,
+    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    * See the License for the specific language governing permissions and
+    * limitations under the License.
     */
 
-
     using MockAnalyzer = Lucene.Net.Analysis.MockAnalyzer;
     using BinaryDocValuesField = Lucene.Net.Documents.BinaryDocValuesField;
     using Document = Lucene.Net.Documents.Document;
@@ -76,6 +75,31 @@ namespace Lucene.Net.Search
         private static BytesRef[][] MultiValued;
         private static Directory Directory;
 
+        /// <summary>
+        /// LUCENENET specific. Ensure we have an infostream attached to the default FieldCache
+        /// when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream() 
+        /// method (which polluted the state of these tests), but we need to make the tests self-contained 
+        /// so they can be run correctly regardless of order. Not setting the InfoStream skips an execution
+        /// path within these tests, so we should do it to make sure we test all of the code.
+        /// </summary>
+        public override void SetUp()
+        {
+            base.SetUp();
+            FieldCache.DEFAULT.InfoStream = new StringWriter();
+        }
+
+        /// <summary>
+        /// LUCENENET specific. See <see cref="SetUp()"/>. Dispose our InfoStream and set it to null
+        /// to avoid polluting the state of other tests.
+        /// </summary>
+        public override void TearDown()
+        {
+            FieldCache.DEFAULT.InfoStream.Dispose();
+            FieldCache.DEFAULT.InfoStream = null;
+            base.TearDown();
+        }
+
+
         // LUCENENET: Changed to non-static because NewIndexWriterConfig is non-static
         [TestFixtureSetUp]
         public void BeforeClass()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4a8a6f18/src/Lucene.Net.Tests/core/Search/TestFieldCacheRangeFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestFieldCacheRangeFilter.cs b/src/Lucene.Net.Tests/core/Search/TestFieldCacheRangeFilter.cs
index 1acffbd..cc0d022 100644
--- a/src/Lucene.Net.Tests/core/Search/TestFieldCacheRangeFilter.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestFieldCacheRangeFilter.cs
@@ -1,30 +1,30 @@
-using System;
 using Lucene.Net.Documents;
+using NUnit.Framework;
+using System;
+using System.IO;
 
 namespace Lucene.Net.Search
 {
-    using NUnit.Framework;
+    /*
+    * Licensed to the Apache Software Foundation (ASF) under one or more
+    * contributor license agreements.  See the NOTICE file distributed with
+    * this work for additional information regarding copyright ownership.
+    * The ASF licenses this file to You under the Apache License, Version 2.0
+    * (the "License"); you may not use this file except in compliance with
+    * the License.  You may obtain a copy of the License at
+    *
+    *     http://www.apache.org/licenses/LICENSE-2.0
+    *
+    * Unless required by applicable law or agreed to in writing, software
+    * distributed under the License is distributed on an "AS IS" BASIS,
+    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    * See the License for the specific language governing permissions and
+    * limitations under the License.
+    */
+
     using Directory = Lucene.Net.Store.Directory;
     using DirectoryReader = Lucene.Net.Index.DirectoryReader;
     using Document = Documents.Document;
-
-    /*
-         * Licensed to the Apache Software Foundation (ASF) under one or more
-         * contributor license agreements.  See the NOTICE file distributed with
-         * this work for additional information regarding copyright ownership.
-         * The ASF licenses this file to You under the Apache License, Version 2.0
-         * (the "License"); you may not use this file except in compliance with
-         * the License.  You may obtain a copy of the License at
-         *
-         *     http://www.apache.org/licenses/LICENSE-2.0
-         *
-         * Unless required by applicable law or agreed to in writing, software
-         * distributed under the License is distributed on an "AS IS" BASIS,
-         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-         * See the License for the specific language governing permissions and
-         * limitations under the License.
-         */
-
     using Field = Field;
     using IndexReader = Lucene.Net.Index.IndexReader;
     using IndexWriter = Lucene.Net.Index.IndexWriter;
@@ -43,6 +43,30 @@ namespace Lucene.Net.Search
     [TestFixture]
     public class TestFieldCacheRangeFilter : BaseTestRangeFilter
     {
+        /// <summary>
+        /// LUCENENET specific. Ensure we have an infostream attached to the default FieldCache
+        /// when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream() 
+        /// method (which polluted the state of these tests), but we need to make the tests self-contained 
+        /// so they can be run correctly regardless of order. Not setting the InfoStream skips an execution
+        /// path within these tests, so we should do it to make sure we test all of the code.
+        /// </summary>
+        public override void SetUp()
+        {
+            base.SetUp();
+            FieldCache.DEFAULT.InfoStream = new StringWriter();
+        }
+
+        /// <summary>
+        /// LUCENENET specific. See <see cref="SetUp()"/>. Dispose our InfoStream and set it to null
+        /// to avoid polluting the state of other tests.
+        /// </summary>
+        public override void TearDown()
+        {
+            FieldCache.DEFAULT.InfoStream.Dispose();
+            FieldCache.DEFAULT.InfoStream = null;
+            base.TearDown();
+        }
+
         [Test]
         public virtual void TestRangeFilterId()
         {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4a8a6f18/src/Lucene.Net.Tests/core/Search/TestSort.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestSort.cs b/src/Lucene.Net.Tests/core/Search/TestSort.cs
index a7cdab0..0c32d54 100644
--- a/src/Lucene.Net.Tests/core/Search/TestSort.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestSort.cs
@@ -1,13 +1,31 @@
+using Lucene.Net.Documents;
+using Lucene.Net.Randomized.Generators;
+using Lucene.Net.Support;
+using NUnit.Framework;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Text;
-using Lucene.Net.Documents;
 
 namespace Lucene.Net.Search
 {
-    using Lucene.Net.Randomized.Generators;
-    using Lucene.Net.Support;
-    using NUnit.Framework;
+    /*
+    * Licensed to the Apache Software Foundation (ASF) under one or more
+    * contributor license agreements.  See the NOTICE file distributed with
+    * this work for additional information regarding copyright ownership.
+    * The ASF licenses this file to You under the Apache License, Version 2.0
+    * (the "License"); you may not use this file except in compliance with
+    * the License.  You may obtain a copy of the License at
+    *
+    *     http://www.apache.org/licenses/LICENSE-2.0
+    *
+    * Unless required by applicable law or agreed to in writing, software
+    * distributed under the License is distributed on an "AS IS" BASIS,
+    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    * See the License for the specific language governing permissions and
+    * limitations under the License.
+    */
+
     using BytesRef = Lucene.Net.Util.BytesRef;
     using Directory = Lucene.Net.Store.Directory;
     using DirectoryReader = Lucene.Net.Index.DirectoryReader;
@@ -17,24 +35,6 @@ namespace Lucene.Net.Search
     using IndexWriter = Lucene.Net.Index.IndexWriter;
     using IndexWriterConfig = Lucene.Net.Index.IndexWriterConfig;
     using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
-
-    /*
-         * Licensed to the Apache Software Foundation (ASF) under one or more
-         * contributor license agreements.  See the NOTICE file distributed with
-         * this work for additional information regarding copyright ownership.
-         * The ASF licenses this file to You under the Apache License, Version 2.0
-         * (the "License"); you may not use this file except in compliance with
-         * the License.  You may obtain a copy of the License at
-         *
-         *     http://www.apache.org/licenses/LICENSE-2.0
-         *
-         * Unless required by applicable law or agreed to in writing, software
-         * distributed under the License is distributed on an "AS IS" BASIS,
-         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-         * See the License for the specific language governing permissions and
-         * limitations under the License.
-         */
-
     using MockAnalyzer = Lucene.Net.Analysis.MockAnalyzer;
     using MultiReader = Lucene.Net.Index.MultiReader;
     using Occur = Lucene.Net.Search.BooleanClause.Occur;
@@ -64,6 +64,30 @@ namespace Lucene.Net.Search
     public class TestSort : LuceneTestCase
     {
         /// <summary>
+        /// LUCENENET specific. Ensure we have an infostream attached to the default FieldCache
+        /// when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream() 
+        /// method (which polluted the state of these tests), but we need to make the tests self-contained 
+        /// so they can be run correctly regardless of order. Not setting the InfoStream skips an execution
+        /// path within these tests, so we should do it to make sure we test all of the code.
+        /// </summary>
+        public override void SetUp()
+        {
+            base.SetUp();
+            FieldCache.DEFAULT.InfoStream = new StringWriter();
+        }
+
+        /// <summary>
+        /// LUCENENET specific. See <see cref="SetUp()"/>. Dispose our InfoStream and set it to null
+        /// to avoid polluting the state of other tests.
+        /// </summary>
+        public override void TearDown()
+        {
+            FieldCache.DEFAULT.InfoStream.Dispose();
+            FieldCache.DEFAULT.InfoStream = null;
+            base.TearDown();
+        }
+
+        /// <summary>
         /// Tests sorting on type string </summary>
         [Test]
         public virtual void TestString()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/4a8a6f18/src/Lucene.Net.Tests/core/Util/TestFieldCacheSanityChecker.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestFieldCacheSanityChecker.cs b/src/Lucene.Net.Tests/core/Util/TestFieldCacheSanityChecker.cs
index aaa7ff1..6a4a2e1 100644
--- a/src/Lucene.Net.Tests/core/Util/TestFieldCacheSanityChecker.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestFieldCacheSanityChecker.cs
@@ -2,9 +2,27 @@ using Lucene.Net.Documents;
 using Lucene.Net.Search;
 using NUnit.Framework;
 using System;
+using System.IO;
 
 namespace Lucene.Net.Util
 {
+    /*
+    * Licensed to the Apache Software Foundation (ASF) under one or more
+    * contributor license agreements.  See the NOTICE file distributed with
+    * this work for additional information regarding copyright ownership.
+    * The ASF licenses this file to You under the Apache License, Version 2.0
+    * (the "License"); you may not use this file except in compliance with
+    * the License.  You may obtain a copy of the License at
+    *
+    *     http://www.apache.org/licenses/LICENSE-2.0
+    *
+    * Unless required by applicable law or agreed to in writing, software
+    * distributed under the License is distributed on an "AS IS" BASIS,
+    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    * See the License for the specific language governing permissions and
+    * limitations under the License.
+    */
+
     using AtomicReader = Lucene.Net.Index.AtomicReader;
     using Directory = Lucene.Net.Store.Directory;
     using DirectoryReader = Lucene.Net.Index.DirectoryReader;
@@ -13,23 +31,6 @@ namespace Lucene.Net.Util
     using IndexWriter = Lucene.Net.Index.IndexWriter;
     using Insanity = Lucene.Net.Util.FieldCacheSanityChecker.Insanity;
     using InsanityType = Lucene.Net.Util.FieldCacheSanityChecker.InsanityType;
-
-    /*
-        /// Copyright 2009 The Apache Software Foundation
-        ///
-        /// Licensed under the Apache License, Version 2.0 (the "License");
-        /// you may not use this file except in compliance with the License.
-        /// You may obtain a copy of the License at
-        ///
-        ///     http://www.apache.org/licenses/LICENSE-2.0
-        ///
-        /// Unless required by applicable law or agreed to in writing, software
-        /// distributed under the License is distributed on an "AS IS" BASIS,
-        /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-        /// See the License for the specific language governing permissions and
-        /// limitations under the License.
-        */
-
     using MockAnalyzer = Lucene.Net.Analysis.MockAnalyzer;
     using MultiReader = Lucene.Net.Index.MultiReader;
     using SlowCompositeReaderWrapper = Lucene.Net.Index.SlowCompositeReaderWrapper;
@@ -87,6 +88,13 @@ namespace Lucene.Net.Util
             ReaderA = SlowCompositeReaderWrapper.Wrap(DirectoryReader.Open(DirA));
             ReaderB = SlowCompositeReaderWrapper.Wrap(DirectoryReader.Open(DirB));
             ReaderX = SlowCompositeReaderWrapper.Wrap(new MultiReader(ReaderA, ReaderB));
+
+            // LUCENENET specific.Ensure we have an infostream attached to the default FieldCache
+            // when running the tests. In Java, this was done in the Core.Search.TestFieldCache.TestInfoStream()
+            // method (which polluted the state of these tests), but we need to make the tests self-contained
+            // so they can be run correctly regardless of order. Not setting the InfoStream skips an execution
+            // path within these tests, so we should do it to make sure we test all of the code.
+            FieldCache.DEFAULT.InfoStream = new StringWriter();
         }
 
         [TearDown]
@@ -98,6 +106,11 @@ namespace Lucene.Net.Util
             ReaderX.Dispose();
             DirA.Dispose();
             DirB.Dispose();
+
+            // LUCENENET specific. See <see cref="SetUp()"/>. Dispose our InfoStream and set it to null
+            // to avoid polluting the state of other tests.
+            FieldCache.DEFAULT.InfoStream.Dispose();
+            FieldCache.DEFAULT.InfoStream = null;
             base.TearDown();
         }