com.asarkar.spring:cassandra-unit-spring

Starts the Cassandra server and makes the ports available as Spring Boot environment properties

License

License

Categories

Categories

Cassandra Data Databases
GroupId

GroupId

com.asarkar.spring
ArtifactId

ArtifactId

cassandra-unit-spring
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

com.asarkar.spring:cassandra-unit-spring
Starts the Cassandra server and makes the ports available as Spring Boot environment properties
Project URL

Project URL

https://github.com/asarkar/cassandra-unit-spring
Source Code Management

Source Code Management

https://github.com/asarkar/cassandra-unit-spring

Download cassandra-unit-spring

How to add to project

<!-- https://jarcasting.com/artifacts/com.asarkar.spring/cassandra-unit-spring/ -->
<dependency>
    <groupId>com.asarkar.spring</groupId>
    <artifactId>cassandra-unit-spring</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.asarkar.spring/cassandra-unit-spring/
implementation 'com.asarkar.spring:cassandra-unit-spring:2.0.0'
// https://jarcasting.com/artifacts/com.asarkar.spring/cassandra-unit-spring/
implementation ("com.asarkar.spring:cassandra-unit-spring:2.0.0")
'com.asarkar.spring:cassandra-unit-spring:jar:2.0.0'
<dependency org="com.asarkar.spring" name="cassandra-unit-spring" rev="2.0.0">
  <artifact name="cassandra-unit-spring" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.asarkar.spring', module='cassandra-unit-spring', version='2.0.0')
)
libraryDependencies += "com.asarkar.spring" % "cassandra-unit-spring" % "2.0.0"
[com.asarkar.spring/cassandra-unit-spring "2.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.10

runtime (3)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar
org.cassandraunit : cassandra-unit jar 4.3.1.0
com.datastax.oss : java-driver-core jar 4.9.0

Project Modules

There are no modules declared in this project.

cassandra-unit-spring

Starts the Cassandra server and makes the ports available as Spring Boot environment properties.

Requires Java 8 or later. Uses cassandra-unit and Spring Boot.

Installation

You can find the latest version on Bintray. Download

It is also on Maven Central and jcenter.

Usage

The only thing you need is the AutoConfigureCassandraUnit annotation:

@SpringBootTest
@AutoConfigureCassandraUnit(config = EmbeddedCassandraServerHelper.CASSANDRA_RNDPORT_YML_FILE)
public class AutoConfigureWithRandomPortsTest {
    @Value("${cassandra-unit.native-transport-port:-1}")
    private int nativeTransportPort = -1;

    @Value("${cassandra-unit.rpc-port:-1}")
    private int rpcPort = -1;

    @Test
    public void testUseRandomPorts() {
        Assertions.assertEquals(EmbeddedCassandraServerHelper.getNativeTransportPort(), nativeTransportPort);
        Assertions.assertEquals(EmbeddedCassandraServerHelper.getRpcPort(), rpcPort);
    }
}

See KDoc for more details.

Note that CassandraUnit can only run one Cassandra instance per JVM; thus, if AutoConfigureCassandraUnit annotation is present on more than one test classes, only the first one is used, the others are ignored. That means the port properties will not change once a Cassandra instance is started.

This library aims to be minimal and manages only the lifecycle of the Cassandra server during testing; it does not run initialization scripts or clean the database between tests, because you can do those things yourself.

If you abort a test or run two tests both of which start the server, you may be faced with a FileAlreadyExistsException. That is because of this bug. If using Maven, clean goal will delete the temporary directory; if using Gradle, you can either delete the target directory manually, or add it to the Gradle clean task.

Contribute

This project is a volunteer effort. You are welcome to send pull requests, ask questions, or create issues. If you like it, you can help by spreading the word!

License

Copyright 2020 Abhijit Sarkar - Released under Apache License v2.0.

Versions

Version
2.0.0
1.0.7