Search in sources :

Example 31 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 32 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)

Example 33 with Cluster

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

the class CassandraComponentProducerUnpreparedTest method testRequestUriCql.

@Test
public void testRequestUriCql() throws Exception {
    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 34 with Cluster

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

the class CassandraComponentProducerUnpreparedTest method testRequestMessageCql.

@Test
public void testRequestMessageCql() throws Exception {
    Object response = producerTemplate.requestBodyAndHeader(new Object[] { "Claus 2", "Ibsen 2", "c_ibsen" }, CassandraConstants.CQL_QUERY, "update camel_user set first_name=?, last_name=? where login=?");
    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 = ?", "c_ibsen");
    Row row = resultSet.one();
    assertNotNull(row);
    assertEquals("Claus 2", row.getString("first_name"));
    assertEquals("Ibsen 2", 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 35 with Cluster

use of com.datastax.driver.core.Cluster in project aroma-data-operations by RedRoma.

the class ModuleCassandraDevClusterTest method testModule.

@Test
public void testModule() {
    Injector injector = Guice.createInjector(instance);
    Cluster cluster = injector.getInstance(Cluster.class);
    assertThat(cluster, notNullValue());
    Session session = injector.getInstance(Session.class);
    assertThat(session, notNullValue());
}
Also used : Injector(com.google.inject.Injector) Cluster(com.datastax.driver.core.Cluster) Session(com.datastax.driver.core.Session) Test(org.junit.Test) IntegrationTest(tech.sirwellington.alchemy.annotations.testing.IntegrationTest)

Aggregations

Cluster (com.datastax.driver.core.Cluster)41 Session (com.datastax.driver.core.Session)17 Test (org.junit.Test)17 ResultSet (com.datastax.driver.core.ResultSet)11 Row (com.datastax.driver.core.Row)9 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)6 ArrayList (java.util.ArrayList)5 PoolingOptions (com.datastax.driver.core.PoolingOptions)4 ReconnectionPolicy (com.datastax.driver.core.policies.ReconnectionPolicy)4 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)4 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)4 QueryOptions (com.datastax.driver.core.QueryOptions)3 TableMetadata (com.datastax.driver.core.TableMetadata)3 DCAwareRoundRobinPolicy (com.datastax.driver.core.policies.DCAwareRoundRobinPolicy)3 Update (com.datastax.driver.core.querybuilder.Update)3 InetSocketAddress (java.net.InetSocketAddress)3 Host (com.datastax.driver.core.Host)2 JdkSSLOptions (com.datastax.driver.core.JdkSSLOptions)2 Metadata (com.datastax.driver.core.Metadata)2 PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)2