Skip to content

Commit d98ab09

Browse files
fix: ensure the failover plugin initial properties contain updated values from previous plugins (#428)
1 parent 9e03b5b commit d98ab09

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/main/user-impl/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,8 @@ private void fetchTopology() throws SQLException {
10381038
}
10391039

10401040
private void createConnection(ConnectionUrl connectionUrl) throws SQLException {
1041+
// Update initial properties in case previous plugins have changed values
1042+
this.initialConnectionProps.putAll(connectionUrl.getOriginalProperties());
10411043

10421044
if (this.enableFailoverSetting) {
10431045
// Connection isn't created - try to use cached topology to create it

src/test/java/com/mysql/cj/jdbc/ha/plugins/failover/FailoverConnectionPluginTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import com.mysql.cj.log.Log;
6363
import java.util.Objects;
6464
import org.junit.jupiter.api.AfterEach;
65-
import org.junit.jupiter.api.BeforeAll;
6665
import org.junit.jupiter.api.BeforeEach;
6766
import org.junit.jupiter.api.Test;
6867
import org.mockito.ArgumentCaptor;
@@ -703,6 +702,42 @@ public void testPluginsShareTopologyCache() throws Exception {
703702
verify(spyAuroratopologyService2, never()).queryForTopology(eq(mockConnection));
704703
}
705704

705+
@Test
706+
public void testRetainPropertiesFromPreviousPlugins() throws Exception {
707+
final String clusterId = "clusterId";
708+
final String url =
709+
"jdbc:mysql:aws://my-cluster-name.cluster-ro-XYZ.us-east-2.rds.amazonaws.com";
710+
final String host = url.split(PREFIX)[1];
711+
when(mockHostInfo.getDatabaseUrl()).thenReturn(url);
712+
when(mockHostInfo.getHost()).thenReturn(host);
713+
714+
final HostInfo writerHost =
715+
ClusterAwareTestUtils.createBasicHostInfo("writer-host");
716+
final List<HostInfo> topology = new ArrayList<>();
717+
topology.add(writerHost);
718+
719+
final AuroraTopologyService auroraTopologyService = new AuroraTopologyService(null);
720+
final AuroraTopologyService spyAuroratopologyService = spy(auroraTopologyService);
721+
spyAuroratopologyService.clusterId = clusterId;
722+
723+
doReturn(new AuroraTopologyService.ClusterTopologyInfo(topology))
724+
.when(spyAuroratopologyService).queryForTopology(eq(mockConnection));
725+
doReturn(writerHost).when(spyAuroratopologyService).getHostByName(eq(mockConnection));
726+
727+
final Properties properties = new Properties();
728+
final FailoverConnectionPlugin failoverPlugin = initFailoverPlugin(properties, spyAuroratopologyService);
729+
730+
final String testProperty = "testProperty";
731+
final String testPropertyValue = "testPropertyValue";
732+
final Properties previousPluginProperties = new Properties();
733+
previousPluginProperties.put(testProperty, testPropertyValue);
734+
735+
final ConnectionUrl connectionUrl = ConnectionUrl.getConnectionUrlInstance(url, previousPluginProperties);
736+
failoverPlugin.openInitialConnection(connectionUrl);
737+
738+
assert(failoverPlugin.initialConnectionProps.get(testProperty).equals(testPropertyValue));
739+
}
740+
706741
@AfterEach
707742
void cleanUp() throws Exception {
708743
closeable.close();

0 commit comments

Comments
 (0)