Search in sources :

Example 1 with ClassPathCQLDataSet

use of org.cassandraunit.dataset.cql.ClassPathCQLDataSet in project jhipster-sample-app-cassandra by jhipster.

the class AbstractCassandraTest method applyScripts.

private static void applyScripts(CQLDataLoader dataLoader, String cqlDir, String pattern) throws IOException, URISyntaxException {
    URL dirUrl = ClassLoader.getSystemResource(cqlDir);
    if (dirUrl == null) {
        // protect for empty directory
        return;
    }
    List<String> scripts = new ArrayList<>();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(dirUrl.toURI()), pattern)) {
        for (Path entry : stream) {
            scripts.add(entry.getFileName().toString());
        }
    }
    Collections.sort(scripts);
    for (String fileName : scripts) {
        dataLoader.load(new ClassPathCQLDataSet(cqlDir + fileName, false, false, CASSANDRA_UNIT_KEYSPACE));
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) ClassPathCQLDataSet(org.cassandraunit.dataset.cql.ClassPathCQLDataSet) URL(java.net.URL)

Example 2 with ClassPathCQLDataSet

use of org.cassandraunit.dataset.cql.ClassPathCQLDataSet in project zeppelin by apache.

the class CassandraInterpreterTest method setUp.

@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();
}
Also used : Properties(java.util.Properties) CqlSession(com.datastax.oss.driver.api.core.CqlSession) ClassPathCQLDataSet(org.cassandraunit.dataset.cql.ClassPathCQLDataSet) CQLDataLoader(org.cassandraunit.CQLDataLoader) BeforeClass(org.junit.BeforeClass)

Aggregations

ClassPathCQLDataSet (org.cassandraunit.dataset.cql.ClassPathCQLDataSet)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 CQLDataLoader (org.cassandraunit.CQLDataLoader)1 BeforeClass (org.junit.BeforeClass)1