Search in sources :

Example 26 with Session

use of com.datastax.driver.core.Session in project pinpoint by naver.

the class CassandraDatastaxITBase method initializeCluster.

public static void initializeCluster(String cassandraVersion) throws Exception {
    CassandraTestHelper.init(cassandraVersion);
    HOST = CassandraTestHelper.getHost();
    PORT = CassandraTestHelper.getNativeTransportPort();
    CASSANDRA_ADDRESS = HOST + ":" + PORT;
    cluster = Cluster.builder().addContactPoint(HOST).withPort(PORT).withoutMetrics().build();
    // Create KeySpace
    Session emptySession = null;
    try {
        emptySession = cluster.connect();
        emptySession.execute(CQL_CREATE_KEYSPACE);
    } finally {
        closeSession(emptySession);
    }
    // Create Table
    Session myKeyspaceSession = null;
    try {
        myKeyspaceSession = cluster.connect(TEST_KEYSPACE);
        myKeyspaceSession.execute(CQL_CREATE_TABLE);
    } finally {
        closeSession(myKeyspaceSession);
    }
}
Also used : Session(com.datastax.driver.core.Session)

Example 27 with Session

use of com.datastax.driver.core.Session 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)

Example 28 with Session

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

the class ModuleCassandraDevClusterTest method testProvideCassandraSession.

@Test
public void testProvideCassandraSession() {
    ReconnectionPolicy policy = instance.provideReconnectPolicy();
    Cluster cluster = instance.provideCassandraCluster(policy);
    Session session = instance.provideCassandraSession(cluster);
    assertThat(session, notNullValue());
}
Also used : ReconnectionPolicy(com.datastax.driver.core.policies.ReconnectionPolicy) Cluster(com.datastax.driver.core.Cluster) Session(com.datastax.driver.core.Session) Test(org.junit.Test) IntegrationTest(tech.sirwellington.alchemy.annotations.testing.IntegrationTest)

Example 29 with Session

use of com.datastax.driver.core.Session in project logging-log4j2 by apache.

the class CassandraAppenderIT method appendManyEvents.

@Test
public void appendManyEvents() throws Exception {
    final Logger logger = CTX.getLogger();
    ThreadContext.put("test", "mdc");
    ThreadContext.push("ndc");
    for (int i = 0; i < 20; i++) {
        logger.info(MarkerManager.getMarker("MARKER"), "Test log message");
    }
    ThreadContext.clearAll();
    TimeUnit.SECONDS.sleep(3);
    int i = 0;
    try (final Session session = CASSANDRA.connect()) {
        for (final Row row : session.execute("SELECT * FROM logs")) {
            assertNotNull(row.get("id", UUID.class));
            assertNotNull(row.get("timeid", UUID.class));
            assertNotNull(row.get("timestamp", Date.class));
            assertEquals("Test log message", row.getString("message"));
            assertEquals("MARKER", row.getString("marker"));
            assertEquals("INFO", row.getString("level"));
            assertEquals(getClass().getName(), row.getString("logger"));
            final Map<String, String> mdc = row.getMap("mdc", String.class, String.class);
            assertEquals(1, mdc.size());
            assertEquals("mdc", mdc.get("test"));
            final List<String> ndc = row.getList("ndc", String.class);
            assertEquals(1, ndc.size());
            assertEquals("ndc", ndc.get(0));
            ++i;
        }
    }
    assertEquals(20, i);
}
Also used : Row(com.datastax.driver.core.Row) Logger(org.apache.logging.log4j.Logger) UUID(java.util.UUID) Date(java.util.Date) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 30 with Session

use of com.datastax.driver.core.Session in project logging-log4j2 by apache.

the class CassandraRule method before.

@Override
protected void before() throws Throwable {
    final Path root = Files.createTempDirectory("cassandra");
    Files.createDirectories(root.resolve("data"));
    final Path config = root.resolve("cassandra.yml");
    Files.copy(getClass().getResourceAsStream("/cassandra.yaml"), config);
    System.setProperty("cassandra.config", "file:" + config.toString());
    System.setProperty("cassandra.storagedir", root.toString());
    // prevents Cassandra from closing stdout/stderr
    System.setProperty("cassandra-foreground", "true");
    THREAD_FACTORY.newThread(embeddedCassandra).start();
    latch.await();
    cluster = Cluster.builder().addContactPoints(InetAddress.getLoopbackAddress()).build();
    try (final Session session = cluster.connect()) {
        session.execute("CREATE KEYSPACE " + keyspace + " WITH REPLICATION = " + "{ 'class': 'SimpleStrategy', 'replication_factor': 2 };");
    }
    try (final Session session = connect()) {
        session.execute(tableDdl);
    }
}
Also used : Path(java.nio.file.Path) Session(com.datastax.driver.core.Session)

Aggregations

Session (com.datastax.driver.core.Session)30 Cluster (com.datastax.driver.core.Cluster)16 Test (org.junit.Test)16 ResultSet (com.datastax.driver.core.ResultSet)11 Row (com.datastax.driver.core.Row)10 BoundStatement (com.datastax.driver.core.BoundStatement)3 PreparedStatement (com.datastax.driver.core.PreparedStatement)3 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)3 Update (com.datastax.driver.core.querybuilder.Update)3 ReconnectionPolicy (com.datastax.driver.core.policies.ReconnectionPolicy)2 IOException (java.io.IOException)2 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)2 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)1 DataType (com.datastax.driver.core.DataType)1 Host (com.datastax.driver.core.Host)1 IndexMetadata (com.datastax.driver.core.IndexMetadata)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 Metadata (com.datastax.driver.core.Metadata)1 QueryTrace (com.datastax.driver.core.QueryTrace)1 SimpleStatement (com.datastax.driver.core.SimpleStatement)1