Java Code Examples for org.cassandraunit.utils.EmbeddedCassandraServerHelper#getSession()

The following examples show how to use org.cassandraunit.utils.EmbeddedCassandraServerHelper#getSession() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmbeddedCassandraStoreFactory.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private Session createEmbeddedCassandra() {
    // Disable fsync for a massive speedup on old platters. This improves boot time by a few seconds.
    System.setProperty("cassandra.unsafesystem", "true");

    try {
        File cassandraTmpDir = Files.createTempDir();
        EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_CONFIG, cassandraTmpDir.getAbsolutePath(), STARTUP_TIMEOUT);
    } catch (Exception e) {
        throw new IllegalStateException("Cannot initialize the embedded Cassandra", e);
    }

    Session session = EmbeddedCassandraServerHelper.getSession();
    session.execute("CREATE KEYSPACE " + CASSANDRA_KEYSPACE + " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }");
    session.execute("USE " + CASSANDRA_KEYSPACE);

    CQLDataLoader dataLoader = new CQLDataLoader(session);
    dataLoader.load(new ClassPathCQLDataSet(CASSANDRA_SCHEMA, "Titus"));

    return session;
}
 
Example 2
Source File: CassandraTransactionManagerTestCase.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startCassandra() {
    try {
        EmbeddedCassandraServerHelper.startEmbeddedCassandra();
        cqlSession = EmbeddedCassandraServerHelper.getSession();
        CqlOperations.createKeyspace(cqlSession).accept(CassandraTransactionManager.KEYSPACE);
        cqlSession.execute(CassandraTransactionManager.CREATE_TABLE);
    } catch (Exception exception) {
        exception.printStackTrace();
        throw new RuntimeException(exception);
    }
}
 
Example 3
Source File: EmbeddedCassandraConnectorTestBase.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
/**
 * Drop all tables in TEST_KEYSPACE
 */
protected static void deleteTestKeyspaceTables() {
    Session session = EmbeddedCassandraServerHelper.getSession();
    Cluster cluster = EmbeddedCassandraServerHelper.getCluster();
    for (TableMetadata tm : cluster.getMetadata().getKeyspace(TEST_KEYSPACE).getTables()) {
        session.execute("DROP TABLE IF EXISTS " + keyspaceTable(tm.getName()));
    }
}
 
Example 4
Source File: TitusCassandraResource.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public Session getSession() {
    if (session == null) {
        loadSchema();
        session = EmbeddedCassandraServerHelper.getSession();
    }
    return session;
}
 
Example 5
Source File: CassandraInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static synchronized void setUp() throws IOException, InterruptedException {
  System.setProperty("cassandra.skip_wait_for_gossip_to_settle", "0");
  System.setProperty("cassandra.load_ring_state", "false");
  System.setProperty("cassandra.initial_token", "0");
  System.setProperty("cassandra.num_tokens", "nil");
  System.setProperty("cassandra.allocate_tokens_for_local_replication_factor", "nil");
  EmbeddedCassandraServerHelper.startEmbeddedCassandra();
  CqlSession session = EmbeddedCassandraServerHelper.getSession();
  new CQLDataLoader(session).load(new ClassPathCQLDataSet("prepare_all.cql", "zeppelin"));

  Properties properties = new Properties();
  properties.setProperty(CASSANDRA_CLUSTER_NAME, EmbeddedCassandraServerHelper.getClusterName());
  properties.setProperty(CASSANDRA_COMPRESSION_PROTOCOL, "NONE");
  properties.setProperty(CASSANDRA_CREDENTIALS_USERNAME, "none");
  properties.setProperty(CASSANDRA_CREDENTIALS_PASSWORD, "none");

  properties.setProperty(CASSANDRA_LOAD_BALANCING_POLICY, "DEFAULT");
  properties.setProperty(CASSANDRA_RETRY_POLICY, "DEFAULT");
  properties.setProperty(CASSANDRA_RECONNECTION_POLICY, "DEFAULT");
  properties.setProperty(CASSANDRA_SPECULATIVE_EXECUTION_POLICY, "DEFAULT");

  properties.setProperty(CASSANDRA_POOLING_CONNECTION_PER_HOST_LOCAL, "2");
  properties.setProperty(CASSANDRA_POOLING_CONNECTION_PER_HOST_REMOTE, "1");
  properties.setProperty(CASSANDRA_POOLING_MAX_REQUESTS_PER_CONNECTION, "1024");

  properties.setProperty(CASSANDRA_POOLING_POOL_TIMEOUT_MILLIS, "5000");
  properties.setProperty(CASSANDRA_POOLING_HEARTBEAT_INTERVAL_SECONDS, "30");

  properties.setProperty(CASSANDRA_QUERY_DEFAULT_CONSISTENCY, "ONE");
  properties.setProperty(CASSANDRA_QUERY_DEFAULT_SERIAL_CONSISTENCY, "SERIAL");
  properties.setProperty(CASSANDRA_QUERY_DEFAULT_FETCH_SIZE, "5000");

  properties.setProperty(CASSANDRA_SOCKET_CONNECTION_TIMEOUT_MILLIS, "5000");
  properties.setProperty(CASSANDRA_SOCKET_READ_TIMEOUT_MILLIS, "12000");
  properties.setProperty(CASSANDRA_SOCKET_TCP_NO_DELAY, "true");

  properties.setProperty(CASSANDRA_HOSTS, EmbeddedCassandraServerHelper.getHost());
  properties.setProperty(CASSANDRA_PORT,
          Integer.toString(EmbeddedCassandraServerHelper.getNativeTransportPort()));
  properties.setProperty("datastax-java-driver.advanced.connection.pool.local.size", "1");
  interpreter = new CassandraInterpreter(properties);
  interpreter.open();
}
 
