Skip to content

Commit e692f31

Browse files
committed
Remove embedded Cassandra integration test mode in favor of Testcontainers.
Closes #1154
1 parent 74ea7f8 commit e692f31

File tree

8 files changed

+30
-1127
lines changed

8 files changed

+30
-1127
lines changed

pom.xml

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898

9999
<properties>
100100
<build.cassandra.host>localhost</build.cassandra.host>
101-
<build.cassandra.mode>embedded</build.cassandra.mode>
101+
<build.cassandra.mode>testcontainers</build.cassandra.mode>
102102
<build.cassandra.native_transport_port>19042</build.cassandra.native_transport_port>
103103
<build.cassandra.rpc_port>19160</build.cassandra.rpc_port>
104104
<build.cassandra.ssl_storage_port>17001</build.cassandra.ssl_storage_port>
@@ -126,24 +126,6 @@
126126
<type>pom</type>
127127
</dependency>
128128

129-
<!-- Test Dependencies -->
130-
<dependency>
131-
<groupId>org.apache.cassandra</groupId>
132-
<artifactId>cassandra-all</artifactId>
133-
<version>${cassandra.version}</version>
134-
<scope>test</scope>
135-
<exclusions>
136-
<exclusion>
137-
<groupId>ch.qos.logback</groupId>
138-
<artifactId>logback-core</artifactId>
139-
</exclusion>
140-
<exclusion>
141-
<groupId>io.netty</groupId>
142-
<artifactId>netty-all</artifactId>
143-
</exclusion>
144-
</exclusions>
145-
</dependency>
146-
147129
<dependency>
148130
<groupId>org.assertj</groupId>
149131
<artifactId>assertj-core</artifactId>
@@ -165,20 +147,6 @@
165147
<scope>import</scope>
166148
</dependency>
167149

168-
<dependency>
169-
<groupId>org.xerial.snappy</groupId>
170-
<artifactId>snappy-java</artifactId>
171-
<version>1.1.10.5</version>
172-
<scope>test</scope>
173-
</dependency>
174-
175-
<dependency>
176-
<groupId>com.carrotsearch</groupId>
177-
<artifactId>hppc</artifactId>
178-
<version>${hppc.version}</version>
179-
<scope>test</scope>
180-
</dependency>
181-
182150
<dependency>
183151
<groupId>edu.umd.cs.mtc</groupId>
184152
<artifactId>multithreadedtc</artifactId>
@@ -189,29 +157,8 @@
189157
</dependencies>
190158
</dependencyManagement>
191159

192-
<dependencies>
193-
<dependency>
194-
<groupId>org.assertj</groupId>
195-
<artifactId>assertj-core</artifactId>
196-
<scope>test</scope>
197-
</dependency>
198-
</dependencies>
199-
200160
<build>
201161
<plugins>
202-
<plugin>
203-
<groupId>org.bitstrings.maven.plugins</groupId>
204-
<artifactId>dependencypath-maven-plugin</artifactId>
205-
<version>1.1.1</version>
206-
<executions>
207-
<execution>
208-
<id>set-all</id>
209-
<goals>
210-
<goal>set</goal>
211-
</goals>
212-
</execution>
213-
</executions>
214-
</plugin>
215162
<plugin>
216163
<groupId>org.apache.maven.plugins</groupId>
217164
<artifactId>maven-dependency-plugin</artifactId>
@@ -232,11 +179,6 @@
232179
<exclude>**/**IntegrationTests</exclude>
233180
<exclude>**/test/performance/**/*</exclude>
234181
</excludes>
235-
<systemPropertyVariables>
236-
<java.util.logging.config.file>
237-
src/test/resources/logging.properties
238-
</java.util.logging.config.file>
239-
</systemPropertyVariables>
240182
</configuration>
241183
</plugin>
242184
<plugin>
@@ -256,11 +198,6 @@
256198
<exclude>**/*UnitTests</exclude>
257199
<exclude>**/test/performance/**/*</exclude>
258200
</excludes>
259-
<systemPropertyVariables>
260-
<java.util.logging.config.file>
261-
src/test/resources/logging.properties
262-
</java.util.logging.config.file>
263-
</systemPropertyVariables>
264201
</configuration>
265202
<executions>
266203
<execution>
@@ -304,50 +241,9 @@
304241
</build>
305242

