Skip to content

Commit

Permalink
testing again
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonli-improving committed Feb 29, 2024
1 parent 2705ea9 commit a1a4bc4
Showing 1 changed file with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import integration.container.TestDriverProvider;
import integration.container.TestEnvironment;
import integration.container.condition.DisableOnTestFeature;
import integration.container.condition.EnableOnDatabaseEngineDeployment;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
Expand All @@ -40,6 +41,7 @@
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;
Expand All @@ -59,21 +61,22 @@
TestEnvironmentFeatures.RUN_HIBERNATE_TESTS_ONLY,
TestEnvironmentFeatures.RUN_AUTOSCALING_TESTS_ONLY})
public class TopologyQueryTests {
private static final Logger LOGGER = Logger.getLogger(BasicConnectivityTests.class.getName());
private static final Logger LOGGER = Logger.getLogger(TopologyQueryTests.class.getName());

@TestTemplate
@EnableOnDatabaseEngineDeployment(DatabaseEngineDeployment.AURORA)
@ExtendWith(TestDriverProvider.class)
public void auroraTestTypes(TestDriver testDriver) throws SQLException {
LOGGER.info(testDriver.toString());

List<String> expectedTypes;
// Topology queries fail on docker containers, can't test topology for them
// Also skip RDS, this is for Aurora
if (TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment()
== DatabaseEngineDeployment.DOCKER
|| TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment()
== DatabaseEngineDeployment.RDS) {
return;
}
// if (TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment()
// == DatabaseEngineDeployment.DOCKER
// || TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment()
// == DatabaseEngineDeployment.RDS) {
// return;
// }

final Properties props = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins();
DriverHelper.setConnectTimeout(testDriver, props, 10, TimeUnit.SECONDS);
Expand All @@ -100,8 +103,22 @@ public void auroraTestTypes(TestDriver testDriver) throws SQLException {
String query = null;
if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.PG) {
query = AuroraPgDialect.TOPOLOGY_QUERY;
expectedTypes = Arrays.asList(
"text",
"bool",
"float4",
"float4",
"timestamptz"
);
} else {
query = AuroraMysqlDialect.TOPOLOGY_QUERY;
expectedTypes = Arrays.asList(
"VARCHAR",
"BIGINT",
"DOUBLE",
"DOUBLE",
"DATETIME"
);
}

final Connection conn = DriverManager.getConnection(url, props);
Expand All @@ -111,33 +128,27 @@ public void auroraTestTypes(TestDriver testDriver) throws SQLException {
ResultSet rs = stmt.getResultSet();
int cols = rs.getMetaData().getColumnCount();
List<String> columnTypes = new ArrayList<>();
List<String> expectedTypes = Arrays.asList(
"VARCHAR",
"BIGINT",
"DOUBLE",
"DOUBLE",
"DATETIME"
);
for (int i = 1; i <= cols; i++) {
columnTypes.add(rs.getMetaData().getColumnTypeName(i));
}
assertEquals(columnTypes, expectedTypes);
assertEquals(expectedTypes, columnTypes);
conn.close();
}

@TestTemplate
@ExtendWith(TestDriverProvider.class)
@EnableOnDatabaseEngineDeployment(DatabaseEngineDeployment.AURORA)
public void auroraTestTimestamp(TestDriver testDriver) throws SQLException, ParseException {
LOGGER.info(testDriver.toString());

// Topology queries fail on docker containers, can't test topology for them
// Also skip RDS, this is for Aurora
if (TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment()
== DatabaseEngineDeployment.DOCKER
|| TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment()
== DatabaseEngineDeployment.RDS) {
return;
}
// if (TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment()
// == DatabaseEngineDeployment.DOCKER
// || TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment()
// == DatabaseEngineDeployment.RDS) {
// return;
// }

final Properties props = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins();
DriverHelper.setConnectTimeout(testDriver, props, 10, TimeUnit.SECONDS);
Expand All @@ -162,14 +173,16 @@ public void auroraTestTimestamp(TestDriver testDriver) throws SQLException, Pars
LOGGER.finest("Connecting to " + url);

String query = null;
SimpleDateFormat format;
if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.PG) {
query = AuroraPgDialect.TOPOLOGY_QUERY;
format = new SimpleDateFormat("yyy-MM-dd HH:mm:ssX");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
} else {
query = AuroraMysqlDialect.TOPOLOGY_QUERY;
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");
}

SimpleDateFormat 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();
Expand All @@ -187,8 +200,9 @@ public void auroraTestTimestamp(TestDriver testDriver) throws SQLException, Pars

@TestTemplate
@ExtendWith(TestDriverProvider.class)
@EnableOnDatabaseEngineDeployment(DatabaseEngineDeployment.RDS)
@Disabled
// Disabled due to RDS integration tests not being supported yet
// TODO: Disabled due to RDS integration tests not being supported yet
public void rdsTestTypes(TestDriver testDriver) throws SQLException {
LOGGER.info(testDriver.toString());

Expand Down Expand Up @@ -250,7 +264,7 @@ public void rdsTestTypes(TestDriver testDriver) throws SQLException {
for (int i = 1; i <= cols; i++) {
columnTypes.add(rs.getMetaData().getColumnTypeName(i));
}
assertEquals(columnTypes, expectedTypes);
assertEquals(expectedTypes, columnTypes);
conn.close();
}
}

0 comments on commit a1a4bc4

Please sign in to comment.