Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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