-
Notifications
You must be signed in to change notification settings - Fork 53
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
chore: add new integration tests to ensure topology query doesn't change #910
base: main
Are you sure you want to change the base?
Changes from all commits
a977881
afe5167
694c36b
65e3e50
e7f5ea6
bea1635
ee23e30
82d0685
32678e0
cc7ee06
b356f63
9001d9f
ae00e64
c728df6
4025f3a
66249f6
0830cf8
33cae6c
e3cb6f6
90e5366
f5e5c69
5ee6c57
03d71d8
df4ebd4
03eb786
90b47d6
d617b72
09496af
9562e11
53237a1
6f4ded8
c22a97f
65174ef
0edb182
83ed69d
2681ddf
5fb7f9f
93895c3
8c8e667
e094029
89efa7e
adb82b3
06ba1bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package integration.container.tests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import integration.DatabaseEngine; | ||
import integration.DatabaseEngineDeployment; | ||
import integration.DriverHelper; | ||
import integration.TestEnvironmentFeatures; | ||
import integration.container.ConnectionStringHelper; | ||
import integration.container.TestDriver; | ||
import integration.container.TestDriverProvider; | ||
import integration.container.TestEnvironment; | ||
import integration.container.condition.DisableOnTestFeature; | ||
import integration.container.condition.EnableOnDatabaseEngineDeployment; | ||
import integration.container.condition.EnableOnNumOfInstances; | ||
import integration.util.AuroraTestUtility; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Properties; | ||
import java.util.TimeZone; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.logging.Logger; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.MethodOrderer.MethodName; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import software.amazon.jdbc.dialect.AuroraMysqlDialect; | ||
import software.amazon.jdbc.dialect.AuroraPgDialect; | ||
import software.amazon.jdbc.dialect.Dialect; | ||
import software.amazon.jdbc.dialect.RdsMultiAzDbClusterMysqlDialect; | ||
import software.amazon.jdbc.dialect.RdsMultiAzDbClusterPgDialect; | ||
|
||
@TestMethodOrder(MethodName.class) | ||
@DisableOnTestFeature({ | ||
TestEnvironmentFeatures.PERFORMANCE, | ||
TestEnvironmentFeatures.RUN_HIBERNATE_TESTS_ONLY, | ||
TestEnvironmentFeatures.RUN_AUTOSCALING_TESTS_ONLY}) | ||
public class TopologyQueryTests { | ||
private static final Logger LOGGER = Logger.getLogger(TopologyQueryTests.class.getName()); | ||
private String query = null; | ||
|
||
@TestTemplate | ||
@EnableOnDatabaseEngineDeployment(DatabaseEngineDeployment.AURORA) | ||
@ExtendWith(TestDriverProvider.class) | ||
public void testAuroraTypes(TestDriver testDriver) throws SQLException { | ||
LOGGER.info(testDriver.toString()); | ||
List<String> expectedTypes; | ||
|
||
final Properties props = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins(); | ||
DriverHelper.setConnectTimeout(testDriver, props, 10, TimeUnit.SECONDS); | ||
DriverHelper.setSocketTimeout(testDriver, props, 10, TimeUnit.SECONDS); | ||
|
||
String url = | ||
ConnectionStringHelper.getWrapperUrl( | ||
testDriver, | ||
TestEnvironment.getCurrent() | ||
.getInfo() | ||
.getDatabaseInfo() | ||
.getInstances() | ||
.get(0) | ||
.getHost(), | ||
TestEnvironment.getCurrent() | ||
.getInfo() | ||
.getDatabaseInfo() | ||
.getInstances() | ||
.get(0) | ||
.getPort(), | ||
TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); | ||
|
||
if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB | ||
&& TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { | ||
props.setProperty("permitMysqlScheme", "1"); | ||
} | ||
Comment on lines
+99
to
+102
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.
|
||
|
||
LOGGER.finest("Connecting to " + url); | ||
|
||
if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.PG) { | ||
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. What's about MariaDb? Is it supported by the test? 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. Supported 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. I mean I don't see a branch of the code that handle the case with mariaDb. I see AuroraMysql and AuroraPG. |
||
AuroraPgDialect dialect = new AuroraPgDialect(); | ||
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. I think you could move this if-else to the beginning of the test after |
||
query = dialect.getTopologyQuery(); | ||
expectedTypes = Arrays.asList( | ||
"text", | ||
"bool", | ||
"float4", | ||
"float4", | ||
"timestamptz" | ||
); | ||
} else { | ||
AuroraMysqlDialect dialect = new AuroraMysqlDialect(); | ||
query = dialect.getTopologyQuery(); | ||
expectedTypes = Arrays.asList( | ||
"VARCHAR", | ||
"BIGINT", | ||
"DOUBLE", | ||
"DOUBLE", | ||
"DATETIME" | ||
); | ||
} | ||
|
||
final Connection conn = DriverManager.getConnection(url, props); | ||
assertTrue(conn.isValid(5)); | ||
Statement stmt = conn.createStatement(); | ||
stmt.executeQuery(query); | ||
ResultSet rs = stmt.getResultSet(); | ||
int cols = rs.getMetaData().getColumnCount(); | ||
List<String> columnTypes = new ArrayList<>(); | ||
for (int i = 1; i <= cols; i++) { | ||
columnTypes.add(rs.getMetaData().getColumnTypeName(i)); | ||
} | ||
assertEquals(expectedTypes, columnTypes); | ||
conn.close(); | ||
} | ||
|
||
@TestTemplate | ||
@ExtendWith(TestDriverProvider.class) | ||
@EnableOnDatabaseEngineDeployment(DatabaseEngineDeployment.AURORA) | ||
@EnableOnNumOfInstances(min = 2) | ||
public void testAuroraTimestamp(TestDriver testDriver) throws SQLException, ParseException { | ||
LOGGER.info(testDriver.toString()); | ||
|
||
final Properties props = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins(); | ||
DriverHelper.setConnectTimeout(testDriver, props, 10, TimeUnit.SECONDS); | ||
DriverHelper.setSocketTimeout(testDriver, props, 10, TimeUnit.SECONDS); | ||
|
||
// Get second instance since first one has null timestamps | ||
String url = | ||
ConnectionStringHelper.getWrapperUrl( | ||
testDriver, | ||
TestEnvironment.getCurrent() | ||
.getInfo() | ||
.getDatabaseInfo() | ||
.getInstances() | ||
.get(1) | ||
.getHost(), | ||
TestEnvironment.getCurrent() | ||
.getInfo() | ||
.getDatabaseInfo() | ||
.getInstances() | ||
.get(1) | ||
.getPort(), | ||
TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); | ||
LOGGER.finest("Connecting to " + url); | ||
|
||
if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB | ||
&& TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { | ||
props.setProperty("permitMysqlScheme", "1"); | ||
} | ||
|
||
SimpleDateFormat format; | ||
if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.PG) { | ||
AuroraPgDialect dialect = new AuroraPgDialect(); | ||
query = dialect.getTopologyQuery(); | ||
format = new SimpleDateFormat("yyy-MM-dd HH:mm:ssX"); | ||
format.setTimeZone(TimeZone.getTimeZone("GMT")); | ||
} else { | ||
AuroraMysqlDialect dialect = new AuroraMysqlDialect(); | ||
query = dialect.getTopologyQuery(); | ||
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS"); | ||
} | ||
|
||
final Connection conn = DriverManager.getConnection(url, props); | ||
assertTrue(conn.isValid(5)); | ||
Statement stmt = conn.createStatement(); | ||
stmt.executeQuery(query); | ||
Comment on lines
+189
to
+192
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. Can you use try with resources here? https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html 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. Same comment for the other locations. |
||
ResultSet rs = stmt.getResultSet(); | ||
|
||
Date date = null; | ||
while (rs.next()) { | ||
if (rs.getString(5) != null) { | ||
date = format.parse(rs.getString(5)); | ||
jasonlamz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertNotNull(date); | ||
} | ||
} | ||
assertNotNull(date); | ||
|
||
conn.close(); | ||
} | ||
|
||
@TestTemplate | ||
@ExtendWith(TestDriverProvider.class) | ||
@EnableOnDatabaseEngineDeployment(DatabaseEngineDeployment.RDS) | ||
@Disabled | ||
// TODO: Disabled due to RdsMultiAz integration tests not being supported yet | ||
public void testRdsMultiAzTypes(TestDriver testDriver) throws SQLException { | ||
LOGGER.info(testDriver.toString()); | ||
|
||
final Properties props = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins(); | ||
DriverHelper.setConnectTimeout(testDriver, props, 10, TimeUnit.SECONDS); | ||
DriverHelper.setSocketTimeout(testDriver, props, 10, TimeUnit.SECONDS); | ||
|
||
String url = | ||
ConnectionStringHelper.getWrapperUrl( | ||
testDriver, | ||
TestEnvironment.getCurrent() | ||
.getInfo() | ||
.getDatabaseInfo() | ||
.getInstances() | ||
.get(0) | ||
.getHost(), | ||
TestEnvironment.getCurrent() | ||
.getInfo() | ||
.getDatabaseInfo() | ||
.getInstances() | ||
.get(0) | ||
.getPort(), | ||
TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); | ||
LOGGER.finest("Connecting to " + url); | ||
|
||
if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB | ||
&& TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { | ||
props.setProperty("permitMysqlScheme", "1"); | ||
} | ||
|
||
List<String> expectedTypes; | ||
if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.PG) { | ||
RdsMultiAzDbClusterPgDialect dialect = new RdsMultiAzDbClusterPgDialect(); | ||
query = dialect.getTopologyQuery(); | ||
expectedTypes = Arrays.asList( | ||
"text", | ||
"text", | ||
"int4" | ||
); | ||
} else { | ||
RdsMultiAzDbClusterMysqlDialect dialect = new RdsMultiAzDbClusterMysqlDialect(); | ||
query = dialect.getTopologyQuery(); | ||
expectedTypes = Arrays.asList( | ||
"VARCHAR", | ||
"VARCHAR", | ||
"INT" | ||
); | ||
} | ||
|
||
final Connection conn = DriverManager.getConnection(url, props); | ||
assertTrue(conn.isValid(5)); | ||
Statement stmt = conn.createStatement(); | ||
stmt.executeQuery(query); | ||
ResultSet rs = stmt.getResultSet(); | ||
int cols = rs.getMetaData().getColumnCount(); | ||
List<String> columnTypes = new ArrayList<>(); | ||
|
||
for (int i = 1; i <= cols; i++) { | ||
columnTypes.add(rs.getMetaData().getColumnTypeName(i)); | ||
} | ||
assertEquals(expectedTypes, columnTypes); | ||
conn.close(); | ||
} | ||
} |
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.
Can you please add the
final
keyword to all your constant local variables?Also you can just call
ConnectionStringHelper.getWrapperUrl()
here.