-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make connectionTimeoutMs
configurable
#15226
Merged
+127
−50
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0fd7a77
Extract connectionTimeout from jdbc_url_params along with correspondi…
ryankfu c50a093
Fixed linter issues
ryankfu 73c0abc
Reverted createDataSourceWithConnectionTimeout and migrated logic to …
ryankfu b3aff09
Fixed dangling createDataSourceWithConnectionTimeout and linter issues
ryankfu 81790a4
Fixed import to use java standard library
ryankfu 03251c4
Bump Postgres Source and Postgres Source Strict Encrypt versions
ryankfu 590b9ab
Fixed import ordering issues
ryankfu e10e0a0
Bumped the connector version [CI fix] for definitions not generated
ryankfu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,20 +15,94 @@ | |
import java.util.Map; | ||
import javax.sql.DataSource; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test suite for the {@link DataSourceFactory} class. | ||
*/ | ||
class DataSourceFactoryTest extends CommonFactoryTest { | ||
|
||
static String database; | ||
static String driverClassName; | ||
static String host; | ||
static String jdbcUrl; | ||
static String password; | ||
static Integer port; | ||
static String username; | ||
|
||
@BeforeAll | ||
static void setup() { | ||
host = container.getHost(); | ||
port = container.getFirstMappedPort(); | ||
database = container.getDatabaseName(); | ||
username = container.getUsername(); | ||
password = container.getPassword(); | ||
driverClassName = container.getDriverClassName(); | ||
jdbcUrl = container.getJdbcUrl(); | ||
} | ||
|
||
@Test | ||
void testCreatingADataSourceWithJdbcUrl() { | ||
final String username = container.getUsername(); | ||
final String password = container.getPassword(); | ||
final String driverClassName = container.getDriverClassName(); | ||
final String jdbcUrl = container.getJdbcUrl(); | ||
void testCreatingDataSourceWithConnectionTimeoutSetAboveDefault() { | ||
final Map<String, String> connectionProperties = Map.of( | ||
"connectTimeout", "61"); | ||
final DataSource dataSource = DataSourceFactory.create( | ||
username, | ||
password, | ||
driverClassName, | ||
jdbcUrl, | ||
connectionProperties); | ||
assertNotNull(dataSource); | ||
assertEquals(HikariDataSource.class, dataSource.getClass()); | ||
assertEquals(61000, ((HikariDataSource) dataSource).getHikariConfigMXBean().getConnectionTimeout()); | ||
} | ||
|
||
@Test | ||
void testCreatingDataSourceWithConnectionTimeoutSetBelowDefault() { | ||
final Map<String, String> connectionProperties = Map.of( | ||
"connectTimeout", "30"); | ||
final DataSource dataSource = DataSourceFactory.create( | ||
username, | ||
password, | ||
driverClassName, | ||
jdbcUrl, | ||
connectionProperties); | ||
assertNotNull(dataSource); | ||
assertEquals(HikariDataSource.class, dataSource.getClass()); | ||
assertEquals(60000, ((HikariDataSource) dataSource).getHikariConfigMXBean().getConnectionTimeout()); | ||
} | ||
|
||
@Test | ||
void testCreatingDataSourceWithConnectionTimeoutSetWithZero() { | ||
final Map<String, String> connectionProperties = Map.of( | ||
"connectTimeout", "0"); | ||
final DataSource dataSource = DataSourceFactory.create( | ||
username, | ||
password, | ||
driverClassName, | ||
jdbcUrl, | ||
connectionProperties); | ||
assertNotNull(dataSource); | ||
assertEquals(HikariDataSource.class, dataSource.getClass()); | ||
assertEquals(Integer.MAX_VALUE, ((HikariDataSource) dataSource).getHikariConfigMXBean().getConnectionTimeout()); | ||
} | ||
|
||
@Test | ||
void testCreatingDataSourceWithConnectionTimeoutNotSet() { | ||
final Map<String, String> connectionProperties = Map.of(); | ||
final DataSource dataSource = DataSourceFactory.create( | ||
username, | ||
password, | ||
driverClassName, | ||
jdbcUrl, | ||
connectionProperties); | ||
assertNotNull(dataSource); | ||
assertEquals(HikariDataSource.class, dataSource.getClass()); | ||
assertEquals(60000, ((HikariDataSource) dataSource).getHikariConfigMXBean().getConnectionTimeout()); | ||
} | ||
|
||
@Test | ||
void testCreatingADataSourceWithJdbcUrl() { | ||
final DataSource dataSource = DataSourceFactory.create(username, password, driverClassName, jdbcUrl); | ||
assertNotNull(dataSource); | ||
assertEquals(HikariDataSource.class, dataSource.getClass()); | ||
|
@@ -37,10 +111,6 @@ void testCreatingADataSourceWithJdbcUrl() { | |
|
||
@Test | ||
void testCreatingADataSourceWithJdbcUrlAndConnectionProperties() { | ||
final String username = container.getUsername(); | ||
final String password = container.getPassword(); | ||
final String driverClassName = container.getDriverClassName(); | ||
final String jdbcUrl = container.getJdbcUrl(); | ||
final Map<String, String> connectionProperties = Map.of("foo", "bar"); | ||
|
||
final DataSource dataSource = DataSourceFactory.create(username, password, driverClassName, jdbcUrl, connectionProperties); | ||
|
@@ -51,13 +121,6 @@ void testCreatingADataSourceWithJdbcUrlAndConnectionProperties() { | |
|
||
@Test | ||
void testCreatingADataSourceWithHostAndPort() { | ||
final String username = container.getUsername(); | ||
final String password = container.getPassword(); | ||
final String driverClassName = container.getDriverClassName(); | ||
final String host = container.getHost(); | ||
final Integer port = container.getFirstMappedPort(); | ||
final String database = container.getDatabaseName(); | ||
|
||
final DataSource dataSource = DataSourceFactory.create(username, password, host, port, database, driverClassName); | ||
assertNotNull(dataSource); | ||
assertEquals(HikariDataSource.class, dataSource.getClass()); | ||
|
@@ -66,12 +129,6 @@ void testCreatingADataSourceWithHostAndPort() { | |
|
||
@Test | ||
void testCreatingADataSourceWithHostPortAndConnectionProperties() { | ||
final String username = container.getUsername(); | ||
final String password = container.getPassword(); | ||
final String driverClassName = container.getDriverClassName(); | ||
final String host = container.getHost(); | ||
final Integer port = container.getFirstMappedPort(); | ||
final String database = container.getDatabaseName(); | ||
final Map<String, String> connectionProperties = Map.of("foo", "bar"); | ||
|
||
final DataSource dataSource = DataSourceFactory.create(username, password, host, port, database, driverClassName, connectionProperties); | ||
|
@@ -82,12 +139,7 @@ void testCreatingADataSourceWithHostPortAndConnectionProperties() { | |
|
||
@Test | ||
void testCreatingAnInvalidDataSourceWithHostAndPort() { | ||
final String username = container.getUsername(); | ||
final String password = container.getPassword(); | ||
final String driverClassName = "Unknown"; | ||
final String host = container.getHost(); | ||
final Integer port = container.getFirstMappedPort(); | ||
final String database = container.getDatabaseName(); | ||
|
||
assertThrows(RuntimeException.class, () -> { | ||
DataSourceFactory.create(username, password, host, port, database, driverClassName); | ||
|
@@ -96,12 +148,6 @@ void testCreatingAnInvalidDataSourceWithHostAndPort() { | |
|
||
@Test | ||
void testCreatingAPostgresqlDataSource() { | ||
final String username = container.getUsername(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job removing out copy-pasta |
||
final String password = container.getPassword(); | ||
final String host = container.getHost(); | ||
final Integer port = container.getFirstMappedPort(); | ||
final String database = container.getDatabaseName(); | ||
|
||
final DataSource dataSource = DataSourceFactory.createPostgres(username, password, host, port, database); | ||
assertNotNull(dataSource); | ||
assertEquals(HikariDataSource.class, dataSource.getClass()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job on making the comments readable and informative.