Skip to content

Commit

Permalink
fix: ensure the failover plugin initial properties contain updated va…
Browse files Browse the repository at this point in the history
…lues from previous plugins (#428)
  • Loading branch information
crystall-bitquill authored Jun 28, 2023
1 parent 9e03b5b commit d98ab09
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<HostInfo> 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();
Expand Down

0 comments on commit d98ab09

Please sign in to comment.