306243
<profiles>
307-
<profile>
308-
<id>embedded-cassandra</id>
309-
310-
<activation>
311-
<activeByDefault>true</activeByDefault>
312-
</activation>
313-
314-
<properties>
315-
<build.cassandra.mode>embedded</build.cassandra.mode>
316-
</properties>
317-
318-
<build>
319-
<plugins>
320-
<plugin>
321-
<!-- Random port generation requires embedded-cassandra.yaml and cassandra-connection.properties
322-
in both modules -->
323-
<groupId>org.codehaus.mojo</groupId>
324-
<artifactId>build-helper-maven-plugin</artifactId>
325-
<version>1.8</version>
326-
<executions>
327-
<execution>
328-
<id>reserve-network-port</id>
329-
<goals>
330-
<goal>reserve-network-port</goal>
331-
</goals>
332-
<phase>generate-test-resources</phase>
333-
<configuration>
334-
<portNames>
335-
<portName>build.cassandra.native_transport_port
336-
</portName>
337-
<portName>build.cassandra.rpc_port</portName>
338-
<portName>build.cassandra.storage_port</portName>
339-
<portName>build.cassandra.ssl_storage_port
340-
</portName>
341-
</portNames>
342-
</configuration>
343-
</execution>
344-
</executions>
345-
</plugin>
346-
</plugins>
347-
</build>
348-
</profile>
349244
<profile>
350245
<id>external-cassandra</id>
246+
351247
<properties>
352248
<build.cassandra.mode>external</build.cassandra.mode>
353249
<build.cassandra.native_transport_port>9042</build.cassandra.native_transport_port>

spring-data-cassandra/pom.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,12 @@
156156
<scope>test</scope>
157157
</dependency>
158158

159-
<dependency>
160-
<groupId>org.apache.cassandra</groupId>
161-
<artifactId>cassandra-all</artifactId>
162-
<exclusions>
163-
<exclusion>
164-
<groupId>javax.inject</groupId>
165-
<artifactId>javax.inject</artifactId>
166-
</exclusion>
167-
</exclusions>
168-
</dependency>
169-
170159
<dependency>
171160
<groupId>org.testcontainers</groupId>
172161
<artifactId>cassandra</artifactId>
173162
<scope>test</scope>
174163
</dependency>
175164

176-
<dependency>
177-
<groupId>org.xerial.snappy</groupId>
178-
<artifactId>snappy-java</artifactId>
179-
</dependency>
180-
181165
<dependency>
182166
<groupId>com.fasterxml.jackson.core</groupId>
183167
<artifactId>jackson-core</artifactId>

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/core/cql/generator/AbstractKeyspaceOperationCqlGeneratorTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717

1818
import java.util.UUID;
1919

20-
import org.apache.commons.lang3.StringUtils;
2120
import org.junit.jupiter.api.Test;
21+
2222
import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceActionSpecification;
23+
import org.springframework.data.cassandra.core.cql.keyspace.TableNameSpecification;
24+
25+
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
2326

