Spring Boot Data Embedded Cassandra

alexanoid

In my Spring Boot 1.5.1 application I'm going to write unit/integration tests for Cassandra related logic.

I have added folowing Maven dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>

The default Spring Boot Cassandra configuration is going to connect with a real Cassandra DB server.

Is there any options in Spring/Spring Boot in order to configure my tests to use embedded Cassandra server ? If so, could you please show the required configuration.

walv

We use on the project Cassandra + Spring Boot. Here are the steps which worked for us:

a) Configure you test like this

import org.cassandraunit.spring.CassandraDataSet;
import org.cassandraunit.spring.CassandraUnitDependencyInjectionTestExecutionListener;
import org.cassandraunit.spring.CassandraUnitTestExecutionListener;
import org.cassandraunit.spring.EmbeddedCassandra;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestConfiguration.class)
@TestExecutionListeners(listeners = {
    CassandraUnitDependencyInjectionTestExecutionListener.class,
    CassandraUnitTestExecutionListener.class,
    ServletTestExecutionListener.class,
    DependencyInjectionTestExecutionListener.class,
    DirtiesContextTestExecutionListener.class
})
@EmbeddedCassandra(timeout = 60000)
@CassandraDataSet(value = {"bootstrap_test.cql"}, keyspace = "local_test")
public abstract class BaseTest {

b) in your src/test/resources/application.properties, add this (please note, embedded cassandra starts on port 9142, but not on default 9042)

spring.data.cassandra.port=9142
spring.data.cassandra.keyspace-name=local_test

c) Create empty file bootstrap_test.cql in src/test/resources

d) Add to your pom.xml

    <dependency>
        <groupId>org.cassandraunit</groupId>
        <artifactId>cassandra-unit-spring</artifactId>
        <version>${cassandra-unit.version}</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.cassandraunit</groupId>
                <artifactId>cassandra-unit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.cassandraunit</groupId>
        <artifactId>cassandra-unit-spring</artifactId>
        <version>${cassandra-unit.version}</version>
    </dependency>

This should be enough to run your tests with Embedded Cassandra. Hope it helps.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring boot Embedded MongoDb data prefilled

spring boot data cassandra reactive JmxReporter problem

Is there any Spring Boot Data Reactive Starter targeting an embedded data store?

Not able to connect to cassandra from spring boot aplication using spring-boot-starter-data-cassandra

Spring boot application with spring data cassandra failing to start

Embedded Redis for Spring Boot

Spring boot + cassandra

Spring Boot Loads Before Embedded Cassandra When Using Cucumber, How Can I Fix This?

How to use cassandra with postgres using spring-boot-starter-data

Spring Data : Embedded /Non embedded?

SymmetricDS Spring boot with Embedded Clients

Embedded Postgres for Spring Boot Tests

Spring boot embedded tomcat logs

Spring Boot + GWT embedded configuraiton

Spring Boot Embedded Tomcat Performance

non embedded postgresql in spring boot

Spring Data Cassandra and PreparedStatementCache

Spring-Cassandra Unit with Embedded Cassandra Dependency Injection Issue

How to disable embedded database Spring-boot spring-data-jpa

Spring-Boot, Spring-Data-Cassandra: Autowire CassandraRepository, java.lang.NoClassDefFoundError

How can I use two Cassandra datasources with Spring Boot and Spring Data?

Auditing and @Embedded in Spring Data JPA

Using multiple embedded datastores with Spring Boot

Spring Boot Embedded ActiveMQ durable messages

Spring boot configure custom jsessionid for embedded server

Spring Boot Embedded Kafka can't connect

How to set Handler for embedded Jetty in Spring Boot?

Spring boot WAR size with different embedded servers

Spring Boot not validating Embedded object on Entity