24
24
25
25
import org .slf4j .Logger ;
26
26
import org .slf4j .LoggerFactory ;
27
+
27
28
import org .springframework .data .cassandra .core .cql .SessionCallback ;
28
29
import org .springframework .data .cassandra .support .CassandraConnectionProperties ;
29
30
import org .springframework .data .cassandra .support .CqlDataSet ;
31
+ import org .springframework .data .util .Optionals ;
30
32
import org .springframework .lang .NonNull ;
31
33
import org .springframework .util .Assert ;
32
34
import org .springframework .util .StringUtils ;
35
+
33
36
import org .testcontainers .containers .CassandraContainer ;
37
+ import org .testcontainers .utility .DockerImageName ;
38
+ import org .testcontainers .utility .MountableFile ;
34
39
35
40
import com .datastax .oss .driver .api .core .CqlIdentifier ;
36
41
import com .datastax .oss .driver .api .core .CqlSession ;
@@ -273,6 +278,14 @@ private void runTestcontainerCassandra() {
273
278
274
279
container = getCassandraDockerImageName ().map (CassandraContainer ::new ).orElseGet (CassandraContainer ::new );
275
280
281
+ DockerImageName imageName = DockerImageName .parse (container .getDockerImageName ());
282
+ String versionPart = imageName .getVersionPart ();
283
+ Version version = Version .parse (versionPart );
284
+
285
+ if (version .getMajor () >= 5 ) {
286
+ container .withCopyToContainer (MountableFile .forClasspathResource ("testcontainer-cassandra-v5.yaml" ),
287
+ "/etc/cassandra/cassandra.yaml" );
288
+ }
276
289
container .start ();
277
290
278
291
log .info ("Running with Cassandra Docker Testcontainer Image Name [{}]" , container .getDockerImageName ());
@@ -290,8 +303,8 @@ private Optional<String> getCassandraDockerImageName() {
290
303
291
304
private Optional <String > resolveCassandraVersion () {
292
305
293
- return Optional .ofNullable (System .getProperty ( "cassandra.version" , System . getenv ("CASSANDRA_VERSION" )))
294
- .filter (StringUtils ::hasText );
306
+ return Optionals . firstNonEmpty (() -> Optional .ofNullable (System .getenv ("CASSANDRA_VERSION" )),
307
+ () -> Optional . ofNullable ( System . getProperty ( "cassandra.version" ))) .filter (StringUtils ::hasText );
295
308
}
296
309
297
310
private synchronized void initializeConnection () {
@@ -392,7 +405,7 @@ private void executeAfterHooks() {
392
405
393
406
private synchronized void releaseConnection () {
394
407
395
- if (resourceHolder == null ) {
408
+ if (resourceHolder == null && this . session != null ) {
396
409
this .session .close ();
397
410
}
398
411
0 commit comments