KandraTestcontainers

Integration test utilities for running Kandra against a real ScyllaDB/Cassandra instance.

Starts one shared container per JVM and creates a fresh, randomly-named keyspace per test class — ensuring complete isolation between test classes running in parallel.

class UserRepositoryTest {
private val db = KandraTestcontainers.freshKeyspace(User::class)
private val userRepo = db.suspendRepository<User>()

@AfterEach fun cleanup() = db.close()
}

Properties

Link copied to clipboard
val container: CassandraContainer<*>

Shared container — started once per JVM, reused across all test classes.

Functions

Link copied to clipboard
fun freshKeyspace(vararg classes: KClass<*>, replicationFactor: Int = 1, statementBuilderConsistencyConfig: ConsistencyConfig = ConsistencyConfig()): KandraRuntimeHandle

Creates a fresh keyspace with a random name, registers classes, and creates tables.

Link copied to clipboard
fun newContainerSession(keyspace: String? = null): CqlSession

A session on the shared Docker container with the same 30 s request/schema timeouts as KandraTestBackend.newSession, bound to keyspace when given. Unlike KandraTestBackend it always targets the container, whatever KANDRA_TEST_BACKEND says — for tests that are Docker-only by design (fixed keyspace names that would collide on a shared cloud cluster). The caller closes it.