|
| 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 | +} |
0 commit comments