diff --git a/src/main/user-impl/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPlugin.java b/src/main/user-impl/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPlugin.java index c63b41480..83c41c5e9 100644 --- a/src/main/user-impl/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPlugin.java +++ b/src/main/user-impl/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPlugin.java @@ -1038,6 +1038,8 @@ private void fetchTopology() throws SQLException { } private void createConnection(ConnectionUrl connectionUrl) throws SQLException { + // Update initial properties in case previous plugins have changed values + this.initialConnectionProps.putAll(connectionUrl.getOriginalProperties()); if (this.enableFailoverSetting) { // Connection isn't created - try to use cached topology to create it diff --git a/src/test/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPluginTest.java b/src/test/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPluginTest.java index 893b901d8..bf9db0023 100644 --- a/src/test/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPluginTest.java +++ b/src/test/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPluginTest.java @@ -62,7 +62,6 @@ import com.mysql.cj.log.Log; import java.util.Objects; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -703,6 +702,42 @@ public void testPluginsShareTopologyCache() throws Exception { verify(spyAuroratopologyService2, never()).queryForTopology(eq(mockConnection)); } + @Test + public void testRetainPropertiesFromPreviousPlugins() throws Exception { + final String clusterId = "clusterId"; + final String url = + "jdbc:mysql:aws://my-cluster-name.cluster-ro-XYZ.us-east-2.rds.amazonaws.com"; + final String host = url.split(PREFIX)[1]; + when(mockHostInfo.getDatabaseUrl()).thenReturn(url); + when(mockHostInfo.getHost()).thenReturn(host); + + final HostInfo writerHost = + ClusterAwareTestUtils.createBasicHostInfo("writer-host"); + final List topology = new ArrayList<>(); + topology.add(writerHost); + + final AuroraTopologyService auroraTopologyService = new AuroraTopologyService(null); + final AuroraTopologyService spyAuroratopologyService = spy(auroraTopologyService); + spyAuroratopologyService.clusterId = clusterId; + + doReturn(new AuroraTopologyService.ClusterTopologyInfo(topology)) + .when(spyAuroratopologyService).queryForTopology(eq(mockConnection)); + doReturn(writerHost).when(spyAuroratopologyService).getHostByName(eq(mockConnection)); + + final Properties properties = new Properties(); + final FailoverConnectionPlugin failoverPlugin = initFailoverPlugin(properties, spyAuroratopologyService); + + final String testProperty = "testProperty"; + final String testPropertyValue = "testPropertyValue"; + final Properties previousPluginProperties = new Properties(); + previousPluginProperties.put(testProperty, testPropertyValue); + + final ConnectionUrl connectionUrl = ConnectionUrl.getConnectionUrlInstance(url, previousPluginProperties); + failoverPlugin.openInitialConnection(connectionUrl); + + assert(failoverPlugin.initialConnectionProps.get(testProperty).equals(testPropertyValue)); + } + @AfterEach void cleanUp() throws Exception { closeable.close();