lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [1/2] lucenenet git commit: match Lucene logic and mark IncrementToken as sealed
Date Mon, 09 Feb 2015 01:16:37 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master af785e29c -> 150651bc1


match Lucene logic and mark IncrementToken as sealed


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

Branch: refs/heads/master
Commit: 830932a9de67e9cb1a08a17c52969a59f77d8da4
Parents: af785e2
Author: Laimonas Simutis <laimis@gmail.com>
Authored: Sun Feb 8 20:02:16 2015 -0500
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Sun Feb 8 20:02:16 2015 -0500

----------------------------------------------------------------------
 .../Analysis/MockTokenizer.cs                   |  2 +-
 .../core/Index/TestIndexWriterExceptions.cs     | 29 ++++++++++-------
 .../core/Index/TestIndexWriterReader.cs         | 33 +++++++++-----------
 3 files changed, 34 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/830932a9/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs b/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs
index 894cf23..a890c45 100644
--- a/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs
+++ b/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs
@@ -138,7 +138,7 @@ namespace Lucene.Net.Analysis
         {
         }
 
-        public override bool IncrementToken()
+        public sealed override bool IncrementToken()
         {
             //Debug.Assert(!EnableChecks_Renamed || (StreamState == State.RESET || StreamState
== State.INCREMENT), "IncrementToken() called while in wrong state: " + StreamState);
             ClearAttributes();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/830932a9/src/Lucene.Net.Tests/core/Index/TestIndexWriterExceptions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestIndexWriterExceptions.cs b/src/Lucene.Net.Tests/core/Index/TestIndexWriterExceptions.cs
index aec7be5..ab0e08f 100644
--- a/src/Lucene.Net.Tests/core/Index/TestIndexWriterExceptions.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestIndexWriterExceptions.cs
@@ -228,7 +228,7 @@ namespace Lucene.Net.Index
                             Writer.UpdateDocument(idTerm, doc);
                         }
                     }
-                    catch (CorruptIndexException re)
+                    catch (TestPoint1Exception re)
                     {
                         if (VERBOSE)
                         {
@@ -297,11 +297,18 @@ namespace Lucene.Net.Index
                         Console.WriteLine(Thread.CurrentThread.Name + ": NOW FAIL: " + name);
                         Console.WriteLine((new Exception()).StackTrace);
                     }
-                    throw new Exception(Thread.CurrentThread.Name + ": intentionally failing
at " + name);
+                    throw new TestPoint1Exception(Thread.CurrentThread.Name + ": intentionally
failing at " + name);
                 }
             }
         }
 
+        private class TestPoint1Exception : ApplicationException
+        {
+            public TestPoint1Exception(string message) : base(message)
+            {
+            }
+        }
+
         [Test]
         public virtual void TestRandomExceptions()
         {
@@ -444,7 +451,7 @@ namespace Lucene.Net.Index
                 this.FieldName = fieldName;
             }
 
