Skip to content

Commit

Permalink
FMWK-587 Return null for inapplicable URLs in driver connect (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored Oct 30, 2024
1 parent 5fb1b8c commit 36de5ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/main/java/com/aerospike/jdbc/AerospikeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class AerospikeDriver implements Driver {

private static final Logger logger = Logger.getLogger("com.aerospike.jdbc");
private static final String AEROSPIKE_URL_PREFIX = "jdbc:aerospike:";

static {
try {
Expand All @@ -33,12 +34,19 @@ public class AerospikeDriver implements Driver {
Log.setCallback(asLoggerCallback);
}

public Connection connect(String url, Properties info) {
public Connection connect(String url, Properties info) throws SQLException {
if (url == null) {
throw new SQLException("url is null");
}
if (!url.startsWith(AEROSPIKE_URL_PREFIX)) {
return null;
}

return new AerospikeConnection(url, info);
}

public boolean acceptsURL(String url) {
return Objects.nonNull(url) && url.startsWith("jdbc:aerospike:");
return Objects.nonNull(url) && url.startsWith(AEROSPIKE_URL_PREFIX);
}

public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/aerospike/jdbc/ParseJdbcUrlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;

public class ParseJdbcUrlTest {
Expand Down Expand Up @@ -70,6 +71,14 @@ public void testParseUrlParameters() throws Exception {
assertEquals(config.getDriverPolicy().getRecordSetTimeoutMs(), 7000);
}

@Test
public void testInapplicableUrl() throws Exception {
AerospikeDriver driver = (AerospikeDriver) Class.forName("com.aerospike.jdbc.AerospikeDriver")
.newInstance();
String url = "jdbc:postgresql://localhost:5432/sample";
assertNull(driver.connect(url, new Properties()));
}

private void assertTotalTimeoutAll(IAerospikeClient client, int timeout) {
assertEquals(client.getReadPolicyDefault().totalTimeout, timeout);
assertEquals(client.getWritePolicyDefault().totalTimeout, timeout);
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/aerospike/jdbc/RecordMetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public void testSelectAllColumns() throws SQLException {
assertTrue(resultSet.next());
assertEquals(resultSet.getString(METADATA_DIGEST_COLUMN_NAME), "212ddf97ff3fe0f6dec5e1626d92a635a55171c2");
assertEquals(resultSet.getInt(METADATA_GEN_COLUMN_NAME), 1);
assertTrue(resultSet.getInt(METADATA_TTL_COLUMN_NAME) > 0);
assertFalse(resultSet.next());
} finally {
closeQuietly(statement);
Expand All @@ -119,7 +118,6 @@ public void testSelectMetadataColumns() throws SQLException {
assertTrue(resultSet.next());
assertNull(resultSet.getObject(METADATA_DIGEST_COLUMN_NAME));
assertEquals(resultSet.getInt(METADATA_GEN_COLUMN_NAME), 1);
assertTrue(resultSet.getInt(METADATA_TTL_COLUMN_NAME) > 0);
assertEquals(resultSet.getInt("int1"), 11100);
assertFalse(resultSet.next());
} finally {
Expand Down

0 comments on commit 36de5ea

Please sign in to comment.