fix(cassandra): omit empty keyspace in jdbc url
This commit is contained in:
1 parent
cec17844a9
commit
6529f22fed
2 files changed
+23
-2
No files matched your search
@@ -159,8 +159,11 @@ public final class CassandraAgent extends AbstractJdbcAgent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String buildUrl(ConnectParams params) {
|
static String buildUrl(ConnectParams params) {
|
||||||
return "jdbc:cassandra://" + params.getHost() + ":" + params.getPort() + "/" + params.getDatabase();
|
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) {
|
private static List<String> targetColumns(String options) {
|
||||||
|
|||||||
+18
@@ -1,7 +1,11 @@
|
|||||||
package com.dbx.agent.cassandra;
|
package com.dbx.agent.cassandra;
|
||||||
|
|
||||||
|
import com.dbx.agent.ConnectParams;
|
||||||
import com.dbx.agent.DatabaseAgent;
|
import com.dbx.agent.DatabaseAgent;
|
||||||
import com.dbx.agent.test.JdbcFakeExecutionBehaviorTest;
|
import com.dbx.agent.test.JdbcFakeExecutionBehaviorTest;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
class CassandraAgentTest extends JdbcFakeExecutionBehaviorTest {
|
class CassandraAgentTest extends JdbcFakeExecutionBehaviorTest {
|
||||||
@Override
|
@Override
|
||||||
@@ -13,4 +17,18 @@ class CassandraAgentTest extends JdbcFakeExecutionBehaviorTest {
|
|||||||
protected String resultSetSql() {
|
protected String resultSetSql() {
|
||||||
return "LIST ROLES";
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user