Search in sources :

Example 21 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 22 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 23 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 24 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)

Example 25 with Cluster

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

the class CassandraComponentProducerTest method testEndpointNoCqlParameter.

/**
     * Simulate different CQL statements in the incoming message containing a header with RegularStatement, justifying the cassandracql endpoint not containing a "cql" Uri parameter
     */
@Test
public void testEndpointNoCqlParameter() throws Exception {
    if (!canTest()) {
        return;
    }
    Update.Where updateFirstName = update("camel_user").with(set("first_name", bindMarker())).where(eq("login", bindMarker()));
    @SuppressWarnings("unused") Object response1 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[] { "Claus 2", "c_ibsen" }, CassandraConstants.CQL_QUERY, updateFirstName);
    Cluster cluster = CassandraUnitUtils.cassandraCluster();
    Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
    ResultSet resultSet1 = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
    Row row1 = resultSet1.one();
    assertNotNull(row1);
    assertEquals("Claus 2", row1.getString("first_name"));
    assertEquals("Ibsen", row1.getString("last_name"));
    Update.Where updateLastName = update("camel_user").with(set("last_name", bindMarker())).where(eq("login", bindMarker()));
    @SuppressWarnings("unused") Object response2 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[] { "Ibsen 2", "c_ibsen" }, CassandraConstants.CQL_QUERY, updateLastName);
    ResultSet resultSet2 = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
    Row row2 = resultSet2.one();
    assertNotNull(row2);
    assertEquals("Claus 2", row2.getString("first_name"));
    assertEquals("Ibsen 2", row2.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) Update(com.datastax.driver.core.querybuilder.Update) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Aggregations

Cluster (com.datastax.driver.core.Cluster)37 Test (org.junit.Test)16 Session (com.datastax.driver.core.Session)15 ResultSet (com.datastax.driver.core.ResultSet)9 Row (com.datastax.driver.core.Row)8 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)5 ReconnectionPolicy (com.datastax.driver.core.policies.ReconnectionPolicy)4 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)4 TableMetadata (com.datastax.driver.core.TableMetadata)3 Update (com.datastax.driver.core.querybuilder.Update)3 ArrayList (java.util.ArrayList)3 PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)2 PoolingOptions (com.datastax.driver.core.PoolingOptions)2 QueryOptions (com.datastax.driver.core.QueryOptions)2 RegularStatement (com.datastax.driver.core.RegularStatement)2 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)2 RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)2 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2