2427
/**
2528
* Useful test class that specifies just about as much as you can for a CQL generation test. Intended to be extended by

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/support/CassandraConnectionProperties.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class CassandraConnectionProperties extends Properties {
4242
private final String resourceName;
4343

4444
/**
45-
* Construct a new instance of {@link CassandraConnectionProperties} using properties
46-
* from {@code config/cassandra-connection.properties}.
45+
* Construct a new instance of {@link CassandraConnectionProperties} using properties from
46+
* {@code config/cassandra-connection.properties}.
4747
*/
4848
public CassandraConnectionProperties() {
4949
this("/config/cassandra-connection.properties");
@@ -69,8 +69,7 @@ public void update() {
6969
}
7070

7171
reload();
72-
}
73-
catch (Exception cause) {
72+
} catch (Exception cause) {
7473
cause.printStackTrace();
7574
throw new IllegalStateException(cause);
7675
}
@@ -94,12 +93,11 @@ private void loadProperties() {
9493

9594
private void loadProperties(String resourceName) {
9695

97-
try (InputStream in = getClass().getResourceAsStream(resourceName)){
96+
try (InputStream in = getClass().getResourceAsStream(resourceName)) {
9897
if (in != null) {
9998
load(in);
10099
}
101-
}
102-
catch (Exception cause) {
100+
} catch (Exception cause) {
103101
throw new RuntimeException(cause);
104102
}
105103
}
@@ -166,15 +164,14 @@ public int getCassandraStoragePort() {
166164
}
167165

168166
/**
169-
* @return the Cassandra type (Embedded or External)
167+
* @return the Cassandra type (Testcontainers or External)
170168
*/
171169
public CassandraType getCassandraType() {
172170

173171
String cassandraType = getProperty("build.cassandra.mode");
174172

175-
return CassandraType.TESTCONTAINERS.name().equalsIgnoreCase(cassandraType) ? CassandraType.TESTCONTAINERS
176-
: CassandraType.EXTERNAL.name().equalsIgnoreCase(cassandraType) ? CassandraType.EXTERNAL
177-
: CassandraType.EMBEDDED;
173+
return CassandraType.EXTERNAL.name().equalsIgnoreCase(cassandraType) ? CassandraType.EXTERNAL
174+
: CassandraType.TESTCONTAINERS;
178175
}
179176

180177
/**
@@ -224,6 +221,6 @@ private <T> T convert(String propertyName, Class<T> type, Converter<String, T> c
224221
}
225222

226223
public enum CassandraType {
227-
EMBEDDED, EXTERNAL, TESTCONTAINERS
224+
EXTERNAL, TESTCONTAINERS
228225
}
229226
}

spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/util/CassandraDelegate.java

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@
4747
import com.datastax.oss.driver.api.core.metadata.Node;
4848

4949
/**
50-
* Delegate used to provide a Cassandra context for integration tests. This rule can use/spin up either an embedded
51-
* Cassandra instance, a TestContainer or use an external instance. Derives its configuration from
52-
* {@code /config/cassandra-connection.properties} and {@link System#getenv(String)} {@code CASSANDRA_VERSION} to
50+
* Delegate used to provide a Cassandra context for integration tests. This rule can use/spin up either a TestContainer
51+
* or use an external instance. Derives its configuration from {@code /config/cassandra-connection.properties} to
5352
* configure the Cassandra version via Testcontainers.
5453
*
5554
* @author Mark Paluch
@@ -68,8 +67,6 @@ class CassandraDelegate {
6867

6968
private static ResourceHolder resourceHolder;
7069

71-
private final long startupTimeout;
72-
7370
private final CassandraConnectionProperties properties = new CassandraConnectionProperties();
7471

7572
private CqlSession session;
@@ -85,35 +82,6 @@ class CassandraDelegate {
8582

8683
private final Map<SessionCallback<?>, InvocationMode> invocationModeMap = new HashMap<>();
8784

88-
private final String configurationFilename;
89-
90-
/**
91-
* Create a new {@link CassandraDelegate} allowing the use of a config file.
92-
*
93-
* @param yamlConfigurationResource {@link String name} of the configuration resource; must not be {@literal null} or
94-
* {@literal empty}.
95-
* @see #CassandraDelegate(String, long)
96-
*/
97-
public CassandraDelegate(@NonNull String yamlConfigurationResource) {
98-
this(yamlConfigurationResource, EmbeddedCassandraServerHelper.DEFAULT_STARTUP_TIMEOUT_MS);
99-
}
100-
101-
/**
102-
* Constructs a new instance of {@link CassandraDelegate} initialized with the given YAML configuration resource,
103-
* thereby allowing the use of a configuration file and to provide a startup timeout.
104-
*
105-
* @param yamlConfigurationResource {@link String name} of the configuration resource; must not be {@literal null} or
106-
* empty.
107-
* @param startupTimeout long value indicating the startup timeout in milliseconds.
108-
*/
109-
private CassandraDelegate(String yamlConfigurationResource, long startupTimeout) {
110-
111-
Assert.hasText(yamlConfigurationResource, "YAML configuration resource must not be empty");
112-
113-
this.configurationFilename = yamlConfigurationResource;
114-
this.startupTimeout = startupTimeout;
115-
}
116-
11785
/**
11886
* Returns the Cassandra host.
11987
*
@@ -257,36 +225,15 @@ public void before() throws Exception {
257225
private void startCassandraIfNeeded() throws Exception {
258226

259227
if (isStartNeeded()) {
260-
261-
configureRemoteJmxPort();
262-
263-
if (isEmbedded()) {
264-
runEmbeddedCassandra();
265-
} else {
266-
runTestcontainerCassandra();
267-
}
228+
startCassandraContainer();
268229
}
269230
}
270231

271232
private boolean isStartNeeded() {
272-
return isEmbedded() || isTestcontainers();
273-
}
274-
275-
private void configureRemoteJmxPort() {
276-
277-
if (!System.getProperties().containsKey("com.sun.management.jmxremote.port")) {
278-
System.setProperty("com.sun.management.jmxremote.port", "1024");
279-
}
233+
return isTestcontainers();
280234
}
281235

282-
private void runEmbeddedCassandra() throws Exception {
283-
284-
if (this.configurationFilename != null) {
285-
EmbeddedCassandraServerHelper.startEmbeddedCassandra(this.configurationFilename, this.startupTimeout);
286-
}
287-
}
288-
289-
private void runTestcontainerCassandra() {
236+
private void startCassandraContainer() {
290237

291238
if (container == null) {
292239

@@ -382,7 +329,7 @@ private String resolveHost() {
382329
return container.getContainerIpAddress();
383330
}
384331

385-
return isEmbedded() ? EmbeddedCassandraServerHelper.getHost() : this.properties.getCassandraHost();
332+
return this.properties.getCassandraHost();
386333
}
387334

388335
private int resolvePort() {
@@ -391,7 +338,7 @@ private int resolvePort() {
391338
return container.getMappedPort(9042);
392339
}
393340

394-
return isEmbedded() ? EmbeddedCassandraServerHelper.getNativeTransportPort() : this.properties.getCassandraPort();
341+
return this.properties.getCassandraPort();
395342
}
396343

397344
private CqlSession resolveSystemSession() {
@@ -436,10 +383,6 @@ private boolean isClusterReuseEnabled() {
436383
return this.properties.getBoolean("build.cassandra.reuse-cluster");
437384
}
438385

439-
private boolean isEmbedded() {
440-
return CassandraConnectionProperties.CassandraType.EMBEDDED.equals(this.properties.getCassandraType());
441-
}
442-
443386
private boolean isTestcontainers() {
444387
return CassandraConnectionProperties.CassandraType.TESTCONTAINERS.equals(this.properties.getCassandraType());
445388
}

0 commit comments

Comments
 (0)