|
62 | 62 | import com.mysql.cj.log.Log; |
63 | 63 | import java.util.Objects; |
64 | 64 | import org.junit.jupiter.api.AfterEach; |
65 | | -import org.junit.jupiter.api.BeforeAll; |
66 | 65 | import org.junit.jupiter.api.BeforeEach; |
67 | 66 | import org.junit.jupiter.api.Test; |
68 | 67 | import org.mockito.ArgumentCaptor; |
@@ -703,6 +702,42 @@ public void testPluginsShareTopologyCache() throws Exception { |
703 | 702 | verify(spyAuroratopologyService2, never()).queryForTopology(eq(mockConnection)); |
704 | 703 | } |
705 | 704 |
|
| 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 | + |
706 | 741 | @AfterEach |
707 | 742 | void cleanUp() throws Exception { |
708 | 743 | closeable.close(); |
|
0 commit comments