LuceneSegmentInputSplit extends InputSplit implements Writable { public SegmentCommitInfo getSegment(Configuration configuration) throws IOException { ReadOnlyFileSystemDirectory directory = new ReadOnlyFileSystemDirectory(FileSystem.get(configuration), indexPath, false, configuration); SegmentInfos segmentInfos = new SegmentInfos(); segmentInfos.read(directory); for (SegmentCommitInfo segmentInfo : segmentInfos) { if (segmentInfo.info.name.equals(segmentInfoName)) { return segmentInfo; } } throw new IllegalArgumentException("No such segment: '" + segmentInfoName + "' in directory " + directory.toString()); } LuceneSegmentInputSplit();  LuceneSegmentInputSplit(Path indexPath, String segmentInfoName, long length); @Override long getLength(); @Override String[] getLocations(); String getSegmentInfoName(); Path getIndexPath(); @Override void write(DataOutput out); @Override void readFields(DataInput in); SegmentCommitInfo getSegment(Configuration configuration);  }
@Test public void testGetSegment() throws Exception { SingleFieldDocument doc1 = new SingleFieldDocument("1", "This is simple document 1"); SingleFieldDocument doc2 = new SingleFieldDocument("2", "This is simple document 2"); SingleFieldDocument doc3 = new SingleFieldDocument("3", "This is simple document 3"); List<SingleFieldDocument> docs = asList(doc1, doc2, doc3); for (SingleFieldDocument doc : docs) { commitDocuments(getDirectory(getIndexPath1AsFile()), doc); } assertSegmentContainsOneDoc("_0"); assertSegmentContainsOneDoc("_1"); assertSegmentContainsOneDoc("_2"); }
@Test(expected = IllegalArgumentException.class) public void testGetSegmentNonExistingSegment() throws Exception { SingleFieldDocument doc1 = new SingleFieldDocument("1", "This is simple document 1"); SingleFieldDocument doc2 = new SingleFieldDocument("2", "This is simple document 2"); SingleFieldDocument doc3 = new SingleFieldDocument("3", "This is simple document 3"); List<SingleFieldDocument> docs = asList(doc1, doc2, doc3); for (SingleFieldDocument doc : docs) { commitDocuments(getDirectory(getIndexPath1AsFile()), doc); } LuceneSegmentInputSplit inputSplit = new LuceneSegmentInputSplit(indexPath1, "_3", 1000); inputSplit.getSegment(configuration); }