DocumentNumberMapper extends StandardStep<DocumentSplit, DocumentMappingData> { @Override public void process(DocumentSplit index) throws IOException { processor.process(new DocumentMappingData(index.fileId, nextIndexStartNumber)); DiskNameReader namesReader = (DiskNameReader) DiskIndex.openIndexPart(index.fileName + File.separator + "names"); DiskNameReader.KeyIterator iterator = namesReader.getIterator(); long lastDocId = iterator.getCurrentIdentifier(); while (iterator.nextKey()) { lastDocId = iterator.getCurrentIdentifier(); } nextIndexStartNumber += lastDocId + 1; }  @Override void process(DocumentSplit index);  }
@Test public void testDocumentMappingCreator() throws Exception { File index1 = null; File index2 = null; File index3 = null; try { index1 = FileUtility.createTemporaryDirectory(); index2 = FileUtility.createTemporaryDirectory(); index3 = FileUtility.createTemporaryDirectory(); makeNamesIndex(9, index1); makeNamesIndex(9, index2); makeNamesIndex(9, index3); Catcher<DocumentMappingData> catcher = new Catcher<DocumentMappingData>(); DocumentNumberMapper mapper = new DocumentNumberMapper(); mapper.setProcessor( catcher ); mapper.process( DocumentSplitFactory.numberedFile(index1.getAbsolutePath(), 0, 3)); mapper.process( DocumentSplitFactory.numberedFile(index2.getAbsolutePath(), 1, 3)); mapper.process( DocumentSplitFactory.numberedFile(index3.getAbsolutePath(), 2, 3)); mapper.close(); assertEquals(0, catcher.data.get(0).indexId); assertEquals(0, catcher.data.get(0).docNumIncrement); assertEquals(1, catcher.data.get(1).indexId); assertEquals(10, catcher.data.get(1).docNumIncrement); assertEquals(2, catcher.data.get(2).indexId); assertEquals(20, catcher.data.get(2).docNumIncrement); } finally { if (index1 != null) { FSUtil.deleteDirectory(index1); } if (index2 != null) { FSUtil.deleteDirectory(index2); } if (index3 != null) { FSUtil.deleteDirectory(index3); } } }