{"record":{"id":"2a0f71193b275338","repo":"testcontainers/testcontainers-java","slug":"could-not-obtain-cassandra-connection","errorCode":null,"errorMessage":"Could not obtain cassandra connection","messagePattern":"Could not obtain cassandra connection","errorType":"exception","errorClass":"ConnectionCreationException","httpStatus":null,"severity":"error","filePath":"modules/cassandra/src/main/java/org/testcontainers/containers/delegate/CassandraDatabaseDelegate.java","lineNumber":32,"sourceCode":"/**\n * Cassandra database delegate\n *\n * @deprecated use {@link org.testcontainers.cassandra.CassandraDatabaseDelegate} instead.\n */\n@Slf4j\n@RequiredArgsConstructor\n@Deprecated\npublic class CassandraDatabaseDelegate extends AbstractDatabaseDelegate<Session> {\n\n    private final ContainerState container;\n\n    @Override\n    protected Session createNewConnection() {\n        try {\n            return CassandraContainer.getCluster(container).newSession();\n        } catch (DriverException e) {\n            log.error(\"Could not obtain cassandra connection\");\n            throw new ConnectionCreationException(\"Could not obtain cassandra connection\", e);\n        }\n    }\n\n    @Override\n    public void execute(\n        String statement,\n        String scriptPath,\n        int lineNumber,\n        boolean continueOnError,\n        boolean ignoreFailedDrops\n    ) {\n        try {\n            ResultSet result = getConnection().execute(statement);\n            if (result.wasApplied()) {\n                log.debug(\"Statement {} was applied\", statement);\n            } else {\n                throw new ScriptStatementFailedException(statement, lineNumber, scriptPath);\n            }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cassandra/src/main/java/org/testcontainers/containers/delegate/CassandraDatabaseDelegate.java#L14-L50","documentation":"CassandraDatabaseDelegate.createNewConnection builds a CQL Session from the container's cluster via CassandraContainer.getCluster(container). If the DataStax driver throws a DriverException (contact point unreachable, protocol/auth failure, node not ready), it logs 'Could not obtain cassandra connection' and throws ConnectionCreationException.","triggerScenarios":"Any execute() call on CassandraDatabaseDelegate (used by CassandraQueryWaitStrategy or runInitScriptIfRequired) when cluster.connect()/newSession() raises DriverException.","commonSituations":"Querying too early before Cassandra is listening on 9042; driver/container CQL protocol version mismatch; auth credentials configured in the image but not in the delegate; network/NAT issues on non-Linux Docker setups.","solutions":["Wait for the container to accept connections (proper wait strategy) before executing queries","Verify the container is running and the mapped CQL port: container.getMappedPort(9042)","Check image version compatibility with the bundled DataStax driver; use a supported Cassandra image","Inspect the wrapped DriverException cause for auth/protocol details"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure the container is running and CQL port is mapped before querying\nif (!container.isRunning()) throw new IllegalStateException(\"container not started\");\ncontainer.getMappedPort(9042);","typeGuard":null,"tryCatchPattern":"try { delegate.execute(\"SELECT now() FROM system.local\", 1, \"probe\", null, false, false); } catch (ConnectionCreationException e) { /* check DriverException cause, backoff-retry */ }","preventionTips":["Use a proper wait strategy before executing queries","Match the driver protocol with the Cassandra image version","Check mapped port 9042 connectivity on non-Linux Docker"],"tags":["cassandra","testcontainers","connection","driver-exception"],"backgroundTag":"connection-refused","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}