Skip to content

Commit 364cd81

Browse files
committed
Remove embedded Cassandra integration test mode in favor of Testcontainers.
Closes #1154
1 parent 305d07a commit 364cd81

File tree

8 files changed

+30
-1128
lines changed

8 files changed

+30
-1128
lines changed

pom.xml

Lines changed: 2 additions & 99 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>
@@ -122,24 +122,6 @@
122122
<type>pom</type>
123123
</dependency>
124124

125-
<!-- Test Dependencies -->
126-
<dependency>
127-
<groupId>org.apache.cassandra</groupId>
128-
<artifactId>cassandra-all</artifactId>
129-
<version>${cassandra.version}</version>
130-
<scope>test</scope>
131-
<exclusions>
132-
<exclusion>
133-
<groupId>ch.qos.logback</groupId>
134-
<artifactId>logback-core</artifactId>
135-
</exclusion>
136-
<exclusion>
137-
<groupId>io.netty</groupId>
138-
<artifactId>netty-all</artifactId>
139-
</exclusion>
140-
</exclusions>
141-
</dependency>
142-
143125
<dependency>
144126
<groupId>org.assertj</groupId>
145127
<artifactId>assertj-core</artifactId>
@@ -161,13 +143,6 @@
161143
<scope>import</scope>
162144
</dependency>
163145

164-
<dependency>
165-
<groupId>org.xerial.snappy</groupId>
166-
<artifactId>snappy-java</artifactId>
167-
<version>1.1.10.5</version>
168-
<scope>test</scope>
169-
</dependency>
170-
171146
<dependency>
172147
<groupId>edu.umd.cs.mtc</groupId>
173148
<artifactId>multithreadedtc</artifactId>
@@ -178,29 +153,8 @@
178153
</dependencies>
179154
</dependencyManagement>
180155

181-
<dependencies>
182-
<dependency>
183-
<groupId>org.assertj</groupId>
184-
<artifactId>assertj-core</artifactId>
185-
<scope>test</scope>
186-
</dependency>
187-
</dependencies>
188-
189156
<build>
190157
<plugins>
191-
<plugin>
192-
<groupId>org.bitstrings.maven.plugins</groupId>
193-
<artifactId>dependencypath-maven-plugin</artifactId>
194-
<version>1.1.1</version>
195-
<executions>
196-
<execution>
197-
<id>set-all</id>
198-
<goals>
199-
<goal>set</goal>
200-
</goals>
201-
</execution>
202-
</executions>
203-
</plugin>
204158
<plugin>
205159
<groupId>org.apache.maven.plugins</groupId>
206160
<artifactId>maven-dependency-plugin</artifactId>
@@ -221,11 +175,6 @@
221175
<exclude>**/**IntegrationTests</exclude>
222176
<exclude>**/test/performance/**/*</exclude>
223177
</excludes>
224-
<systemPropertyVariables>
225-
<java.util.logging.config.file>
226-
src/test/resources/logging.properties
227-
</java.util.logging.config.file>
228-
</systemPropertyVariables>
229178
</configuration>
230179
</plugin>
231180
<plugin>
@@ -245,11 +194,6 @@
245194
<exclude>**/*UnitTests</exclude>
246195
<exclude>**/test/performance/**/*</exclude>
247196
</excludes>
248-
<systemPropertyVariables>
249-
<java.util.logging.config.file>
250-
src/test/resources/logging.properties
251-
</java.util.logging.config.file>
252-
</systemPropertyVariables>
253197
</configuration>
254198
<executions>
255199
<execution>
@@ -293,50 +237,9 @@
293237
</build>
294238

