Skip to content

CQL embedded cassandra server

DuyHai DOAN edited this page Oct 29, 2015 · 16 revisions

Achilles exposes a simple builder to start an embedded Cassandra server and optionally bootstrap the framework.

Such feature is already available for JUnit testing using the AchillesTestResourceBuilder discussed previously. However there is still a need to start an embedded Cassandra outside of testing context and more importantly, to connect to several keyspaces.

To use the embedded Cassandra server, you must pull the following dependency:

 	<dependency>	
 		<groupId>info.archinnov</groupId>
 		<artifactId>achilles-embedded</artifactId>
 		<version>${achilles.version}</version>
 	</dependency>

The builder API:

	CassandraEmbeddedServerBuilder
		.builder()
		.withClusterName("Test Cluster")
		.withDataFolder("/home/user/cassandra/data")
		.withCommitLogFolder("/home/user/cassandra/commitlog")
		.withSavedCachesFolder("/home/user/cassandra/saved_caches")
		.cleanDataFilesAtStartup(true)
		.withClusterName("Test Cluster")
		.withKeyspaceName("achilles_test")
		.withConcurrentReads(16)
		.withConcurrentWrites(16)
		.withCQLPort(9042)
		.withThriftPort(9160)
		.withStoragePort(7990)
		.withStorageSSLPort(7999)
		.withDurableWrite(true)
		.withScript("src/test/resources/startup_script.cql")
		.withScriptTemplate("src/test/resources/startup_script_template.cql", values)
		.buildNativeSession() || buildNativeCluster() || buildServer();
	

Most of the parameters are optional, below are the default values:

  • clusterName: Achilles Embedded Cassandra Cluster
  • keyspaceName: achilles_embedded
  • dataFolder: target/cassandra_embedded/data
  • commitLogFolder: target/cassandra_embedded/commitlog
  • savedCachesFolder: target/cassandra_embedded/saved_caches
  • cleanDataFilesAtStartup: true
  • concurrenReads: number of concurrent reads
  • concurrenWrites: number of concurrent writes
  • cqlPort: randomized at runtime
  • thriftPort: randomized at runtime
  • storagePort: randomized at runtime
  • storageSSLPort: randomized at runtime
  • durableWrite: true
  • script: startup CQL script to be executed. You can specify many scripts by calling the method withScript() multiple times
  • script template: startup CQL script template to be executed given provided values. You can specify many script templates by calling the method withScriptTemplate() multiple times

The builder can return:

  1. either a com.datastax.driver.core.Cluster object
  2. or a com.datastax.driver.core.Session object
  3. or an Achilles CassandraEmbeddedServerBuilder object

There will be at most one embedded Cassandra server started per JVM (more precisely, per classloader) event if many CassandraEmbeddedServer are built. But because the keyspace name is provided each time, the builder will create as many keyspaces as specified.

Home

Clone this wiki locally