@Test public void confAddress() throws Exception { ClientContext context = Mockito.mock(ClientContext.class); Mockito.when(context.getClusterConf()).thenReturn( new InstancedConfiguration(ConfigurationUtils.defaults())); InetSocketAddress baseAddress = new InetSocketAddress("0.0.0.0", 2000); InetSocketAddress confAddress = new InetSocketAddress("0.0.0.0", 2001); final alluxio.Client client = new BaseTestClient(context) { @Override public synchronized InetSocketAddress getAddress() { return baseAddress; } @Override public synchronized InetSocketAddress getConfAddress() { return confAddress; } }; ArgumentCaptor<InetSocketAddress> argument = ArgumentCaptor.forClass(InetSocketAddress.class); Mockito.doThrow(new RuntimeException("test")) .when(context) .loadConfIfNotLoaded(argument.capture()); Mockito.doReturn(Mockito.mock(BaseUserState.class)) .when(context) .getUserState(); try { client.connect(); Assert.fail(); } catch (Exception e) { } Assert.assertEquals(confAddress, argument.getValue()); }
@Override public synchronized void connect() throws AlluxioStatusException { if (mConnected) { return; } disconnect(); Preconditions.checkState(!mClosed, "Client is closed, will not try to connect."); IOException lastConnectFailure = null; RetryPolicy retryPolicy = mRetryPolicySupplier.get(); while (retryPolicy.attempt()) { if (mClosed) { throw new FailedPreconditionException("Failed to connect: client has been closed"); } try { mAddress = getAddress(); mConfAddress = getConfAddress(); } catch (UnavailableException e) { LOG.debug("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString()); continue; } try { beforeConnect(); LOG.debug("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); mChannel = GrpcChannelBuilder .newBuilder(GrpcServerAddress.create(mAddress), mContext.getClusterConf()) .setSubject(mContext.getSubject()) .setClientType(getServiceName()) .build(); mVersionService = ServiceVersionClientServiceGrpc.newBlockingStub(mChannel); mConnected = true; afterConnect(); checkVersion(getServiceVersion()); LOG.debug("Alluxio client (version {}) is connected with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); return; } catch (IOException e) { LOG.debug("Failed to connect ({}) with {} @ {}: {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e.getMessage()); lastConnectFailure = e; if (e instanceof UnauthenticatedException) { mContext.getUserState().relogin(); } if (e instanceof NotFoundException) { break; } } } if (mChannel != null) { mChannel.shutdown(); } if (mAddress == null) { throw new UnavailableException( String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount())); } if (lastConnectFailure instanceof UnauthenticatedException) { throw (AlluxioStatusException) lastConnectFailure; } if (lastConnectFailure instanceof NotFoundException) { throw new NotFoundException(lastConnectFailure.getMessage(), new ServiceNotFoundException(lastConnectFailure.getMessage(), lastConnectFailure)); } throw new UnavailableException(String.format("Failed to connect to %s @ %s after %s attempts", getServiceName(), mAddress, retryPolicy.getAttemptCount()), lastConnectFailure); }
AbstractClient implements Client { @Override public synchronized void connect() throws AlluxioStatusException { if (mConnected) { return; } disconnect(); Preconditions.checkState(!mClosed, "Client is closed, will not try to connect."); IOException lastConnectFailure = null; RetryPolicy retryPolicy = mRetryPolicySupplier.get(); while (retryPolicy.attempt()) { if (mClosed) { throw new FailedPreconditionException("Failed to connect: client has been closed"); } try { mAddress = getAddress(); mConfAddress = getConfAddress(); } catch (UnavailableException e) { LOG.debug("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString()); continue; } try { beforeConnect(); LOG.debug("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); mChannel = GrpcChannelBuilder .newBuilder(GrpcServerAddress.create(mAddress), mContext.getClusterConf()) .setSubject(mContext.getSubject()) .setClientType(getServiceName()) .build(); mVersionService = ServiceVersionClientServiceGrpc.newBlockingStub(mChannel); mConnected = true; afterConnect(); checkVersion(getServiceVersion()); LOG.debug("Alluxio client (version {}) is connected with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); return; } catch (IOException e) { LOG.debug("Failed to connect ({}) with {} @ {}: {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e.getMessage()); lastConnectFailure = e; if (e instanceof UnauthenticatedException) { mContext.getUserState().relogin(); } if (e instanceof NotFoundException) { break; } } } if (mChannel != null) { mChannel.shutdown(); } if (mAddress == null) { throw new UnavailableException( String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount())); } if (lastConnectFailure instanceof UnauthenticatedException) { throw (AlluxioStatusException) lastConnectFailure; } if (lastConnectFailure instanceof NotFoundException) { throw new NotFoundException(lastConnectFailure.getMessage(), new ServiceNotFoundException(lastConnectFailure.getMessage(), lastConnectFailure)); } throw new UnavailableException(String.format("Failed to connect to %s @ %s after %s attempts", getServiceName(), mAddress, retryPolicy.getAttemptCount()), lastConnectFailure); } }
AbstractClient implements Client { @Override public synchronized void connect() throws AlluxioStatusException { if (mConnected) { return; } disconnect(); Preconditions.checkState(!mClosed, "Client is closed, will not try to connect."); IOException lastConnectFailure = null; RetryPolicy retryPolicy = mRetryPolicySupplier.get(); while (retryPolicy.attempt()) { if (mClosed) { throw new FailedPreconditionException("Failed to connect: client has been closed"); } try { mAddress = getAddress(); mConfAddress = getConfAddress(); } catch (UnavailableException e) { LOG.debug("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString()); continue; } try { beforeConnect(); LOG.debug("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); mChannel = GrpcChannelBuilder .newBuilder(GrpcServerAddress.create(mAddress), mContext.getClusterConf()) .setSubject(mContext.getSubject()) .setClientType(getServiceName()) .build(); mVersionService = ServiceVersionClientServiceGrpc.newBlockingStub(mChannel); mConnected = true; afterConnect(); checkVersion(getServiceVersion()); LOG.debug("Alluxio client (version {}) is connected with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); return; } catch (IOException e) { LOG.debug("Failed to connect ({}) with {} @ {}: {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e.getMessage()); lastConnectFailure = e; if (e instanceof UnauthenticatedException) { mContext.getUserState().relogin(); } if (e instanceof NotFoundException) { break; } } } if (mChannel != null) { mChannel.shutdown(); } if (mAddress == null) { throw new UnavailableException( String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount())); } if (lastConnectFailure instanceof UnauthenticatedException) { throw (AlluxioStatusException) lastConnectFailure; } if (lastConnectFailure instanceof NotFoundException) { throw new NotFoundException(lastConnectFailure.getMessage(), new ServiceNotFoundException(lastConnectFailure.getMessage(), lastConnectFailure)); } throw new UnavailableException(String.format("Failed to connect to %s @ %s after %s attempts", getServiceName(), mAddress, retryPolicy.getAttemptCount()), lastConnectFailure); } AbstractClient(ClientContext context, InetSocketAddress address);  AbstractClient(ClientContext context, InetSocketAddress address,
      Supplier<RetryPolicy> retryPolicySupplier); }
