fix(cassandra): omit empty keyspace in jdbc url
This commit is contained in:
parent
cec17844a9
commit
6529f22fed
|
|
@ -159,8 +159,11 @@ public final class CassandraAgent extends AbstractJdbcAgent {
|
|||
});
|
||||
}
|
||||
|
||||
private static String buildUrl(ConnectParams params) {
|
||||
return "jdbc:cassandra://" + params.getHost() + ":" + params.getPort() + "/" + params.getDatabase();
|
||||
static String buildUrl(ConnectParams params) {
|
||||
String baseUrl = "jdbc:cassandra://" + params.getHost() + ":" + params.getPort();
|
||||
String keyspace = coalesce(params.getDatabase()).trim();
|
||||
// Cassandra rejects an empty keyspace path; omit it so DBX can connect first and list keyspaces.
|
||||
return keyspace.isEmpty() ? baseUrl : baseUrl + "/" + keyspace;
|
||||
}
|
||||
|
||||
private static List<String> targetColumns(String options) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
package com.dbx.agent.cassandra;
|
||||
|
||||
import com.dbx.agent.ConnectParams;
|
||||
import com.dbx.agent.DatabaseAgent;
|
||||
import com.dbx.agent.test.JdbcFakeExecutionBehaviorTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class CassandraAgentTest extends JdbcFakeExecutionBehaviorTest {
|
||||
@Override
|
||||
|
|
@ -13,4 +17,18 @@ class CassandraAgentTest extends JdbcFakeExecutionBehaviorTest {
|
|||
protected String resultSetSql() {
|
||||
return "LIST ROLES";
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildsServerUrlWhenKeyspaceIsEmpty() {
|
||||
ConnectParams params = new ConnectParams("127.0.0.1", 9042, "", "cassandra", "cassandra", "", "", false);
|
||||
|
||||
assertEquals("jdbc:cassandra://127.0.0.1:9042", CassandraAgent.buildUrl(params));
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildsKeyspaceUrlWhenKeyspaceIsSet() {
|
||||
ConnectParams params = new ConnectParams("127.0.0.1", 9042, "app_keyspace", "cassandra", "cassandra", "", "", false);
|
||||
|
||||
assertEquals("jdbc:cassandra://127.0.0.1:9042/app_keyspace", CassandraAgent.buildUrl(params));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue