FileMerger extends FileStitcher<OutputFileMetadata> { @Override protected void mergeOutputFile(OutputFileMetadata outputFileMetadata) throws IOException { LOG.debug("Processing file: {}", outputFileMetadata.getStitchedFileRelativePath()); Path outputFilePath = new Path(filePath, outputFileMetadata.getStitchedFileRelativePath()); if (outputFileMetadata.isDirectory()) { createDir(outputFilePath); successfulFiles.add(outputFileMetadata); return; } if (outputFS.exists(outputFilePath) && !overwriteOnConflict) { LOG.debug("Output file {} already exits and overwrite flag is off. Skipping.", outputFilePath); skippedFiles.add(outputFileMetadata); return; } super.mergeOutputFile(outputFileMetadata); deleteBlockFiles(outputFileMetadata); }  @Override void beginWindow(long windowId); boolean isOverwriteOnConflict(); void setOverwriteOnConflict(boolean overwriteOnConflict);  }
@Test public void testMergeFile() throws IOException { testFM.underTest.mergeOutputFile(testFM.fileMetaDataMock); Assert.assertEquals("File size differes", FILE_DATA.length(), FileUtils.sizeOf(new File(testFM.outputDir, testFM.outputFileName))); }
@Test public void testDirectory() throws IOException { when(testFM.fileMetaDataMock.getFileName()).thenReturn(dummyDir); when(testFM.fileMetaDataMock.getRelativePath()).thenReturn(dummyDir); when(testFM.fileMetaDataMock.getStitchedFileRelativePath()).thenReturn(dummyDir); when(testFM.fileMetaDataMock.isDirectory()).thenReturn(true); when(testFM.fileMetaDataMock.getNumberOfBlocks()).thenReturn(0); when(testFM.fileMetaDataMock.getBlockIds()).thenReturn(new long[] {}); testFM.underTest.mergeOutputFile(testFM.fileMetaDataMock); File statsFile = new File(testFM.outputDir, dummyDir); Assert.assertTrue(statsFile.exists() && statsFile.isDirectory()); }
@Test public void testFileWithRelativePath() throws IOException { FileUtils.write(new File(testFM.outputDir, dummyDir + dummyFile), FILE_DATA); when(testFM.fileMetaDataMock.getFileName()).thenReturn(dummyDir + dummyFile); when(testFM.fileMetaDataMock.getRelativePath()).thenReturn(dummyDir + dummyFile); when(testFM.fileMetaDataMock.getStitchedFileRelativePath()).thenReturn(dummyDir + dummyFile); testFM.underTest.mergeOutputFile(testFM.fileMetaDataMock); File statsFile = new File(testFM.outputDir, dummyDir + dummyFile); Assert.assertTrue(statsFile.exists() && !statsFile.isDirectory()); Assert.assertEquals("File size differes", FILE_DATA.length(), FileUtils.sizeOf(new File(testFM.outputDir, dummyDir + dummyFile))); }