Skip to content

change implementation so that Read overrides behave as expected#29

Merged
asfgit merged 1 commit into
apache:masterfrom
laimis:MockReaderWrapper_fixes
Dec 27, 2014
Merged

change implementation so that Read overrides behave as expected#29
asfgit merged 1 commit into
apache:masterfrom
laimis:MockReaderWrapper_fixes

Conversation

@laimis

@laimis laimis commented Dec 27, 2014

Copy link
Copy Markdown
Contributor

Discovered this issue while running Lucene.Net.Analysis\TestGraphTokenizers tests. From time to time an assert would fail at this location:

https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.TestFramework/Analysis/BaseTokenStreamTestCase.cs#L964

The idea here is to randomly simulate an exception being thrown when token stream is being iterated. Instead of "evil exception" being thrown, the following assert would fail:

https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.TestFramework/Analysis/MockReaderWrapper.cs#L92

The underlying problem is the implementation of MockReaderWrapper in C#. It was not exactly a 1-to-1 map to the Java version due to framework differences and bug was introduced in MockReaderWrapper constructor:

https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.TestFramework/Analysis/MockReaderWrapper.cs#L43

StringReader's ReadToEnd() gets called advancing the iterator to the end. When the actual token stream iteration tries to read the stream, 0 is returned as the underlying text stream has been already iterated by the "ReadToEnd" call in the constructor. Furthermore, MockReaderWrapper should override Read() method as to make sure that all the possible ways that the reader is being used are covered (see https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.TestFramework/Analysis/MockTokenizer.cs#L242 how it can call Read with no params).

Also changed the way MockReader is initialized, instead of new StringReader, text string is passed to it directly. That seemed to make the most sense as there does not appear to be the need to create new stream reader on the same text just to extract that text again.

TestGraphTokenizers still occassionally fail but that appears to be due to another bug that gets invoked radomly and is yet to be determined what is the cause of it. Taking care of this "evil exception" branch gets us moving forward in that investigation.

@synhershko

Copy link
Copy Markdown
Contributor

Looks good, let us know when its ready to merge!

@laimis

laimis commented Dec 27, 2014

Copy link
Copy Markdown
Contributor Author

If it looks good to you, I say go ahead and merge. Most of the times TestGraphTokenizer tests now pass. In certain conditions we still encounter failures but they are not related to the MockReaderWrapper anymore.

@asfgit asfgit merged commit 6b16956 into apache:master Dec 27, 2014
@laimis laimis deleted the MockReaderWrapper_fixes branch December 27, 2014 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants