Search in sources :

Example 61 with Cluster

use of com.datastax.driver.core.Cluster in project zipkin by openzipkin.

the class Schema method getKeyspaceMetadata.

static KeyspaceMetadata getKeyspaceMetadata(Session session) {
    String keyspace = session.getLoggedKeyspace();
    Cluster cluster = session.getCluster();
    KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace);
    if (keyspaceMetadata == null) {
        throw new IllegalStateException(String.format("Cannot read keyspace metadata for give keyspace: %s and cluster: %s", keyspace, cluster.getClusterName()));
    }
    return keyspaceMetadata;
}
Also used : Cluster(com.datastax.driver.core.Cluster) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 62 with Cluster

use of com.datastax.driver.core.Cluster in project spring-boot by spring-projects.

the class CassandraAutoConfigurationTests method customizerOverridesAutoConfig.

@Test
public void customizerOverridesAutoConfig() {
    load(SimpleCustomizerConfig.class, "spring.data.cassandra.cluster-name=testcluster");
    assertThat(this.context.getBeanNamesForType(Cluster.class).length).isEqualTo(1);
    Cluster cluster = this.context.getBean(Cluster.class);
    assertThat(cluster.getClusterName()).isEqualTo("overridden-name");
}
Also used : Cluster(com.datastax.driver.core.Cluster) Test(org.junit.Test)

Example 63 with Cluster

use of com.datastax.driver.core.Cluster in project spring-boot by spring-projects.

the class CassandraTestServer method newCluster.

private Cluster newCluster() {
    Cluster cluster = Cluster.builder().addContactPoint("localhost").build();
    testCluster(cluster);
    return cluster;
}
Also used : Cluster(com.datastax.driver.core.Cluster)

Example 64 with Cluster

use of com.datastax.driver.core.Cluster in project camel by apache.

the class CassandraComponentBeanRefTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    if (canTest()) {
        Cluster cluster = Cluster.builder().addContactPoint("localhost").build();
        registry.bind("cassandraCluster", cluster);
        registry.bind("cassandraSession", cluster.connect("camel_ks"));
        registry.bind("insertCql", CQL);
    }
    return registry;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) Cluster(com.datastax.driver.core.Cluster)

Example 65 with Cluster

use of com.datastax.driver.core.Cluster in project camel by apache.

the class CassandraComponentProducerTest method testRequestUriCql.

@Test
public void testRequestUriCql() throws Exception {
    if (!canTest()) {
        return;
    }
    Object response = producerTemplate.requestBody(Arrays.asList("w_jiang", "Willem", "Jiang"));
    Cluster cluster = CassandraUnitUtils.cassandraCluster();
    Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
    ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "w_jiang");
    Row row = resultSet.one();
    assertNotNull(row);
    assertEquals("Willem", row.getString("first_name"));
    assertEquals("Jiang", row.getString("last_name"));
    session.close();
    cluster.close();
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) 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