295239
<profiles>
296-
<profile>
297-
<id>embedded-cassandra</id>
298-
299-
<activation>
300-
<activeByDefault>true</activeByDefault>
301-
</activation>
302-
303-
<properties>
304-
<build.cassandra.mode>embedded</build.cassandra.mode>
305-
</properties>
306-
307-
<build>
308-
<plugins>
309-
<plugin>
310-
<!-- Random port generation requires embedded-cassandra.yaml and cassandra-connection.properties
311-
in both modules -->
312-
<groupId>org.codehaus.mojo</groupId>
313-
<artifactId>build-helper-maven-plugin</artifactId>
314-
<version>1.8</version>
315-
<executions>
316-
<execution>
317-
<id>reserve-network-port</id>
318-
<goals>
319-
<goal>reserve-network-port</goal>
320-
</goals>
321-
<phase>generate-test-resources</phase>
322-
<configuration>
323-
<portNames>
324-
<portName>build.cassandra.native_transport_port
325-
</portName>
326-
<portName>build.cassandra.rpc_port</portName>
327-
<portName>build.cassandra.storage_port</portName>
328-
<portName>build.cassandra.ssl_storage_port
329-
</portName>
330-
</portNames>
331-
</configuration>
332-
</execution>
333-
</executions>
334-
</plugin>
335-
</plugins>
336-
</build>
337-
</profile>
338240
<profile>
339241
<id>external-cassandra</id>
242+
340243
<properties>
341244
<build.cassandra.mode>external</build.cassandra.mode>
342245
<build.cassandra.native_transport_port>9042</build.cassandra.native_transport_port>

spring-data-cassandra/pom.xml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,36 +162,12 @@
162162
<scope>test</scope>
163163
</dependency>
164164

165-
<dependency>
166-
<groupId>org.apache.cassandra</groupId>
167-
<artifactId>cassandra-all</artifactId>
168-
<exclusions>
169-
<exclusion>
170-
<groupId>javax.inject</groupId>
171-
<artifactId>javax.inject</artifactId>
172-
</exclusion>
173-
<exclusion>
174-
<groupId>org.perfkit.sjk.parsers</groupId>
175-
<artifactId>*</artifactId>
176-
</exclusion>
177-
<exclusion>
178-
<groupId>com.jrockit.mc</groupId>
179-
<artifactId>*</artifactId>
180-
</exclusion>
181-
</exclusions>
182-
</dependency>
183-
184165
<dependency>
185166
<groupId>org.testcontainers</groupId>
186167
<artifactId>cassandra</artifactId>
187168
<scope>test</scope>
188169
</dependency>
189170

190-
<dependency>
191-
<groupId>org.xerial.snappy</groupId>
192-
<artifactId>snappy-java</artifactId>
193-
</dependency>
194-
195171
<dependency>
196172
<groupId>com.fasterxml.jackson.core</groupId>
197173
<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
@@ -46,9 +46,8 @@
4646
import com.datastax.oss.driver.api.core.metadata.Node;
4747

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

6867
private static ResourceHolder resourceHolder;
6968

70-
private final long startupTimeout;
71-
7269
private final CassandraConnectionProperties properties = new CassandraConnectionProperties();
7370

7471
private CqlSession session;
@@ -84,35 +81,6 @@ class CassandraDelegate {
8481

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

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

258226
if (isStartNeeded()) {
259-
260-
configureRemoteJmxPort();
261-
262-
if (isEmbedded()) {
263-
runEmbeddedCassandra();
264-
} else {
265-
runTestcontainerCassandra();
266-
}
227+
startCassandraContainer();
267228
}
268229
}
269230

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

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

290237
if (container == null) {
291238

@@ -381,7 +328,7 @@ private String resolveHost() {
381328
return container.getContainerIpAddress();
382329
}
383330

384-
return isEmbedded() ? EmbeddedCassandraServerHelper.getHost() : this.properties.getCassandraHost();
331+
return this.properties.getCassandraHost();
385332
}
386333

387334
private int resolvePort() {
@@ -390,7 +337,7 @@ private int resolvePort() {
390337
return container.getMappedPort(9042);
391338
}
392339

393-
return isEmbedded() ? EmbeddedCassandraServerHelper.getNativeTransportPort() : this.properties.getCassandraPort();
340+
return this.properties.getCassandraPort();
394341
}
395342

396343
private CqlSession resolveSystemSession() {
@@ -435,10 +382,6 @@ private boolean isClusterReuseEnabled() {
435382
return this.properties.getBoolean("build.cassandra.reuse-cluster");
436383
}
437384

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

0 commit comments

Comments
 (0)