-            public override bool IncrementToken()
+            public sealed override bool IncrementToken()
             {
                 if (this.FieldName.Equals("crash") && Count++ >= 4)
                 {
@@ -659,7 +666,7 @@ namespace Lucene.Net.Index
 
                 private int count;
 
-                public override bool IncrementToken()
+                public sealed override bool IncrementToken()
                 {
                     if (count++ == 5)
                     {
@@ -2129,7 +2136,7 @@ namespace Lucene.Net.Index
 
             MockDirectoryWrapper dir = NewMockDirectory();
             AtomicBoolean shouldFail = new AtomicBoolean();
-            dir.FailOn(new FailureAnonymousInnerClassHelper2(this, dir, shouldFail));
+            dir.FailOn(new FailureAnonymousInnerClassHelper2(shouldFail));
 
             RandomIndexWriter w = null;
 
@@ -2358,21 +2365,21 @@ namespace Lucene.Net.Index
 
         private class FailureAnonymousInnerClassHelper2 : MockDirectoryWrapper.Failure
         {
-            private readonly TestIndexWriterExceptions OuterInstance;
-
-            private MockDirectoryWrapper Dir;
             private AtomicBoolean ShouldFail;
 
-            public FailureAnonymousInnerClassHelper2(TestIndexWriterExceptions outerInstance,
MockDirectoryWrapper dir, AtomicBoolean shouldFail)
+            public FailureAnonymousInnerClassHelper2(AtomicBoolean shouldFail)
             {
-                this.OuterInstance = outerInstance;
-                this.Dir = dir;
                 this.ShouldFail = shouldFail;
             }
 
             public override void Eval(MockDirectoryWrapper dir)
             {
                 var trace = new StackTrace();
+                if (ShouldFail.Get() == false)
+                {
+                    return;
+                }
+
                 bool sawSeal = false;
                 bool sawWrite = false;
                 foreach (var frame in trace.GetFrames())

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/830932a9/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs b/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs
index 70e7cd6..75482a5 100644
--- a/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs
+++ b/src/Lucene.Net.Tests/core/Index/TestIndexWriterReader.cs
@@ -45,7 +45,7 @@ namespace Lucene.Net.Index
     using TextField = TextField;
     using ThreadInterruptedException = Lucene.Net.Util.ThreadInterruptedException;
     using TopDocs = Lucene.Net.Search.TopDocs;
-
+    
     [TestFixture]
     public class TestIndexWriterReader : LuceneTestCase
     {
@@ -1318,7 +1318,7 @@ namespace Lucene.Net.Index
             // don't leak file handles.
             MockDirectoryWrapper dir = (MockDirectoryWrapper)GetAssertNoDeletesDirectory(NewMockDirectory());
             AtomicBoolean shouldFail = new AtomicBoolean();
-            dir.FailOn(new FailureAnonymousInnerClassHelper(this, dir, shouldFail));
+            dir.FailOn(new FailureAnonymousInnerClassHelper(shouldFail));
 
             IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
             conf.SetMergePolicy(NoMergePolicy.COMPOUND_FILES); // prevent merges from getting
in the way
@@ -1357,34 +1357,31 @@ namespace Lucene.Net.Index
 
         private class FailureAnonymousInnerClassHelper : MockDirectoryWrapper.Failure
         {
-            private readonly TestIndexWriterReader OuterInstance;
+            private readonly AtomicBoolean ShouldFail;
 
-            private MockDirectoryWrapper Dir;
-            private AtomicBoolean ShouldFail;
-
-            public FailureAnonymousInnerClassHelper(TestIndexWriterReader outerInstance,
MockDirectoryWrapper dir, AtomicBoolean shouldFail)
+            public FailureAnonymousInnerClassHelper(AtomicBoolean shouldFail)
             {
-                this.OuterInstance = outerInstance;
-                this.Dir = dir;
                 this.ShouldFail = shouldFail;
             }
 
             public override void Eval(MockDirectoryWrapper dir)
             {
-                //var trace = new StackTrace(new Exception());
                 var trace = new StackTrace();
-                foreach (var frame in trace.GetFrames())
+                if (ShouldFail.Get())
                 {
-                    var method = frame.GetMethod();
-                    if ("GetReadOnlyClone".Equals(method.Name))
+                    foreach (var frame in trace.GetFrames())
                     {
-                        if (VERBOSE)
+                        var method = frame.GetMethod();
+                        if ("GetReadOnlyClone".Equals(method.Name))
                         {
-                            Console.WriteLine("TEST: now fail; exc:");
-                            Console.WriteLine((new Exception()).StackTrace);
+                            if (VERBOSE)
+                            {
+                                Console.WriteLine("TEST: now fail; exc:");
+                                Console.WriteLine((new Exception()).StackTrace);
+                            }
+                            ShouldFail.Set(false);
+                            throw new FakeIOException();
                         }
-                        ShouldFail.Set(false);
-                        throw new FakeIOException();
                     }
                 }
             }


Mime
View raw message