public virtual void TestCloseInnerReader()
        {
            Directory       dir1 = GetDir1(Random);
            CompositeReader ir1  = DirectoryReader.Open(dir1);

            Assert.AreEqual(1, ir1.GetSequentialSubReaders()[0].RefCount);

            // with overlapping
            ParallelCompositeReader pr = new ParallelCompositeReader(true, new CompositeReader[] { ir1 }, new CompositeReader[] { ir1 });

            IndexReader psub = pr.GetSequentialSubReaders()[0];

            Assert.AreEqual(1, psub.RefCount);

            ir1.Dispose();

            Assert.AreEqual(1, psub.RefCount, "refCount of synthetic subreader should be unchanged");
            try
            {
                psub.Document(0);
                Assert.Fail("Subreader should be already closed because inner reader was closed!");
            }
#pragma warning disable 168
            catch (ObjectDisposedException e)
#pragma warning restore 168
            {
                // pass
            }

            try
            {
                pr.Document(0);
                Assert.Fail("ParallelCompositeReader should be already closed because inner reader was closed!");
            }
#pragma warning disable 168
            catch (ObjectDisposedException e)
#pragma warning restore 168
            {
                // pass
            }

            // noop:
            pr.Dispose();
            Assert.AreEqual(0, psub.RefCount);
            dir1.Dispose();
        }
        public virtual void TestIgnoreStoredFields()
        {
            Directory       dir1 = GetDir1(Random());
            Directory       dir2 = GetDir2(Random());
            CompositeReader ir1  = DirectoryReader.Open(dir1);
            CompositeReader ir2  = DirectoryReader.Open(dir2);

            // with overlapping
            ParallelCompositeReader pr = new ParallelCompositeReader(false, new CompositeReader[] { ir1, ir2 }, new CompositeReader[] { ir1 });

            Assert.AreEqual("v1", pr.Document(0).Get("f1"));
            Assert.AreEqual("v1", pr.Document(0).Get("f2"));
            Assert.IsNull(pr.Document(0).Get("f3"));
            Assert.IsNull(pr.Document(0).Get("f4"));
            // check that fields are there
            AtomicReader slow = SlowCompositeReaderWrapper.Wrap(pr);

            Assert.IsNotNull(slow.Terms("f1"));
            Assert.IsNotNull(slow.Terms("f2"));
            Assert.IsNotNull(slow.Terms("f3"));
            Assert.IsNotNull(slow.Terms("f4"));
            pr.Dispose();

            // no stored fields at all
            pr = new ParallelCompositeReader(false, new CompositeReader[] { ir2 }, new CompositeReader[0]);
            Assert.IsNull(pr.Document(0).Get("f1"));
            Assert.IsNull(pr.Document(0).Get("f2"));
            Assert.IsNull(pr.Document(0).Get("f3"));
            Assert.IsNull(pr.Document(0).Get("f4"));
            // check that fields are there
            slow = SlowCompositeReaderWrapper.Wrap(pr);
            Assert.IsNull(slow.Terms("f1"));
            Assert.IsNull(slow.Terms("f2"));
            Assert.IsNotNull(slow.Terms("f3"));
            Assert.IsNotNull(slow.Terms("f4"));
            pr.Dispose();

            // without overlapping
            pr = new ParallelCompositeReader(true, new CompositeReader[] { ir2 }, new CompositeReader[] { ir1 });
            Assert.AreEqual("v1", pr.Document(0).Get("f1"));
            Assert.AreEqual("v1", pr.Document(0).Get("f2"));
            Assert.IsNull(pr.Document(0).Get("f3"));
            Assert.IsNull(pr.Document(0).Get("f4"));
            // check that fields are there
            slow = SlowCompositeReaderWrapper.Wrap(pr);
            Assert.IsNull(slow.Terms("f1"));
            Assert.IsNull(slow.Terms("f2"));
            Assert.IsNotNull(slow.Terms("f3"));
            Assert.IsNotNull(slow.Terms("f4"));
            pr.Dispose();

            // no main readers
            try
            {
                new ParallelCompositeReader(true, new CompositeReader[0], new CompositeReader[] { ir1 });
                Assert.Fail("didn't get expected exception: need a non-empty main-reader array");
            }
            catch (System.ArgumentException iae)
            {
                // pass
            }

            dir1.Dispose();
            dir2.Dispose();
        }