/** * Connect to a cassandra cluster at a given host/port */ public void connect() { try { lock.lock(); } catch (IOException e) { throw new IllegalStateException("There appears to be another health check running", e); } final List<InetSocketAddress> whiteList= new ArrayList<>(); whiteList.add(new InetSocketAddress(host, port)); final LoadBalancingPolicy loadBalancingPolicy = new WhiteListPolicy(new RoundRobinPolicy(), whiteList); final Cluster.Builder cb = Cluster.builder() .addContactPoint(host) .withPort(port) .withLoadBalancingPolicy(loadBalancingPolicy) .withRetryPolicy(retryPolicy); if (username != null) { cb.withCredentials(username, password); } cluster = cb.build(); session = cluster.connect(); hosts = cluster.getMetadata().getAllHosts(); }
public JavaDriverClient(StressSettings settings, String host, int port, EncryptionOptions.ClientEncryptionOptions encryptionOptions) { this.host = host; this.port = port; this.username = settings.mode.username; this.password = settings.mode.password; this.authProvider = settings.mode.authProvider; this.encryptionOptions = encryptionOptions; if (settings.node.isWhiteList) whitelist = new WhiteListPolicy(new DCAwareRoundRobinPolicy(), settings.node.resolveAll(settings.port.nativePort)); else whitelist = null; }
public JavaDriverClient(StressSettings settings, String host, int port, EncryptionOptions.ClientEncryptionOptions encryptionOptions) { this.protocolVersion = settings.mode.protocolVersion; this.host = host; this.port = port; this.username = settings.mode.username; this.password = settings.mode.password; this.authProvider = settings.mode.authProvider; this.encryptionOptions = encryptionOptions; if (settings.node.isWhiteList) whitelist = new WhiteListPolicy(DCAwareRoundRobinPolicy.builder().build(), settings.node.resolveAll(settings.port.nativePort)); else whitelist = null; connectionsPerHost = settings.mode.connectionsPerHost == null ? 8 : settings.mode.connectionsPerHost; int maxThreadCount = 0; if (settings.rate.auto) maxThreadCount = settings.rate.maxThreads; else maxThreadCount = settings.rate.threadCount; //Always allow enough pending requests so every thread can have a request pending //See https://issues.apache.org/jira/browse/CASSANDRA-7217 int requestsPerConnection = (maxThreadCount / connectionsPerHost) + connectionsPerHost; maxPendingPerConnection = settings.mode.maxPendingPerConnection == null ? Math.max(128, requestsPerConnection ) : settings.mode.maxPendingPerConnection; }
@Test public void buildsPolicy() throws Exception { final WhiteListPolicyFactory factory = new WhiteListPolicyFactory(); factory.setSubPolicy(subPolicyFactory); factory.setWhiteList(Collections.singletonList(new InetSocketAddress("localhost", 9876))); final WhiteListPolicy policy = (WhiteListPolicy) factory.build(); assertThat(policy.getChildPolicy()).isSameAs(subPolicy); }
public JavaDriverClient(StressSettings settings, String host, int port, EncryptionOptions.ClientEncryptionOptions encryptionOptions) { this.host = host; this.port = port; this.encryptionOptions = encryptionOptions; if (settings.node.isWhiteList) whitelist = new WhiteListPolicy(new DCAwareRoundRobinPolicy(), settings.node.resolveAll(settings.port.nativePort)); else whitelist = null; }
@Override public LoadBalancingPolicy build() { return new WhiteListPolicy(subPolicy.build(), whiteList); }