@Test public void testNullException() throws Exception { RpcException.propagateIfPossible(null, Exception.class); }
@Test public void testNonRemoteException() throws Exception { RpcException e = new RpcException("Test message", new Exception()); RpcException.propagateIfPossible(e, Exception.class); }
private void nextIterator() throws IOException { final ListStatusCommand command = new ListStatusCommand(path, handle, listStatusBatchSize); runner.runCommand(command); RpcFuture<DFS.ListStatusResponse> future = command.getFuture(); try { DFS.ListStatusResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); handle = response.hasHandle() ? response.getHandle() : null; List<DFS.FileStatus> protoStatuses = getListOrEmpty(response.getStatusesList()); currentIterator = protoStatuses.stream().map(s -> { return fromProtoFileStatus(s); }).iterator(); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } }
@Override public boolean rename(Path src, Path dst) throws IOException { Path absoluteSrc = toAbsolutePath(src); Path absoluteDst = toAbsolutePath(dst); checkPath(absoluteSrc); checkPath(absoluteDst); final RenameCommand command = new RenameCommand(absoluteSrc.toUri().getPath(), absoluteDst.toUri().getPath()); runner.runCommand(command); RpcFuture<DFS.RenameResponse> future = command.getFuture(); try { DFS.RenameResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } }
@Override public boolean delete(Path f, boolean recursive) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final DeleteCommand command = new DeleteCommand(absolutePath.toUri().getPath(), recursive); runner.runCommand(command); RpcFuture<DFS.DeleteResponse> future = command.getFuture(); try { DFS.DeleteResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } }
@Override public FileStatus getFileStatus(Path f) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final GetFileStatusCommand command = new GetFileStatusCommand(absolutePath.toUri().getPath()); runner.runCommand(command); RpcFuture<DFS.GetFileStatusResponse> future = command.getFuture(); try { DFS.GetFileStatusResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); return fromProtoFileStatus(response.getStatus()); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } }
@Override public boolean mkdirs(Path f, FsPermission permission) throws IOException { Path absolutePath = toAbsolutePath(f); checkPath(absolutePath); final MkdirsCommand command = new MkdirsCommand( absolutePath.toUri().getPath(), permission != null ? (int) permission.toExtendedShort() : null); runner.runCommand(command); RpcFuture<DFS.MkdirsResponse> future = command.getFuture(); try { DFS.MkdirsResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); return response.getValue(); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } }
private void getData() throws IOException { // Free previous resources in.close(); buf.release(); final GetFileDataCommand command = new GetFileDataCommand(path, pos, buffersize); runner.runCommand(command); RpcFuture<DFS.GetFileDataResponse> future = command.getFuture(); try { DFS.GetFileDataResponse response = future.checkedGet(rpcTimeoutMs, TimeUnit.MILLISECONDS); eof = (response.getRead() == -1); buf = future.getBuffer(); if (buf == null) { buf = EMPTY_BUFFER; } in = new ByteBufInputStream(buf); } catch(TimeoutException e) { throw new IOException("Timeout occured during I/O request for " + uri, e); } catch(RpcException e) { RpcException.propagateIfPossible(e, IOException.class); throw e; } } }
@Test public void testRemoteRuntimeException() throws Exception { UserRemoteException ure = UserRemoteException.create(UserException .unsupportedError(new UserRpcException(null, "user rpc exception", new RuntimeException("test message"))) .build(logger).getOrCreatePBError(false)); exception.expect(RuntimeException.class); exception.expectMessage("test message"); RpcException.propagateIfPossible(new RpcException(ure), TestException.class); } }
@Test public void testRemoteTestException() throws Exception { UserRemoteException ure = UserRemoteException.create(UserException .unsupportedError(new UserRpcException(null, "user rpc exception", new TestException("test message"))) .build(logger).getOrCreatePBError(false)); exception.expect(TestException.class); exception.expectMessage("test message"); RpcException.propagateIfPossible(new RpcException(ure), TestException.class); }