.withPoolingOptions(new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, m_clusterConfiguration.getConnectionsLocalCore(), m_clusterConfiguration.getConnectionsLocalMax()) .setConnectionsPerHost(HostDistance.REMOTE,
final PoolingOptions poolingOptions = new PoolingOptions() .setCoreConnectionsPerHost(HostDistance.LOCAL, cassandraConfig.getConnections()) .setMaxConnectionsPerHost(HostDistance.LOCAL, cassandraConfig.getConnections())
cluster.withQueryOptions(options); PoolingOptions poolOps = new PoolingOptions(); poolOps.setMaxQueueSize(cassandraConf.getPoolMaxQueueSize()); poolOps.setHeartbeatIntervalSeconds(cassandraConf.getHeartbeatIntervalSeconds());
PoolingOptions options = new PoolingOptions();
@Override public Cluster.Builder createClusterBuilder() { executor = spy( new ThreadPoolExecutor( 1, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>())); PoolingOptions poolingOptions = new PoolingOptions(); poolingOptions.setInitializationExecutor(executor); return Cluster.builder().withPoolingOptions(poolingOptions); }
@Test(groups = "unit") public void should_leave_connection_options_unset_until_protocol_version_known() { PoolingOptions options = new PoolingOptions(); assertThat(options.getCoreConnectionsPerHost(LOCAL)).isEqualTo(PoolingOptions.UNSET); assertThat(options.getCoreConnectionsPerHost(REMOTE)).isEqualTo(PoolingOptions.UNSET); assertThat(options.getMaxConnectionsPerHost(LOCAL)).isEqualTo(PoolingOptions.UNSET); assertThat(options.getMaxConnectionsPerHost(REMOTE)).isEqualTo(PoolingOptions.UNSET); assertThat(options.getNewConnectionThreshold(LOCAL)).isEqualTo(PoolingOptions.UNSET); assertThat(options.getNewConnectionThreshold(REMOTE)).isEqualTo(PoolingOptions.UNSET); assertThat(options.getMaxRequestsPerConnection(LOCAL)).isEqualTo(PoolingOptions.UNSET); assertThat(options.getMaxRequestsPerConnection(REMOTE)).isEqualTo(PoolingOptions.UNSET); }
@Test(groups = "unit") public void should_set_core_and_max_connections_simultaneously() { PoolingOptions options = new PoolingOptions(); options.setProtocolVersion(ProtocolVersion.V2); options.setConnectionsPerHost(LOCAL, 10, 15); assertThat(options.getCoreConnectionsPerHost(LOCAL)).isEqualTo(10); assertThat(options.getMaxConnectionsPerHost(LOCAL)).isEqualTo(15); }
@Test(groups = "unit") public void should_initialize_to_v2_defaults_if_v2_or_below() { PoolingOptions options = new PoolingOptions(); options.setProtocolVersion(ProtocolVersion.V1); assertThat(options.getCoreConnectionsPerHost(LOCAL)).isEqualTo(2); assertThat(options.getMaxConnectionsPerHost(LOCAL)).isEqualTo(8); assertThat(options.getCoreConnectionsPerHost(REMOTE)).isEqualTo(1); assertThat(options.getMaxConnectionsPerHost(REMOTE)).isEqualTo(2); assertThat(options.getNewConnectionThreshold(LOCAL)).isEqualTo(100); assertThat(options.getNewConnectionThreshold(REMOTE)).isEqualTo(100); assertThat(options.getMaxRequestsPerConnection(LOCAL)).isEqualTo(128); assertThat(options.getMaxRequestsPerConnection(REMOTE)).isEqualTo(128); }
@Test(groups = "unit") public void should_initialize_to_v3_defaults_if_v3_or_above() { PoolingOptions options = new PoolingOptions(); options.setProtocolVersion(ProtocolVersion.V3); assertThat(options.getCoreConnectionsPerHost(LOCAL)).isEqualTo(1); assertThat(options.getMaxConnectionsPerHost(LOCAL)).isEqualTo(1); assertThat(options.getCoreConnectionsPerHost(REMOTE)).isEqualTo(1); assertThat(options.getMaxConnectionsPerHost(REMOTE)).isEqualTo(1); assertThat(options.getNewConnectionThreshold(LOCAL)).isEqualTo(800); assertThat(options.getNewConnectionThreshold(REMOTE)).isEqualTo(200); assertThat(options.getMaxRequestsPerConnection(LOCAL)).isEqualTo(1024); assertThat(options.getMaxRequestsPerConnection(REMOTE)).isEqualTo(256); }
/** * Builds the final object from this builder. * * <p>Any field that hasn't been set explicitly will get its default value. * * @return the object. */ public Configuration build() { return new Configuration( policies != null ? policies : Policies.builder().build(), protocolOptions != null ? protocolOptions : new ProtocolOptions(), poolingOptions != null ? poolingOptions : new PoolingOptions(), socketOptions != null ? socketOptions : new SocketOptions(), metricsOptions != null ? metricsOptions : new MetricsOptions(), queryOptions != null ? queryOptions : new QueryOptions(), threadingOptions != null ? threadingOptions : new ThreadingOptions(), nettyOptions != null ? nettyOptions : NettyOptions.DEFAULT_INSTANCE, codecRegistry != null ? codecRegistry : CodecRegistry.DEFAULT_INSTANCE); } }
@Test(groups = "unit") public void should_enforce_invariants_once_protocol_version_known() { // OK for v2 (default max = 8) PoolingOptions options = new PoolingOptions().setCoreConnectionsPerHost(LOCAL, 3); options.setCoreConnectionsPerHost(LOCAL, 3); options.setProtocolVersion(ProtocolVersion.V2); assertThat(options.getCoreConnectionsPerHost(LOCAL)).isEqualTo(3); assertThat(options.getMaxConnectionsPerHost(LOCAL)).isEqualTo(8); // KO for v3 (default max = 1) options = new PoolingOptions().setCoreConnectionsPerHost(LOCAL, 3); try { options.setProtocolVersion(ProtocolVersion.V3); fail("Expected an IllegalArgumentException"); } catch (IllegalArgumentException e) { /*expected*/ } // OK for v3 (up to 32K stream ids) options = new PoolingOptions().setMaxRequestsPerConnection(LOCAL, 5000); options.setProtocolVersion(ProtocolVersion.V3); assertThat(options.getMaxRequestsPerConnection(LOCAL)).isEqualTo(5000); // KO for v2 (up to 128) options = new PoolingOptions().setMaxRequestsPerConnection(LOCAL, 5000); try { options.setProtocolVersion(ProtocolVersion.V2); fail("Expected an IllegalArgumentException"); } catch (IllegalArgumentException e) { /*expected*/ } }
private void copyPoolingOptions(Builder builder) { PoolingOptions opts = new PoolingOptions(); opts.setCoreConnectionsPerHost(HostDistance.REMOTE, remoteCoreConnectionsPerHost); opts.setCoreConnectionsPerHost(HostDistance.LOCAL, localCoreConnectionsPerHost); opts.setMaxConnectionsPerHost(HostDistance.REMOTE, remoteMaxConnectionsPerHost); opts.setMaxConnectionsPerHost(HostDistance.LOCAL, localMaxConnectionsPerHost); opts.setMaxSimultaneousRequestsPerConnectionThreshold( HostDistance.REMOTE, remoteMaxSimultaneousRequestsPerConnectionThreshold); opts.setMaxSimultaneousRequestsPerConnectionThreshold( HostDistance.LOCAL, localMaxSimultaneousRequestsPerConnectionThreshold); opts.setMinSimultaneousRequestsPerConnectionThreshold( HostDistance.REMOTE, remoteMinSimultaneousRequestsPerConnectionThreshold); opts.setMinSimultaneousRequestsPerConnectionThreshold( HostDistance.LOCAL, localMinSimultaneousRequestsPerConnectionThreshold); builder.withPoolingOptions(opts); }
protected Cluster.Builder createClusterBuilder() { return Cluster.builder() .withPort(scassandra.getBinaryPort()) .addContactPoints(hostAddress.getAddress()) .withPort(scassandra.getBinaryPort()) .withPoolingOptions( new PoolingOptions() .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) .setHeartbeatIntervalSeconds(0)); }
@Override public Cluster.Builder createClusterBuilder() { channelMonitor = register(new SocketChannelMonitor()); PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, 8, 8); return Cluster.builder() .withPoolingOptions(poolingOptions) .withNettyOptions(channelMonitor.nettyOptions()) .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)); }
.addContactPoints(hostAddress.getAddress()) .withPort(scassandra.getBinaryPort()) .withPoolingOptions(new PoolingOptions().setHeartbeatIntervalSeconds(0)) .build();
CreateClusterAndCheckConnections(CountDownLatch startSignal) { this.startSignal = startSignal; this.cluster = Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withPoolingOptions( new PoolingOptions().setCoreConnectionsPerHost(HostDistance.LOCAL, 1)) .withNettyOptions(channelMonitor.nettyOptions()) .build(); }
/** * Ensures that authentication is possible even if the server is busy during SASL handshake. * * @jira_ticket JAVA-1429 */ @Test(groups = "short") @CCMConfig(dirtiesContext = true) public void should_connect_with_slow_server() { Cluster cluster = Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withAuthProvider(new SlowAuthProvider()) .withPoolingOptions(new PoolingOptions().setHeartbeatIntervalSeconds(1)) .build(); cluster.connect(); }
private void createCluster(int core, int max) { PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(LOCAL, core, max); SocketOptions socketOptions = new SocketOptions().setReadTimeoutMillis(1000); cluster = Cluster.builder() .addContactPoints(scassandra.address(1).getAddress()) .withPort(scassandra.getBinaryPort()) .withQueryOptions(nonDebouncingQueryOptions()) .withPoolingOptions(poolingOptions) .withSocketOptions(socketOptions) .withReconnectionPolicy(new ConstantReconnectionPolicy(1000)) .build(); cluster.connect(); }
@Test(groups = "unit") public void should_reject_negative_connection_options_even_when_protocol_version_unknown() { PoolingOptions options = new PoolingOptions();
@BeforeMethod(groups = "short") public void beforeMethod() { scassandras = ScassandraCluster.builder().withNodes(3).build(); scassandras.init(); cluster = Cluster.builder() .addContactPoints(scassandras.address(1).getAddress()) .withPort(scassandras.getBinaryPort()) .withRetryPolicy(retryPolicy) .withLoadBalancingPolicy(new SortingLoadBalancingPolicy()) .withPoolingOptions( new PoolingOptions() .setCoreConnectionsPerHost(HostDistance.LOCAL, 1) .setMaxConnectionsPerHost(HostDistance.LOCAL, 1) .setHeartbeatIntervalSeconds(0)) .withNettyOptions(nonQuietClusterCloseOptions) // Mark everything as idempotent by default so RetryPolicy is exercised. .withQueryOptions(new QueryOptions().setDefaultIdempotence(true)) .build(); session = cluster.connect(); host1 = TestUtils.findHost(cluster, 1); host2 = TestUtils.findHost(cluster, 2); host3 = TestUtils.findHost(cluster, 3); errors = cluster.getMetrics().getErrorMetrics(); Mockito.reset(retryPolicy); for (Scassandra node : scassandras.nodes()) { node.activityClient().clearAllRecordedActivity(); } }