Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/asarkar/cassandra-unit-spring
https://github.com/asarkar/cassandra-unit-spring
annotation cassandra cassandra-server cassandra-unit integration-testing spring spring-boot testing
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/asarkar/cassandra-unit-spring
- Owner: asarkar
- License: apache-2.0
- Created: 2020-09-27T03:48:33.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-19T03:41:23.000Z (almost 3 years ago)
- Last Synced: 2024-11-20T16:28:30.478Z (2 months ago)
- Topics: annotation, cassandra, cassandra-server, cassandra-unit, integration-testing, spring, spring-boot, testing
- Language: Kotlin
- Homepage:
- Size: 106 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/jsevellec/cassandra-unit) and [Spring Boot](https://spring.io/projects/spring-boot).
## Installation
You can find the latest version on [Maven Central](https://search.maven.org/search?q=g:com.asarkar.spring%20AND%20a:cassandra-unit-spring).
## Usage
You will need to add a test runtime dependency on [org.cassandraunit:cassandra-unit](https://search.maven.org/artifact/org.cassandraunit/cassandra-unit). If using Gradle, it can be done with `testRuntimeOnly("org.cassandraunit:cassandra-unit:$someVersion")`.
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.
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.:information_source: If you use Spring Data, you can set `spring.data.cassandra.port=${cassandra-unit.rpc-port:-1}` property in `src/test/application.properties` or `@SpringBootTest.properties` attribute.
:information_source: cassandra-unit 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.:warning: 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](https://github.com/jsevellec/cassandra-unit/issues/319). 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](https://stackoverflow.com/a/29813360/839733).
:warning: cassandra-unit doesn't work with Java 11; see [this bug](https://github.com/jsevellec/cassandra-unit/issues/294).
:warning: cassandra-unit doesn't work with Java 17; see [this bug](https://github.com/jsevellec/cassandra-unit/issues/332).
## 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 and "Starring" the GitHub repo!
## License
Copyright 2022 Abhijit Sarkar - Released under [Apache License v2.0](LICENSE).