List of usage examples for org.apache.hadoop.fs Path toUri
public URI toUri()
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
License:Apache License
public void putFileAtomically_validInput_fileShouldBePutToFilesSystem() throws IOException { File testFile = TUtilsFile.createFileWithRandomContent(); Path hadoopPath = TUtilsPath.getSafeDirectory(fileSystem); URI fileSystemPath = hadoopPath.toUri(); // Test// w w w. ja v a 2s . com hadoopFileSystemArchive.putFileAtomically(testFile, fileSystemPath); // Confirm File retrivedFile = TUtilsFileSystem.getFileFromFileSystem(fileSystem, hadoopPath); TUtilsTestNG.assertFileContentsEqual(testFile, retrivedFile); }
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
License:Apache License
@Test(expectedExceptions = FileNotFoundException.class) public void putFileAtomically_whenLocalFileDoNotExist_fileNotFoundException() throws IOException { File testFile = TUtilsFile.createFilePath(); Path hadoopPath = TUtilsPath.getSafeDirectory(fileSystem); URI fileSystemPath = hadoopPath.toUri(); // Test/*from w w w .ja v a2 s . c o m*/ hadoopFileSystemArchive.putFileAtomically(testFile, fileSystemPath); }
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
License:Apache License
@Test(expectedExceptions = FileOverwriteException.class) public void putFileAtomically_whenRemoteFileExists_fileOverwriteException() throws IOException { File fileThatWouldBeOwerwriten = TUtilsFile.createFileWithRandomContent(); hadoopFileSystemPutter.putFile(fileThatWouldBeOwerwriten); Path hadoopPath = hadoopFileSystemPutter.getPathForFile(fileThatWouldBeOwerwriten); URI pathToRemoteFile = hadoopPath.toUri(); File testFile = TUtilsFile.createFileWithRandomContent(); // Test/* ww w. j a v a 2 s . c o m*/ hadoopFileSystemArchive.putFileAtomically(testFile, pathToRemoteFile); }
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
License:Apache License
public void putFileAtomically_whenRemoteFileExists_remoteFileShouldNotBeOverwriten() throws IOException { File fileThatWouldBeOwerwriten = TUtilsFile.createFileWithRandomContent(); hadoopFileSystemPutter.putFile(fileThatWouldBeOwerwriten); Path hadoopPath = hadoopFileSystemPutter.getPathForFile(fileThatWouldBeOwerwriten); URI pathToRemoteFile = hadoopPath.toUri(); File testFile = TUtilsFile.createFileWithRandomContent(); boolean didGetExeption = false; try {/*from ww w .j ava 2 s. c o m*/ // Test hadoopFileSystemArchive.putFileAtomically(testFile, pathToRemoteFile); } catch (FileOverwriteException e) { didGetExeption = true; } // Make sure there was an exception assertTrue(didGetExeption); // Confirm File fileAfterPut = TUtilsFile.createFilePath(); hadoopFileSystemArchive.getFile(fileAfterPut, pathToRemoteFile); TUtilsTestNG.assertFileContentsEqual("Put shouln't have overwritten the file.", fileThatWouldBeOwerwriten, fileAfterPut); }
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
License:Apache License
public void putFileAtomically_withDirectoryContainingAnotherDirectory_bothDirectoriesExistsInTheArchive() throws URISyntaxException, FileNotFoundException, FileOverwriteException, IOException { File parent = TUtilsFile.createDirectory(); String childFileName = "childDir"; TUtilsFile.createDirectoryInParent(parent, childFileName); Path parentPathOnHadoop = hadoopFileSystemPutter.getPathForFile(parent); hadoopFileSystemArchive.putFileAtomically(parent, parentPathOnHadoop.toUri()); assertTrue(fileSystem.exists(parentPathOnHadoop)); Path childPath = new Path(parentPathOnHadoop, childFileName); assertTrue(fileSystem.exists(childPath)); FileUtils.deleteDirectory(parent);/* w w w.j av a 2 s . c o m*/ }
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
License:Apache License
public void putFileAtomically_withFileAllreadyInTmpFolder_theFilesinTmpFolderDoesNotAffectTheTrasfer() throws FileNotFoundException, FileOverwriteException, IOException { File fileToTransfer = TUtilsFile.createFileWithRandomContent(); File fileToPutOnTempThatShouldNotAffectTheTransfer = TUtilsFile.createFileWithRandomContent(); hadoopFileSystemPutter.putFile(fileToPutOnTempThatShouldNotAffectTheTransfer); Path hadoopPath = TUtilsPath.getSafeDirectory(fileSystem); hadoopPath = new Path(hadoopPath, "fileName"); URI fileSystemPath = hadoopPath.toUri(); // Test//from w w w . ja va 2 s . c om hadoopFileSystemArchive.putFileAtomically(fileToTransfer, fileSystemPath); // Confirm File retrivedFile = TUtilsFileSystem.getFileFromFileSystem(fileSystem, hadoopPath); TUtilsTestNG.assertFileContentsEqual(fileToTransfer, retrivedFile); }
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
License:Apache License
public void putFileToTmpDirectoryAppendingPath_existingFile_fileIsCopiedToTheTmpDirectory() throws IOException { File testFile = TUtilsFile.createFileWithRandomContent(); Path testFilePath = new Path("/just/a/random/path"); Path whereTestFileShouldGo = new Path(tmpPath.toUri().getPath() + testFilePath.toUri().getPath()); // Make sure setup was correct assertFalse(fileSystem.exists(whereTestFileShouldGo)); assertFalse(fileSystem.exists(testFilePath)); // Test/*from w w w .j a va2 s .c o m*/ Path pathWhereTestFilePut = hadoopFileSystemArchive .putFileToTmpDirectoryOverwirtingOldFilesAppendingPath(testFile, testFilePath.toUri()); // Verify assertEquals(whereTestFileShouldGo, pathWhereTestFilePut); assertTrue(fileSystem.exists(whereTestFileShouldGo)); assertFalse(fileSystem.exists(testFilePath)); }
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
License:Apache License
public void move_existingFileOnHadoop_fileIsMoved() throws IOException { File testFile = TUtilsFile.createFileWithRandomContent(); hadoopFileSystemPutter.putFile(testFile); Path testFilePath = hadoopFileSystemPutter.getPathForFile(testFile); Path testFilePathAfterMoving = new Path(tmpPath.toUri().getPath() + testFilePath.toUri().getPath()); // Make sure setup was correct assertTrue(fileSystem.exists(testFilePath)); assertFalse(fileSystem.exists(testFilePathAfterMoving)); // Test//www . jav a 2 s . c o m hadoopFileSystemArchive.move(testFilePath, testFilePathAfterMoving); // Verify assertFalse(fileSystem.exists(testFilePath)); assertTrue(fileSystem.exists(testFilePathAfterMoving)); }
From source file:com.splunk.shuttl.archiver.filesystem.HadoopFileSystemArchiveTest.java
License:Apache License
public void openFile_existingFileOnHadoop_inputStreamToFile() throws FileNotFoundException, IOException { File fileWithRandomContent = createFileWithRandomContent(); List<String> expectedContent = IOUtils.readLines(new FileInputStream(fileWithRandomContent)); hadoopFileSystemPutter.putFile(fileWithRandomContent); Path pathToFile = hadoopFileSystemPutter.getPathForFile(fileWithRandomContent); InputStream openFile = hadoopFileSystemArchive.openFile(pathToFile.toUri()); List<String> actualContent = IOUtils.readLines(openFile); assertEquals(expectedContent, actualContent); }
From source file:com.splunk.shuttl.archiver.util.UtilsPath.java
License:Apache License
/** * When appending the scheme is taking from pathToAppend and only the actual * path is taking from pathThatWillBeAppended * //ww w. ja va 2s. c o m * @param pathThatWillBeAppended * This is the base path the scheme will be taken from this one. * @param pathToAppend * The path string is taken from this argument and appended to the * previous one. * * @return a new Path created by appending 'pathToAppend' to * 'pathThatWillBeAppended' */ public static Path createPathByAppending(Path pathThatWillBeAppended, Path pathToAppend) { return pathThatWillBeAppended.suffix(pathToAppend.toUri().getPath()); }