AbstractClient implements Client { @Override public synchronized void connect() throws AlluxioStatusException { if (mConnected) { return; } disconnect(); Preconditions.checkState(!mClosed, "Client is closed, will not try to connect."); IOException lastConnectFailure = null; RetryPolicy retryPolicy = mRetryPolicySupplier.get(); while (retryPolicy.attempt()) { if (mClosed) { throw new FailedPreconditionException("Failed to connect: client has been closed"); } try { mAddress = getAddress(); mConfAddress = getConfAddress(); } catch (UnavailableException e) { LOG.debug("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString()); continue; } try { beforeConnect(); LOG.debug("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); mChannel = GrpcChannelBuilder .newBuilder(GrpcServerAddress.create(mAddress), mContext.getClusterConf()) .setSubject(mContext.getSubject()) .setClientType(getServiceName()) .build(); mVersionService = ServiceVersionClientServiceGrpc.newBlockingStub(mChannel); mConnected = true; afterConnect(); checkVersion(getServiceVersion()); LOG.debug("Alluxio client (version {}) is connected with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); return; } catch (IOException e) { LOG.debug("Failed to connect ({}) with {} @ {}: {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e.getMessage()); lastConnectFailure = e; if (e instanceof UnauthenticatedException) { mContext.getUserState().relogin(); } if (e instanceof NotFoundException) { break; } } } if (mChannel != null) { mChannel.shutdown(); } if (mAddress == null) { throw new UnavailableException( String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount())); } if (lastConnectFailure instanceof UnauthenticatedException) { throw (AlluxioStatusException) lastConnectFailure; } if (lastConnectFailure instanceof NotFoundException) { throw new NotFoundException(lastConnectFailure.getMessage(), new ServiceNotFoundException(lastConnectFailure.getMessage(), lastConnectFailure)); } throw new UnavailableException(String.format("Failed to connect to %s @ %s after %s attempts", getServiceName(), mAddress, retryPolicy.getAttemptCount()), lastConnectFailure); } AbstractClient(ClientContext context, InetSocketAddress address);  AbstractClient(ClientContext context, InetSocketAddress address,
      Supplier<RetryPolicy> retryPolicySupplier); @Override synchronized void connect(); synchronized void disconnect(); synchronized boolean isConnected(); @Override synchronized void close(); @Override synchronized InetSocketAddress getAddress(); @Override synchronized InetSocketAddress getConfAddress(); @Override boolean isClosed(); }
