/** * Tests for the {@link BaseFileSystem#listStatus(AlluxioURI, ListStatusPOptions)} method. */ @Test public void listStatus() throws Exception { AlluxioURI file = new AlluxioURI("/file"); List<URIStatus> infos = new ArrayList<>(); infos.add(new URIStatus(new FileInfo())); ListStatusPOptions listStatusOptions = ListStatusPOptions.getDefaultInstance(); when(mFileSystemMasterClient.listStatus(file, listStatusOptions)).thenReturn(infos); assertSame(infos, mFileSystem.listStatus(file, listStatusOptions)); verify(mFileSystemMasterClient).listStatus(file, listStatusOptions); verifyFilesystemContextAcquiredAndReleased(); }
@Override public List<URIStatus> listStatus(AlluxioURI path, ListStatusPOptions options) throws FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); // TODO(calvin): Fix the exception handling in the master try { return masterClient.listStatus(path, options); } catch (NotFoundException e) { throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path)); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
/** * Ensures that an exception is propagated correctly when listing the status. */ @Test public void listStatusException() throws Exception { AlluxioURI file = new AlluxioURI("/file"); when(mFileSystemMasterClient.listStatus(file, ListStatusPOptions.getDefaultInstance())) .thenThrow(EXCEPTION); try { mFileSystem.listStatus(file, ListStatusPOptions.getDefaultInstance()); fail(SHOULD_HAVE_PROPAGATED_MESSAGE); } catch (Exception e) { assertSame(EXCEPTION, e); } verifyFilesystemContextAcquiredAndReleased(); }
@Override public List<URIStatus> listStatus(AlluxioURI path, ListStatusOptions options) throws FileDoesNotExistException, IOException, AlluxioException { FileSystemMasterClient masterClient = mContext.acquireMasterClient(); // TODO(calvin): Fix the exception handling in the master try { return masterClient.listStatus(path); } catch (FileDoesNotExistException e) { throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path)); } finally { mContext.releaseMasterClient(masterClient); } }