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: change implementation so that Read overrides behave as expected
Date Sat, 27 Dec 2014 17:21:14 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master b688fb355 -> 959ceb954


change implementation so that Read overrides behave as expected


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

Branch: refs/heads/master
Commit: 6b169565f88b5a776ff12ed460e7fb5d00a5468e
Parents: 2221c6e
Author: Laimonas Simutis <laimis@gmail.com>
Authored: Sat Dec 27 11:42:39 2014 -0500
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Sat Dec 27 11:42:39 2014 -0500

----------------------------------------------------------------------
 .../Analysis/BaseTokenStreamTestCase.cs         |  6 ++--
 .../Analysis/MockReaderWrapper.cs               | 31 ++++++++++++--------
 2 files changed, 22 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6b169565/src/Lucene.Net.TestFramework/Analysis/BaseTokenStreamTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Analysis/BaseTokenStreamTestCase.cs b/src/Lucene.Net.TestFramework/Analysis/BaseTokenStreamTestCase.cs
index ae519a1..9dbd673 100644
--- a/src/Lucene.Net.TestFramework/Analysis/BaseTokenStreamTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Analysis/BaseTokenStreamTestCase.cs
@@ -939,7 +939,7 @@ namespace Lucene.Net.Analysis
                         }
                         // Throw an errant exception from the Reader:
 
-                        MockReaderWrapper evilReader = new MockReaderWrapper(random, new
StringReader(text));
+                        MockReaderWrapper evilReader = new MockReaderWrapper(random, text);
                         evilReader.ThrowExcAfterChar(random.Next(text.Length));
                         reader = evilReader;
 
@@ -1046,7 +1046,7 @@ namespace Lucene.Net.Analysis
                     Console.WriteLine(Thread.CurrentThread.Name + ": NOTE: baseTokenStreamTestCase:
using spoon-feed reader");
                 }
 
-                reader = new MockReaderWrapper(random, reader);
+                reader = new MockReaderWrapper(random, text);
             }
 
             ts = a.TokenStream("dummy", useCharFilter ? (TextReader)new MockCharFilter(reader,
remainder) : reader);
@@ -1092,7 +1092,7 @@ namespace Lucene.Net.Analysis
                         Console.WriteLine(Thread.CurrentThread.Name + ": NOTE: baseTokenStreamTestCase:
indexing using spoon-feed reader");
                     }
 
-                    reader = new MockReaderWrapper(random, reader);
+                    reader = new MockReaderWrapper(random, text);
                 }
 
                 field.ReaderValue = useCharFilter ? (TextReader)new MockCharFilter(reader,
remainder) : reader;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6b169565/src/Lucene.Net.TestFramework/Analysis/MockReaderWrapper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Analysis/MockReaderWrapper.cs b/src/Lucene.Net.TestFramework/Analysis/MockReaderWrapper.cs
index 1fe49b2..9c42dcf 100644
--- a/src/Lucene.Net.TestFramework/Analysis/MockReaderWrapper.cs
+++ b/src/Lucene.Net.TestFramework/Analysis/MockReaderWrapper.cs
@@ -32,17 +32,15 @@ namespace Lucene.Net.Analysis
 
     public class MockReaderWrapper : StringReader
     {
-        private readonly StringReader @in;
         private readonly Random Random;
 
         private int ExcAtChar = -1;
         private int ReadSoFar;
         private bool ThrowExcNext_Renamed;
 
-        public MockReaderWrapper(Random random, StringReader @in)
-            : base(@in.ReadToEnd())
+        public MockReaderWrapper(Random random, string text)
+            : base(text)
         {
-            this.@in = @in;
             this.Random = random;
         }
 
@@ -60,17 +58,18 @@ namespace Lucene.Net.Analysis
             ThrowExcNext_Renamed = true;
         }
 
-        public override void Close()
+        public override int Read()
         {
-            @in.Close();
+            ThrowExceptionIfApplicable();
+
+            var c = base.Read();
+            ReadSoFar += 1;
+            return c;
         }
 
         public override int Read(char[] cbuf, int off, int len)
         {
-            if (ThrowExcNext_Renamed || (ExcAtChar != -1 && ReadSoFar >= ExcAtChar))
-            {
-                throw new Exception("fake exception now!");
-            }
+            ThrowExceptionIfApplicable();
             int read;
             int realLen;
             if (len == 1)
@@ -87,14 +86,14 @@ namespace Lucene.Net.Analysis
             {
                 int left = ExcAtChar - ReadSoFar;
                 Assert.True(left != 0);
-                read = @in.Read(cbuf, off, Math.Min(realLen, left));
+                read = base.Read(cbuf, off, Math.Min(realLen, left));
                 //Characters are left
                 Assert.True(read != 0);
                 ReadSoFar += read;
             }
             else
             {
-                read = @in.Read(cbuf, off, realLen);
+                read = base.Read(cbuf, off, realLen);
                 //Terrible TextReader::Read semantics
                 if (read == 0)
                 {
@@ -104,6 +103,14 @@ namespace Lucene.Net.Analysis
             return read;
         }
 
+        private void ThrowExceptionIfApplicable()
+        {
+            if (ThrowExcNext_Renamed || (ExcAtChar != -1 && ReadSoFar >= ExcAtChar))
+            {
+                throw new Exception("fake exception now!");
+            }
+        }
+
         public bool MarkSupported()
         {
             return false;


Mime
View raw message