-
Notifications
You must be signed in to change notification settings - Fork 92
CQL embedded cassandra server
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 AchillesResourceBuilder 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
.withEntityPackages("test") || noEntityPackages()
.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")
.withCQLPort(9042)
.withThriftPort(9160)
.withStoragePort(7990)
.withStorageSSLPort(7999)
.withDurableWrite(true)
.buildNativeSessionOnly() || buildPersistenceManagerFactory() || buildPersistenceManager();
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
- cqlPort: randomized at runtime
- thriftPort: randomized at runtime
- storagePort: randomized at runtime
- storageSSLPort: randomized at runtime
- durableWrite: true
The builder can return:
- either an Achilles
PersistenceManagerFactory
- or an Achilles
PersistenceManager
- or just a native
Session
object from the driver
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 bootstrap as many PersistenceManager
instances or Session
objects as distinct keyspaces.
Example is better than words:
PersistenceManagerFactory factory1 = CassandraEmbeddedServerBuilder
.withEntityPackages("my.entity.package1")
.withKeyspaceName("keyspace1")
.withScript("startup_script1.cql")
.buildPersistenceManagerFactory();
PersistenceManagerFactory factory2 = CassandraEmbeddedServerBuilder
.withEntityPackages("my.entity.package2")
.withKeyspaceName("keyspace2")
.withScript("startup_script2.cql")
.buildPersistenceManagerFactory();
PersistenceManagerFactory factory3 = CassandraEmbeddedServerBuilder
.withEntityPackages("my.entity.package1")
.withKeyspaceName("keyspace1")
.withScript("startup_script3.cql")
.buildPersistenceManagerFactory();
assertThat(factory1).isNotEqualTo(factory2);
assertThat(factory1).isEqualTo(factory3);
-
Bootstraping Achilles at runtime
- Runtime Configuration Parameters
-
Manager
-
Consistency Level
-
Cassandra Options at runtime
-
Lightweight Transaction (LWT)
-
JSON Serialization
-
Interceptors
-
Bean Validation (JSR-303)