Example 6
Source File: CassandraInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_execute_statement_with_timestamp_option() throws Exception {
  //Given
  String statement1 = "INSERT INTO zeppelin.ts(key,val) VALUES('k','v1');";
  String statement2 = "@timestamp=15\n" +
          "INSERT INTO zeppelin.ts(key,val) VALUES('k','v2');";

  CqlSession session = EmbeddedCassandraServerHelper.getSession();
  // Insert v1 with current timestamp
  interpreter.interpret(statement1, intrContext);
  System.out.println("going to read data from zeppelin.ts;");
  session.execute("SELECT val FROM zeppelin.ts LIMIT 1")
          .forEach(x -> System.out.println("row " + x ));

  Thread.sleep(1);

  //When
  // Insert v2 with past timestamp
  interpreter.interpret(statement2, intrContext);
  System.out.println("going to read data from zeppelin.ts;");
  session.execute("SELECT val FROM zeppelin.ts LIMIT 1")
          .forEach(x -> System.out.println("row " + x ));
  final String actual = session.execute("SELECT val FROM zeppelin.ts LIMIT 1").one()
          .getString("val");

  //Then
  assertThat(actual).isEqualTo("v1");
}
 
Example 7
Source File: EmbeddedCassandraConnectorTestBase.java    From debezium-incubator with Apache License 2.0 4 votes vote down vote up
private static void createTestKeyspace() {
    Session session = EmbeddedCassandraServerHelper.getSession();
    CqlOperations.createKeyspace(session).accept(TEST_KEYSPACE);
}
 
Example 8
Source File: EmbeddedCassandraConnectorTestBase.java    From debezium-incubator with Apache License 2.0 4 votes vote down vote up
private static void destroyTestKeyspace() {
    Session session = EmbeddedCassandraServerHelper.getSession();
    CqlOperations.dropKeyspace(session).accept(TEST_KEYSPACE);
}
 
Example 9
Source File: TitusCassandraResource.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private void loadSchema() {
    CQLDataLoader dataLoader = new CQLDataLoader(EmbeddedCassandraServerHelper.getSession());
    dataLoader.load(new ClassPathCQLDataSet(CASSANDRA_SCHEMA, "Titus"));
}
 
Example 10
Source File: CassandraLoaderStandaloneTest.java    From swblocks-decisiontree with Apache License 2.0 4 votes vote down vote up
@Before
public void before() {
    this.cluster = EmbeddedCassandraServerHelper.getCluster();
    this.session = EmbeddedCassandraServerHelper.getSession();
}
 
Example 11
Source File: EmbeddedCassandra.java    From conductor with Apache License 2.0 4 votes vote down vote up
public Session getSession() {
    return EmbeddedCassandraServerHelper.getSession();
}
 
Example 12
Source File: CassandraLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 4 votes vote down vote up
@BeforeAll
public static void startCassandra() throws IOException, InterruptedException {
    EmbeddedCassandraServerHelper.startEmbeddedCassandra();
    cqlSession = EmbeddedCassandraServerHelper.getSession();
    new CQLDataLoader(cqlSession).load(new ClassPathCQLDataSet("shedlock.cql", "shedlock"));
}
 
Example 13
Source File: CassandraExtension.java    From calcite with Apache License 2.0 4 votes vote down vote up
private CassandraResource() {
  startCassandra();
  this.cluster = EmbeddedCassandraServerHelper.getCluster();
  this.session = EmbeddedCassandraServerHelper.getSession();
}