Search in sources :

Example 51 with Cluster

use of com.datastax.driver.core.Cluster in project spring-cloud-connectors by spring-cloud.

the class CassandraClusterCreatorTest method shouldCreateCluster.

@Test
public void shouldCreateCluster() throws Exception {
    CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142);
    Cluster cluster = creator.create(info, null);
    Configuration configuration = cluster.getConfiguration();
    assertThat(configuration.getProtocolOptions().getAuthProvider(), is(AuthProvider.NONE));
}
Also used : Configuration(com.datastax.driver.core.Configuration) CassandraServiceInfo(org.springframework.cloud.service.common.CassandraServiceInfo) Cluster(com.datastax.driver.core.Cluster) Test(org.junit.Test)

Example 52 with Cluster

use of com.datastax.driver.core.Cluster in project spring-cloud-connectors by spring-cloud.

the class CassandraClusterCreatorTest method shouldCreateClusterWithAuthentication.

@Test
public void shouldCreateClusterWithAuthentication() throws Exception {
    CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142, "walter", "white");
    Cluster cluster = creator.create(info, null);
    Configuration configuration = cluster.getConfiguration();
    assertThat(configuration.getProtocolOptions().getAuthProvider(), is(instanceOf(PlainTextAuthProvider.class)));
}
Also used : Configuration(com.datastax.driver.core.Configuration) CassandraServiceInfo(org.springframework.cloud.service.common.CassandraServiceInfo) Cluster(com.datastax.driver.core.Cluster) Test(org.junit.Test)

Example 53 with Cluster

use of com.datastax.driver.core.Cluster in project spring-cloud-connectors by spring-cloud.

the class CassandraClusterCreatorTest method shouldCreateClusterWithConfig.

@Test
public void shouldCreateClusterWithConfig() throws Exception {
    CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142);
    CassandraClusterConfig config = new CassandraClusterConfig();
    config.setCompression(ProtocolOptions.Compression.NONE);
    config.setPoolingOptions(new PoolingOptions().setPoolTimeoutMillis(1234));
    config.setQueryOptions(new QueryOptions());
    config.setProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED);
    config.setLoadBalancingPolicy(new RoundRobinPolicy());
    config.setReconnectionPolicy(new ConstantReconnectionPolicy(1));
    config.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
    config.setSocketOptions(new SocketOptions());
    Cluster cluster = creator.create(info, config);
    Configuration configuration = cluster.getConfiguration();
    assertThat(configuration.getProtocolOptions().getCompression(), is(config.getCompression()));
    assertThat(configuration.getQueryOptions(), is(config.getQueryOptions()));
    assertThat(configuration.getSocketOptions(), is(config.getSocketOptions()));
    Policies policies = configuration.getPolicies();
    assertThat(policies.getLoadBalancingPolicy(), is(config.getLoadBalancingPolicy()));
    assertThat(policies.getReconnectionPolicy(), is(config.getReconnectionPolicy()));
    assertThat(policies.getRetryPolicy(), is(config.getRetryPolicy()));
}
Also used : Policies(com.datastax.driver.core.policies.Policies) Configuration(com.datastax.driver.core.Configuration) CassandraServiceInfo(org.springframework.cloud.service.common.CassandraServiceInfo) SocketOptions(com.datastax.driver.core.SocketOptions) PoolingOptions(com.datastax.driver.core.PoolingOptions) Cluster(com.datastax.driver.core.Cluster) QueryOptions(com.datastax.driver.core.QueryOptions) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy) Test(org.junit.Test)

Example 54 with Cluster

use of com.datastax.driver.core.Cluster in project spring-cloud-connectors by spring-cloud.

the class CassandraClusterConfigWithServiceConfig method cloudCassandraConnectionFactoryConfig.

@Test
public void cloudCassandraConnectionFactoryConfig() {
    ApplicationContext testContext = getTestApplicationContext(CassandraClusterConfigWithServiceConfig.class, createService("my-service"));
    Cluster connector = testContext.getBean("my-service", getConnectorType());
    assertThat(connector.getConfiguration().getSocketOptions().getSendBufferSize(), is(12345));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Cluster(com.datastax.driver.core.Cluster) Test(org.junit.Test)

Example 55 with Cluster

use of com.datastax.driver.core.Cluster in project spring-cloud-connectors by spring-cloud.

the class CassandraClusterXmlConfigTest method cassandraSessionWithConfiguration.

@Test
public void cassandraSessionWithConfiguration() throws Exception {
    ApplicationContext testContext = getTestApplicationContext("cloud-cassandra-with-config.xml", createService("my-service"));
    Cluster cluster = testContext.getBean("cassandra-full-config", getConnectorType());
    assertNotNull(cluster.getConfiguration().getSocketOptions());
    assertEquals(15000, cluster.getConfiguration().getSocketOptions().getConnectTimeoutMillis());
    assertTrue(DefaultRetryPolicy.class.isAssignableFrom(cluster.getConfiguration().getPolicies().getRetryPolicy().getClass()));
    assertTrue(RoundRobinPolicy.class.isAssignableFrom(cluster.getConfiguration().getPolicies().getLoadBalancingPolicy().getClass()));
    assertTrue(ConstantReconnectionPolicy.class.isAssignableFrom(cluster.getConfiguration().getPolicies().getReconnectionPolicy().getClass()));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Cluster(com.datastax.driver.core.Cluster) DefaultRetryPolicy(com.datastax.driver.core.policies.DefaultRetryPolicy) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy) Test(org.junit.Test)

Aggregations

Cluster (com.datastax.driver.core.Cluster)123 Session (com.datastax.driver.core.Session)74 ResultSet (com.datastax.driver.core.ResultSet)41 Row (com.datastax.driver.core.Row)37 Test (org.junit.Test)33 ConstantReconnectionPolicy (com.datastax.driver.core.policies.ConstantReconnectionPolicy)30 Host (com.datastax.driver.core.Host)10 Metadata (com.datastax.driver.core.Metadata)9 PreparedStatement (com.datastax.driver.core.PreparedStatement)9 ArrayList (java.util.ArrayList)9 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)8 IOException (java.io.IOException)8 PoolingOptions (com.datastax.driver.core.PoolingOptions)7 ReconnectionPolicy (com.datastax.driver.core.policies.ReconnectionPolicy)7 BeforeClass (org.junit.BeforeClass)7 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)6 QueryOptions (com.datastax.driver.core.QueryOptions)6 InetSocketAddress (java.net.InetSocketAddress)6 BoundStatement (com.datastax.driver.core.BoundStatement)5 SocketOptions (com.datastax.driver.core.SocketOptions)5