Skip to content

Commit cf4be04

Browse files
ruhan1claude
andcommitted
Fix CassandraTestResource compilation error
Use withInitScript() instead of getSession() which doesn't exist in CassandraContainer API. This is the proper way to load init scripts with testcontainers. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 84eb557 commit cf4be04

1 file changed

Lines changed: 2 additions & 24 deletions

File tree

src/test/java/org/commonjava/service/storage/util/CassandraTestResource.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,20 @@
1919
import org.testcontainers.containers.CassandraContainer;
2020
import org.testcontainers.utility.DockerImageName;
2121

22-
import java.io.IOException;
23-
import java.nio.file.Files;
24-
import java.nio.file.Paths;
2522
import java.util.HashMap;
2623
import java.util.Map;
2724

2825
public class CassandraTestResource implements QuarkusTestResourceLifecycleManager {
2926

3027
static DockerImageName dockerImageName = DockerImageName.parse("cassandra:3.11.10");
3128
static CassandraContainer<?> cassandraContainer = new CassandraContainer<>(dockerImageName)
32-
.withExposedPorts(9042);
29+
.withExposedPorts(9042)
30+
.withInitScript("cql/load.cql");
3331

3432
@Override
3533
public Map<String, String> start() {
3634
cassandraContainer.start();
3735

38-
// Load CQL script if it exists
39-
try {
40-
String scriptPath = "src/test/resources/cql/load.cql";
41-
if (Files.exists(Paths.get(scriptPath))) {
42-
String cqlScript = Files.readString(Paths.get(scriptPath)).trim();
43-
if (!cqlScript.isEmpty()) {
44-
// Split by semicolon and execute each statement
45-
String[] statements = cqlScript.split(";");
46-
for (String statement : statements) {
47-
String trimmed = statement.trim();
48-
if (!trimmed.isEmpty() && !trimmed.startsWith("--") && !trimmed.startsWith("//")) {
49-
cassandraContainer.getSession().execute(trimmed);
50-
}
51-
}
52-
}
53-
}
54-
} catch (IOException e) {
55-
// Script loading is optional, continue without it
56-
}
57-
5836
HashMap<String, String> map = new HashMap<>();
5937
map.put("cassandra.host", cassandraContainer.getHost());
6038
map.put("cassandra.port", String.valueOf(cassandraContainer.getMappedPort(9042)));

0 commit comments

Comments
 (0)