Skip to content

Commit 9c3719e

Browse files
fix: update aurora pg topology query to also return instances with null last_update_timestamp (#595)
1 parent 0ebbda7 commit 9c3719e

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

wrapper/src/main/java/software/amazon/jdbc/dialect/AuroraPgDialect.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public class AuroraPgDialect extends PgDialect {
4242
+ "CPU, COALESCE(REPLICA_LAG_IN_MSEC, 0), LAST_UPDATE_TIMESTAMP "
4343
+ "FROM aurora_replica_status() "
4444
// filter out nodes that haven't been updated in the last 5 minutes
45-
+ "WHERE EXTRACT(EPOCH FROM(NOW() - LAST_UPDATE_TIMESTAMP)) <= 300 OR SESSION_ID = 'MASTER_SESSION_ID' ";
45+
+ "WHERE EXTRACT(EPOCH FROM(NOW() - LAST_UPDATE_TIMESTAMP)) <= 300 OR SESSION_ID = 'MASTER_SESSION_ID' "
46+
+ "OR LAST_UPDATE_TIMESTAMP IS NULL";
4647

4748
private static final String NODE_ID_QUERY = "SELECT aurora_db_instance_identifier()";
4849
private static final String IS_READER_QUERY = "SELECT pg_is_in_recovery()";
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package integration.container.tests;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
21+
22+
import integration.DatabaseEngineDeployment;
23+
import integration.DriverHelper;
24+
import integration.TestEnvironmentFeatures;
25+
import integration.container.ConnectionStringHelper;
26+
import integration.container.TestDriver;
27+
import integration.container.TestDriverProvider;
28+
import integration.container.TestEnvironment;
29+
import integration.container.condition.DisableOnTestFeature;
30+
import integration.container.condition.EnableOnDatabaseEngineDeployment;
31+
import integration.container.condition.EnableOnNumOfInstances;
32+
import java.sql.Connection;
33+
import java.sql.DriverManager;
34+
import java.sql.ResultSet;
35+
import java.sql.SQLException;
36+
import java.sql.Statement;
37+
import java.util.Properties;
38+
import java.util.concurrent.TimeUnit;
39+
import java.util.logging.Logger;
40+
import org.junit.jupiter.api.MethodOrderer;
41+
import org.junit.jupiter.api.TestMethodOrder;
42+
import org.junit.jupiter.api.TestTemplate;
43+
import org.junit.jupiter.api.extension.ExtendWith;
44+
import software.amazon.jdbc.PropertyDefinition;
45+
46+
@TestMethodOrder(MethodOrderer.MethodName.class)
47+
@ExtendWith(TestDriverProvider.class)
48+
@EnableOnNumOfInstances(min = 2)
49+
@EnableOnDatabaseEngineDeployment(DatabaseEngineDeployment.AURORA)
50+
@DisableOnTestFeature({
51+
TestEnvironmentFeatures.PERFORMANCE,
52+
TestEnvironmentFeatures.RUN_HIBERNATE_TESTS_ONLY,
53+
TestEnvironmentFeatures.RUN_AUTOSCALING_TESTS_ONLY})
54+
public class AuroraConnectivityTests {
55+
56+
private static final Logger LOGGER = Logger.getLogger(AuroraConnectivityTests.class.getName());
57+
58+
@TestTemplate
59+
@ExtendWith(TestDriverProvider.class)
60+
public void test_WrapperConnectionReaderClusterWithEfmEnabled(TestDriver testDriver) throws SQLException {
61+
LOGGER.info(testDriver.toString());
62+
63+
final Properties props = new Properties();
64+
props.setProperty(
65+
PropertyDefinition.USER.name,
66+
TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername());
67+
props.setProperty(
68+
PropertyDefinition.PASSWORD.name,
69+
TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword());
70+
DriverHelper.setConnectTimeout(testDriver, props, 10, TimeUnit.SECONDS);
71+
DriverHelper.setSocketTimeout(testDriver, props, 10, TimeUnit.SECONDS);
72+
props.setProperty(PropertyDefinition.PLUGINS.name, "efm");
73+
74+
String url = ConnectionStringHelper.getWrapperReaderClusterUrl();
75+
LOGGER.finest("Connecting to " + url);
76+
77+
try (final Connection conn = DriverManager.getConnection(url, props)) {
78+
assertTrue(conn.isValid(5));
79+
80+
Statement stmt = conn.createStatement();
81+
stmt.executeQuery("SELECT 1");
82+
ResultSet rs = stmt.getResultSet();
83+
rs.next();
84+
assertEquals(1, rs.getInt(1));
85+
}
86+
}
87+
}

wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
import software.amazon.jdbc.HikariPooledConnectionProvider;
6666
import software.amazon.jdbc.PropertyDefinition;
6767
import software.amazon.jdbc.hostlistprovider.AuroraHostListProvider;
68-
import software.amazon.jdbc.hostlistprovider.ConnectionStringHostListProvider;
6968
import software.amazon.jdbc.plugin.failover.FailoverConnectionPlugin;
7069
import software.amazon.jdbc.plugin.failover.FailoverFailedSQLException;
7170
import software.amazon.jdbc.plugin.failover.FailoverSuccessSQLException;

wrapper/src/test/java/integration/util/AuroraTestUtility.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class AuroraTestUtility {
9292
private String dbName = "test";
9393
private String dbIdentifier = "test-identifier";
9494
private String dbEngine = "aurora-postgresql";
95-
private String dbEngineVersion = "13.7";
95+
private String dbEngineVersion = "13.9";
9696
private String dbInstanceClass = "db.r5.large";
9797
private final Region dbRegion;
9898
private final String dbSecGroup = "default";

0 commit comments

Comments
 (0)