Skip to content

Commit

Permalink
Merge pull request #2 from yugabyte/unit-test-fixes
Browse files Browse the repository at this point in the history
Fix test failures of bad url input
  • Loading branch information
ashetkar committed Sep 28, 2022
2 parents 5f45494 + 56c666c commit f819dbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/ing/data/cassandra/jdbc/Utils.java
Expand Up @@ -264,9 +264,9 @@ public static Properties parseURL(final String url) throws SQLException {

if (!isDbaasConnection) {
host = uri.getHost();
String[] hostsStr = rawUri.split("/");
if (host == null) {
if (!hostsStr[2].contains("--")) {
String[] hostsStr = rawUri.split("/");
if (hostsStr.length < 3 || !hostsStr[2].contains("--")) {
throw new SQLNonTransientConnectionException("Connection url must specify a host, e.g. jdbc:cassandra://localhost:9042/keyspace");
}

Expand Down Expand Up @@ -386,12 +386,12 @@ public static String createSubName(final Properties props) throws SQLException {
}

String host = props.getProperty(TAG_SERVER_NAME);
if (host.contains("--")) {
host = host.split("--")[0];
}
if (host == null) {
throw new SQLNonTransientConnectionException(HOST_REQUIRED);
}
if (host.contains("--")) {
host = host.split("--")[0];
}

// Build a valid URI from parts.
final URI uri;
Expand Down
Expand Up @@ -35,6 +35,7 @@
import com.ing.data.cassandra.jdbc.utils.FakeReconnectionPolicy;
import com.ing.data.cassandra.jdbc.utils.FakeRetryPolicy;
import com.ing.data.cassandra.jdbc.utils.FakeSslEngineFactory;
import com.yugabyte.oss.driver.internal.core.loadbalancing.PartitionAwarePolicy;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -155,7 +156,7 @@ void givenNoLoadBalancingPolicy_whenGetConnection_createConnectionWithExpectedCo
final LoadBalancingPolicy loadBalancingPolicy = sqlConnection.getSession().getContext()
.getLoadBalancingPolicy(DriverExecutionProfile.DEFAULT_NAME);
assertNotNull(loadBalancingPolicy);
assertThat(loadBalancingPolicy, instanceOf(DefaultLoadBalancingPolicy.class));
assertThat(loadBalancingPolicy, instanceOf(PartitionAwarePolicy.class));
sqlConnection.close();
}

Expand Down

0 comments on commit f819dbb

Please sign in to comment.