public SocketChannel getClientChannel(final boolean noTearDown) throws IOException { final List<String> listeners = m_config.getListenerAddresses(); final Random r = new Random(); final String listener = listeners.get(r.nextInt(listeners.size())); byte[] hashedPassword = ConnectionUtil.getHashedPassword(m_password); HostAndPort hNp = HostAndPort.fromString(listener); int port = Constants.DEFAULT_PORT; if (hNp.hasPort()) { port = hNp.getPort(); } final SocketChannel channel = (SocketChannel) ConnectionUtil.getAuthenticatedConnection( hNp.getHostText(), m_username, hashedPassword, port, null, ClientAuthHashScheme.getByUnencodedLength(hashedPassword.length))[0]; channel.configureBlocking(true); if (!noTearDown) { synchronized (m_clientChannels) { m_clientChannels.add(channel); } } return channel; }
public Client getFullyConnectedClient(long timeout) throws IOException { final List<String> listeners = m_config.getListenerAddresses(); final Random r = new Random(); ClientConfig config = new ClientConfigForTest(m_username, m_password); config.setConnectionResponseTimeout(timeout); config.setProcedureCallTimeout(timeout); final Client client = ClientFactory.createClient(config); for (String listener : listeners) { // Use the port generated by LocalCluster if applicable try { client.createConnection(listener); } // retry once catch (ConnectException e) { listener = listeners.get(r.nextInt(listeners.size())); client.createConnection(listener); } } m_clients.add(client); return client; }