AbstractClient implements Client { @Override public synchronized void connect() throws AlluxioStatusException { if (mConnected) { return; } disconnect(); Preconditions.checkState(!mClosed, "Client is closed, will not try to connect."); IOException lastConnectFailure = null; RetryPolicy retryPolicy = mRetryPolicySupplier.get(); while (retryPolicy.attempt()) { if (mClosed) { throw new FailedPreconditionException("Failed to connect: client has been closed"); } try { mAddress = getAddress(); mConfAddress = getConfAddress(); } catch (UnavailableException e) { LOG.debug("Failed to determine {} rpc address ({}): {}", getServiceName(), retryPolicy.getAttemptCount(), e.toString()); continue; } try { beforeConnect(); LOG.debug("Alluxio client (version {}) is trying to connect with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); mChannel = GrpcChannelBuilder .newBuilder(GrpcServerAddress.create(mAddress), mContext.getClusterConf()) .setSubject(mContext.getSubject()) .setClientType(getServiceName()) .build(); mVersionService = ServiceVersionClientServiceGrpc.newBlockingStub(mChannel); mConnected = true; afterConnect(); checkVersion(getServiceVersion()); LOG.debug("Alluxio client (version {}) is connected with {} @ {}", RuntimeConstants.VERSION, getServiceName(), mAddress); return; } catch (IOException e) { LOG.debug("Failed to connect ({}) with {} @ {}: {}", retryPolicy.getAttemptCount(), getServiceName(), mAddress, e.getMessage()); lastConnectFailure = e; if (e instanceof UnauthenticatedException) { mContext.getUserState().relogin(); } if (e instanceof NotFoundException) { break; } } } if (mChannel != null) { mChannel.shutdown(); } if (mAddress == null) { throw new UnavailableException( String.format("Failed to determine address for %s after %s attempts", getServiceName(), retryPolicy.getAttemptCount())); } if (lastConnectFailure instanceof UnauthenticatedException) { throw (AlluxioStatusException) lastConnectFailure; } if (lastConnectFailure instanceof NotFoundException) { throw new NotFoundException(lastConnectFailure.getMessage(), new ServiceNotFoundException(lastConnectFailure.getMessage(), lastConnectFailure)); } throw new UnavailableException(String.format("Failed to connect to %s @ %s after %s attempts", getServiceName(), mAddress, retryPolicy.getAttemptCount()), lastConnectFailure); } AbstractClient(ClientContext context, InetSocketAddress address);  AbstractClient(ClientContext context, InetSocketAddress address,
      Supplier<RetryPolicy> retryPolicySupplier); @Override synchronized void connect(); synchronized void disconnect(); synchronized boolean isConnected(); @Override synchronized void close(); @Override synchronized InetSocketAddress getAddress(); @Override synchronized InetSocketAddress getConfAddress(); @Override boolean isClosed();  }