Skip to content

RandomFailingFieldEnumerable/Iterable isn't properly randomly throwing #695

@NightOwl888

Description

@NightOwl888

See #259.

In TestIndexWriter, the GetEnumerator() return instance is supposed to throw random exceptions for the test, but it is currently commented out and returning an instance that doesn't throw exceptions. So, we are missing test conditions.

https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java#L2242-L2276

Furthermore, the anonymous class it returns needs to be refactored into an enumerator.

NOTE: As this is being written the name of the class is being changed from RandomFailingFieldIterable to RandomFailingFieldEnumerable for Lucene.NET. We should wait for the rename patch before fixing this to avoid merge conflicts.

        private class RandomFailingFieldEnumerable : IEnumerable<IEnumerable<IIndexableField>>
        {
            internal readonly IList<IEnumerable<IIndexableField>> docList;
            internal readonly Random random;

            public RandomFailingFieldEnumerable(IList<IEnumerable<IIndexableField>> docList, Random random)
            {
                this.docList = docList;
                this.random = random;
            }

            public virtual IEnumerator<IEnumerable<IIndexableField>> GetEnumerator()
            {
                return docList.GetEnumerator();
                //return new EnumeratorAnonymousClass(this, docIter);
            }

            IEnumerator IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }

            /*
          private class EnumeratorAnonymousClass : IEnumerator<IEnumerable<IndexableField>>
          {
              private readonly RandomFailingFieldEnumerable outerInstance;

              private IEnumerator<IEnumerable<IndexableField>> DocIter;

              public EnumeratorAnonymousClass(RandomFailingFieldEnumerable outerInstance, IEnumerator<IEnumerable<IndexableField>> docIter)
              {
                  this.outerInstance = outerInstance;
                  this.DocIter = docIter;
              }

              public virtual bool HasNext()
              {
                return DocIter.hasNext();
              }

              public virtual IEnumerable<IndexableField> Next()
              {
                if (outerInstance.Random.Next(5) == 0)
                {
                  throw RuntimeException.Create("boom");
                }
                return DocIter.Next();
              }

              public virtual void Remove()
              {
                  throw UnsupportedOperationException.Create();
              }
          }*/
        }

Fixing this may (but most likely will not) cause test failures that will need to be debugged and patched if they exist.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions