@Override public Cluster get() { String host = configuration.getHostAddress(); int port = configuration.getPort(); LOGGER.info("Connecting to cassandra cluster with host:{}, port:{}", host, port); Cluster cluster = Cluster.builder() .addContactPoint(host) .withPort(port) .build(); Metadata metadata = cluster.getMetadata(); LOGGER.info("Connected to cluster: {}", metadata.getClusterName()); metadata.getAllHosts().forEach(h -> { LOGGER.info("Datacenter:{}, host:{}, rack: {}", h.getDatacenter(), h.getAddress(), h.getRack()); }); return cluster; } }
.addContactPoints(cstr.contactPoints()) .withPort(cstr.port()); Cluster cluster = builder.build();
@Override protected void load() { String hostIp = EmbeddedCassandraServerHelper.getHost(); int port = EmbeddedCassandraServerHelper.getNativeTransportPort(); cluster = new Cluster.Builder().addContactPoints(hostIp).withPort(port).withSocketOptions(getSocketOptions()) .build(); session = cluster.connect(); CQLDataLoader dataLoader = new CQLDataLoader(session); dataLoader.load(dataSet); session = dataLoader.getSession(); }
protected void resetTestSession() throws Exception { session.close(); Cluster.Builder builder = ccmTestConfig.clusterProvider(this); // add contact points only if the provided builder didn't do so if (builder.getContactPoints().isEmpty()) builder.addContactPoints(getContactPoints()); builder.withPort(ccm.getBinaryPort()); cluster = register(builder.build()); cluster.init(); session.close(); session = register(cluster.connect()); useKeyspace(session, keyspace); }
protected void initTestCluster(Object testInstance) throws Exception { if (ccmTestConfig.createCcm() && ccmTestConfig.createCluster()) { Cluster.Builder builder = ccmTestConfig.clusterProvider(testInstance); // add contact points only if the provided builder didn't do so if (builder.getContactPoints().isEmpty()) builder.addContactPoints(getContactPoints()); builder.withPort(ccm.getBinaryPort()); cluster = register(builder.build()); cluster.init(); } }
private void startUp() { int port = 9042; String[] seeds; if (configuration.containsKey(CONTACT_POINTS)) { seeds = configuration.get(CONTACT_POINTS).split(","); } else { seeds = new String[] {LOCALHOST}; } Cluster cluster = new Cluster.Builder() .addContactPoints(seeds) .withPort(port) .build(); String keySpace = configuration.get(KEY_SPACE); if (keySpace == null || keySpace.isEmpty()) { keySpace=DEFAULT_KEYSPACE; } session = Optional.of(cluster.connect(keySpace)); dataAccess = new DataAccess(session.get()); }
public void useNamedValuesWithProtocol(ProtocolVersion version) { Cluster vCluster = createClusterBuilder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withProtocolVersion(version) .build(); try { Session vSession = vCluster.connect(this.keyspace); // Given - A simple statement with named parameters. SimpleStatement statement = new SimpleStatement( "SELECT * FROM users WHERE id = :id", ImmutableMap.<String, Object>of("id", 1)); // When - Executing that statement against a Cluster instance using Protocol Version V2. vSession.execute(statement).one(); // Then - Should throw an UnsupportedFeatureException } finally { vCluster.close(); } }
Cluster cluster = builder() .addContactPoints(sCluster.address(1, 1).getAddress()) .withPort(sCluster.getBinaryPort()) .withLoadBalancingPolicy( DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()) .build(); try { sCluster.init();
Cluster cluster = builder() .addContactPoints(sCluster.address(1, 1).getAddress()) .withPort(sCluster.getBinaryPort()) .withLoadBalancingPolicy(policy) .build();
cluster = Cluster.builder().withCredentials(username, password) .withPort(Integer.valueOf(port)).addContactPoints(hosts).build(); } else { cluster = Cluster.builder().withPort(Integer.valueOf(port)) .addContactPoints(hosts).build();
@Override protected void before() throws Throwable { dependency.before(); Cluster cluster = Cluster.builder().addContactPoint(getHost()).withPort(getPort()) .withNettyOptions(new NettyOptions() { @Override public void onClusterClose(EventLoopGroup eventLoopGroup) { eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly(); } }).build(); Session session = cluster.newSession(); try { if (requiredVersion != null) { Version cassandraReleaseVersion = CassandraVersion.getReleaseVersion(session); if (cassandraReleaseVersion.isLessThan(requiredVersion)) { throw new AssumptionViolatedException( String.format("Cassandra at %s:%s runs in Version %s but we require at least %s", getHost(), getPort(), cassandraReleaseVersion, requiredVersion)); } } session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s \n" + "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", keyspaceName)); } finally { session.close(); cluster.close(); } }
requireNonNull(extraColumnMetadataCodec, "extraColumnMetadataCodec is null"); Cluster.Builder clusterBuilder = Cluster.builder() .withProtocolVersion(config.getProtocolVersion()); clusterBuilder.withPort(config.getNativeProtocolPort()); clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000)); clusterBuilder.withRetryPolicy(config.getRetryPolicy().getPolicy()); new ReopeningCluster(() -> { contactPoints.forEach(clusterBuilder::addContactPoint); return clusterBuilder.build(); }), config.getNoHostAvailableRetryTimeout());
private ResultSet performQuery(CassandraContainer cassandraContainer, String cql) { Cluster explicitCluster = Cluster.builder() .addContactPoint(cassandraContainer.getContainerIpAddress()) .withPort(cassandraContainer.getMappedPort(CassandraContainer.CQL_PORT)) .build(); return performQuery(explicitCluster, cql); }
return ses; Cluster.Builder builder = Cluster.builder(); builder = builder.withPort(port); builder = builder.addContactPoints(contactPoints);
CassandraConf cassandraConf = new CassandraConf(topoConf); Cluster.Builder cluster = Cluster.builder() .withoutJMXReporting() .withoutMetrics() .addContactPoints(cassandraConf.getNodes()) .withPort(cassandraConf.getPort()) .withRetryPolicy(cassandraConf.getRetryPolicy()) .withReconnectionPolicy(new ExponentialReconnectionPolicy( cluster.withPoolingOptions(poolOps); return cluster.build();
/** * Validates that when a Cluster is initialized that {@link * SpeculativeExecutionPolicy#init(Cluster)} is called and that when a Cluster is closed {@link * SpeculativeExecutionPolicy#close()} is called. * * @test_category queries:speculative_execution * @expected_result init and close are called on cluster init and close. * @jira_ticket JAVA-796 * @since 2.0.11, 2.1.7, 2.2.1 */ @Test(groups = "short") public void should_init_and_close_policy_on_cluster() { SpeculativeExecutionPolicy mockPolicy = mock(SpeculativeExecutionPolicy.class); Cluster cluster = Cluster.builder() .addContactPoints(scassandras.address(2).getAddress()) .withPort(scassandras.getBinaryPort()) .withSpeculativeExecutionPolicy(mockPolicy) .build(); verify(mockPolicy, times(0)).init(cluster); verify(mockPolicy, times(0)).close(); try { cluster.init(); verify(mockPolicy, times(1)).init(cluster); } finally { cluster.close(); verify(mockPolicy, times(1)).close(); } }
Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withCodecRegistry(codecRegistry) .build()); Session session = cluster.connect(keyspace); setUpTupleTypes(cluster);