use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class JournalWriterTest method rotateLogOnWriteException.
@Test
public void rotateLogOnWriteException() throws Exception {
// Setup so that we can trigger an IOException when a write is performed on the underlying
// stream.
JournalWriter mockJournalWriter = PowerMockito.mock(JournalWriter.class);
FSDataOutputStream mockOutStream = mock(FSDataOutputStream.class);
UnderFileSystem mockUfs = mock(UnderFileSystem.class);
doReturn(mockOutStream).when(mockUfs).create(eq(mJournal.getCurrentLogFilePath()), any(CreateOptions.class));
EntryOutputStream entryOutStream = new EntryOutputStream(mockUfs, mJournal.getCurrentLogFilePath(), mJournal.getJournalFormatter(), mockJournalWriter);
doThrow(new IOException("write failed")).when(mockOutStream).write(any(byte[].class), anyInt(), anyInt());
try {
entryOutStream.writeEntry(JournalEntry.newBuilder().setSequenceNumber(10).build());
Assert.fail("Should have thrown an exception");
} catch (IOException ignored) {
// expected
}
// Undo the earlier mocking so that the writeEntry doesn't fail.
doNothing().when(mockOutStream).write(any(byte[].class), anyInt(), anyInt());
// The rotation happens the next time an entry is written.
entryOutStream.writeEntry(JournalEntry.newBuilder().build());
verify(mockJournalWriter).completeCurrentLog();
}
use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class DefaultAlluxioMaster method isJournalFormatted.
/**
* Checks to see if the journal directory is formatted.
*
* @param journalDirectory the journal directory to check
* @return true if the journal directory was formatted previously, false otherwise
* @throws IOException if an I/O error occurs
*/
private boolean isJournalFormatted(String journalDirectory) throws IOException {
UnderFileSystem ufs = UnderFileSystem.Factory.get(journalDirectory);
UnderFileStatus[] files = ufs.listStatus(journalDirectory);
if (files == null) {
return false;
}
// Search for the format file.
String formatFilePrefix = Configuration.get(PropertyKey.MASTER_FORMAT_FILE_PREFIX);
for (UnderFileStatus file : files) {
if (file.getName().startsWith(formatFilePrefix)) {
return true;
}
}
return false;
}
use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class CheckConsistencyIntegrationTest method inconsistent.
/**
* Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyOptions)} method
* when no files are consistent.
*/
@Test
public void inconsistent() throws Exception {
String ufsDirectory = mFileSystem.getStatus(DIRECTORY).getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsDirectory);
ufs.deleteDirectory(ufsDirectory, DeleteOptions.defaults().setRecursive(true));
List<AlluxioURI> expected = Lists.newArrayList(FILE, DIRECTORY);
List<AlluxioURI> result = mFileSystemMaster.checkConsistency(new AlluxioURI("/"), CheckConsistencyOptions.defaults());
Collections.sort(expected);
Collections.sort(result);
Assert.assertEquals(expected, result);
}
use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class CheckConsistencyIntegrationTest method notAFile.
/**
* Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyOptions)} method
* when a file does not exist as a file in the under storage.
*/
@Test
public void notAFile() throws Exception {
String ufsFile = mFileSystem.getStatus(FILE).getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsFile);
ufs.deleteFile(ufsFile);
ufs.mkdirs(ufsFile);
List<AlluxioURI> expected = Lists.newArrayList(FILE);
Assert.assertEquals(expected, mFileSystemMaster.checkConsistency(new AlluxioURI("/"), CheckConsistencyOptions.defaults()));
}
use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class CheckConsistencyIntegrationTest method notADirectory.
/**
* Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyOptions)} method
* when a directory does not exist as a directory in the under storage.
*/
@Test
public void notADirectory() throws Exception {
String ufsDirectory = mFileSystem.getStatus(DIRECTORY).getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsDirectory);
ufs.deleteDirectory(ufsDirectory, DeleteOptions.defaults().setRecursive(true));
ufs.create(ufsDirectory).close();
List<AlluxioURI> expected = Lists.newArrayList(DIRECTORY, FILE);
List<AlluxioURI> result = mFileSystemMaster.checkConsistency(new AlluxioURI("/"), CheckConsistencyOptions.defaults());
Collections.sort(expected);
Collections.sort(result);
Assert.assertEquals(expected, result);
}
Aggregations