public Client getClient(long timeout, ClientAuthHashScheme scheme, boolean useAdmin) throws IOException { final Random r = new Random(); String listener = null; if (useAdmin) { listener = m_config.getAdminAddress(r.nextInt(m_config.getListenerCount())); } else { listener = m_config.getListenerAddress(r.nextInt(m_config.getListenerCount())); } ClientConfig config = new ClientConfigForTest(m_username, m_password, scheme); config.setConnectionResponseTimeout(timeout); config.setProcedureCallTimeout(timeout); final Client client = ClientFactory.createClient(config); // Use the port generated by LocalCluster if applicable try { client.createConnection(listener); } // retry once catch (ConnectException e) { if (useAdmin) { listener = m_config.getAdminAddress(r.nextInt(m_config.getListenerCount())); } else { listener = m_config.getListenerAddress(r.nextInt(m_config.getListenerCount())); } client.createConnection(listener); } m_clients.add(client); return client; }
/** * Get a VoltClient instance connected to a specific server driven by the VoltServerConfig * instance. Find the server by the config's HostId. * * @return A VoltClient instance connected to the server driven by the VoltServerConfig instance. */ public Client getClientToHostId(int hostId, long timeout) throws IOException { final String listener = m_config.getListenerAddress(hostId); ClientConfig config = new ClientConfigForTest(m_username, m_password); config.setConnectionResponseTimeout(timeout); config.setProcedureCallTimeout(timeout); final Client client = ClientFactory.createClient(config); try { client.createConnection(listener); } // retry once catch (ConnectException e) { client.createConnection(listener); } m_clients.add(client); return client; }