public void testIgnoreStoredFields() throws IOException { Directory dir1 = getDir1(random()); Directory dir2 = getDir2(random()); LeafReader ir1 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir1)); LeafReader ir2 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir2)); // with overlapping ParallelLeafReader pr = new ParallelLeafReader(false, new LeafReader[] {ir1, ir2}, new LeafReader[] {ir1}); assertEquals("v1", pr.document(0).get("f1")); assertEquals("v1", pr.document(0).get("f2")); assertNull(pr.document(0).get("f3")); assertNull(pr.document(0).get("f4")); // check that fields are there assertNotNull(pr.terms("f1")); assertNotNull(pr.terms("f2")); assertNotNull(pr.terms("f3")); assertNotNull(pr.terms("f4")); pr.close(); // no stored fields at all pr = new ParallelLeafReader(false, new LeafReader[] {ir2}, new LeafReader[0]); assertNull(pr.document(0).get("f1")); assertNull(pr.document(0).get("f2")); assertNull(pr.document(0).get("f3")); assertNull(pr.document(0).get("f4")); // check that fields are there assertNull(pr.terms("f1")); assertNull(pr.terms("f2")); assertNotNull(pr.terms("f3")); assertNotNull(pr.terms("f4")); pr.close(); // without overlapping pr = new ParallelLeafReader(true, new LeafReader[] {ir2}, new LeafReader[] {ir1}); assertEquals("v1", pr.document(0).get("f1")); assertEquals("v1", pr.document(0).get("f2")); assertNull(pr.document(0).get("f3")); assertNull(pr.document(0).get("f4")); // check that fields are there assertNull(pr.terms("f1")); assertNull(pr.terms("f2")); assertNotNull(pr.terms("f3")); assertNotNull(pr.terms("f4")); pr.close(); // no main readers try { new ParallelLeafReader(true, new LeafReader[0], new LeafReader[] {ir1}); fail("didn't get expected exception: need a non-empty main-reader array"); } catch (IllegalArgumentException iae) { // pass } dir1.close(); dir2.close(); }
public void testCloseInnerReader() throws Exception { Directory dir1 = getDir1(random()); LeafReader ir1 = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(dir1)); // with overlapping ParallelLeafReader pr = new ParallelLeafReader(true, new LeafReader[] {ir1}, new LeafReader[] {ir1}); ir1.close(); try { pr.document(0); fail("ParallelLeafReader should be already closed because inner reader was closed!"); } catch (AlreadyClosedException e) { // pass } // noop: pr.close(); dir1.close(); }