@@ -104,7 +104,7 @@ class FailoverConnectionPluginTest {
104104
105105
106106 private final Properties properties = new Properties ();
107- private FailoverConnectionPlugin plugin ;
107+ private FailoverConnectionPlugin spyPlugin ;
108108 private AutoCloseable closeable ;
109109
110110 @ AfterEach
@@ -150,7 +150,7 @@ void test_notifyNodeListChanged_withFailoverDisabled() {
150150 final Map <String , EnumSet <NodeChangeOptions >> changes = new HashMap <>();
151151
152152 initializePlugin ();
153- plugin .notifyNodeListChanged (changes );
153+ spyPlugin .notifyNodeListChanged (changes );
154154
155155 verify (mockPluginService , never ()).getCurrentHostSpec ();
156156 verify (mockHostSpec , never ()).getAliases ();
@@ -163,7 +163,7 @@ void test_notifyNodeListChanged_withValidConnectionNotInTopology() {
163163 changes .put ("instance/" , EnumSet .of (NodeChangeOptions .NODE_ADDED ));
164164
165165 initializePlugin ();
166- plugin .notifyNodeListChanged (changes );
166+ spyPlugin .notifyNodeListChanged (changes );
167167
168168 when (mockHostSpec .getUrl ()).thenReturn ("cluster-url/" );
169169 when (mockHostSpec .getAliases ()).thenReturn (new HashSet <>(Collections .singletonList ("instance" )));
@@ -177,20 +177,20 @@ void test_updateTopology() throws SQLException {
177177 initializePlugin ();
178178
179179 // Test updateTopology with failover disabled
180- plugin .setRdsUrlType (RdsUrlType .RDS_PROXY );
181- plugin .updateTopology (false );
180+ spyPlugin .setRdsUrlType (RdsUrlType .RDS_PROXY );
181+ spyPlugin .updateTopology (false );
182182 verify (mockPluginService , never ()).forceRefreshHostList ();
183183 verify (mockPluginService , never ()).refreshHostList ();
184184
185185 // Test updateTopology with no connection
186186 when (mockPluginService .getCurrentHostSpec ()).thenReturn (null );
187- plugin .updateTopology (false );
187+ spyPlugin .updateTopology (false );
188188 verify (mockPluginService , never ()).forceRefreshHostList ();
189189 verify (mockPluginService , never ()).refreshHostList ();
190190
191191 // Test updateTopology with closed connection
192192 when (mockConnection .isClosed ()).thenReturn (true );
193- plugin .updateTopology (false );
193+ spyPlugin .updateTopology (false );
194194 verify (mockPluginService , never ()).forceRefreshHostList ();
195195 verify (mockPluginService , never ()).refreshHostList ();
196196 }
@@ -205,9 +205,9 @@ void test_updateTopology_withForceUpdate(final boolean forceUpdate) throws SQLEx
205205 new HostSpecBuilder (new SimpleHostAvailabilityStrategy ()).host ("host" ).build ()));
206206 when (mockConnection .isClosed ()).thenReturn (false );
207207 initializePlugin ();
208- plugin .setRdsUrlType (RdsUrlType .RDS_INSTANCE );
208+ spyPlugin .setRdsUrlType (RdsUrlType .RDS_INSTANCE );
209209
210- plugin .updateTopology (forceUpdate );
210+ spyPlugin .updateTopology (forceUpdate );
211211 if (forceUpdate ) {
212212 verify (mockPluginService , atLeastOnce ()).forceRefreshHostList ();
213213 } else {
@@ -220,23 +220,23 @@ void test_failover_failoverWriter() throws SQLException {
220220 when (mockPluginService .isInTransaction ()).thenReturn (true );
221221
222222 initializePlugin ();
223- doThrow (FailoverSuccessSQLException .class ).when (plugin ).failoverWriter ();
224- plugin .failoverMode = FailoverMode .STRICT_WRITER ;
223+ doThrow (FailoverSuccessSQLException .class ).when (spyPlugin ).failoverWriter ();
224+ spyPlugin .failoverMode = FailoverMode .STRICT_WRITER ;
225225
226- assertThrows (FailoverSuccessSQLException .class , () -> plugin .failover (mockHostSpec ));
227- verify (plugin ).failoverWriter ();
226+ assertThrows (FailoverSuccessSQLException .class , () -> spyPlugin .failover (mockHostSpec ));
227+ verify (spyPlugin ).failoverWriter ();
228228 }
229229
230230 @ Test
231231 void test_failover_failoverReader () throws SQLException {
232232 when (mockPluginService .isInTransaction ()).thenReturn (false );
233233
234234 initializePlugin ();
235- doThrow (FailoverSuccessSQLException .class ).when (plugin ).failoverReader (eq (mockHostSpec ));
236- plugin .failoverMode = FailoverMode .READER_OR_WRITER ;
235+ doThrow (FailoverSuccessSQLException .class ).when (spyPlugin ).failoverReader (eq (mockHostSpec ));
236+ spyPlugin .failoverMode = FailoverMode .READER_OR_WRITER ;
237237
238- assertThrows (FailoverSuccessSQLException .class , () -> plugin .failover (mockHostSpec ));
239- verify (plugin ).failoverReader (eq (mockHostSpec ));
238+ assertThrows (FailoverSuccessSQLException .class , () -> spyPlugin .failover (mockHostSpec ));
239+ verify (spyPlugin ).failoverReader (eq (mockHostSpec ));
240240 }
241241
242242 @ Test
@@ -248,13 +248,13 @@ void test_failoverReader_withValidFailedHostSpec_successFailover() throws SQLExc
248248 when (mockReaderResult .getHost ()).thenReturn (defaultHosts .get (1 ));
249249
250250 initializePlugin ();
251- plugin .initHostProvider (
251+ spyPlugin .initHostProvider (
252252 mockHostListProviderService ,
253253 mockInitHostProviderFunc ,
254254 (connectionService ) -> mockReaderFailoverHandler ,
255255 (connectionService ) -> mockWriterFailoverHandler );
256256
257- final FailoverConnectionPlugin spyPlugin = spy (plugin );
257+ final FailoverConnectionPlugin spyPlugin = spy (this . spyPlugin );
258258 doNothing ().when (spyPlugin ).updateTopology (true );
259259
260260 assertThrows (FailoverSuccessSQLException .class , () -> spyPlugin .failoverReader (mockHostSpec ));
@@ -277,13 +277,13 @@ void test_failoverReader_withNoFailedHostSpec_withException() throws SQLExceptio
277277 when (mockReaderResult .getHost ()).thenReturn (hostSpec );
278278
279279 initializePlugin ();
280- plugin .initHostProvider (
280+ spyPlugin .initHostProvider (
281281 mockHostListProviderService ,
282282 mockInitHostProviderFunc ,
283283 (connectionService ) -> mockReaderFailoverHandler ,
284284 (connectionService ) -> mockWriterFailoverHandler );
285285
286- assertThrows (SQLException .class , () -> plugin .failoverReader (null ));
286+ assertThrows (SQLException .class , () -> spyPlugin .failoverReader (null ));
287287 verify (mockReaderFailoverHandler ).failover (eq (hosts ), eq (null ));
288288 }
289289
@@ -299,13 +299,13 @@ void test_failoverWriter_failedFailover_throwsException() throws SQLException {
299299 when (mockWriterResult .getException ()).thenReturn (new SQLException ());
300300
301301 initializePlugin ();
302- plugin .initHostProvider (
302+ spyPlugin .initHostProvider (
303303 mockHostListProviderService ,
304304 mockInitHostProviderFunc ,
305305 (connectionService ) -> mockReaderFailoverHandler ,
306306 (connectionService ) -> mockWriterFailoverHandler );
307307
308- assertThrows (SQLException .class , () -> plugin .failoverWriter ());
308+ assertThrows (SQLException .class , () -> spyPlugin .failoverWriter ());
309309 verify (mockWriterFailoverHandler ).failover (eq (hosts ));
310310 }
311311
@@ -321,13 +321,13 @@ void test_failoverWriter_failedFailover_withNoResult() throws SQLException {
321321 when (mockWriterResult .isConnected ()).thenReturn (false );
322322
323323 initializePlugin ();
324- plugin .initHostProvider (
324+ spyPlugin .initHostProvider (
325325 mockHostListProviderService ,
326326 mockInitHostProviderFunc ,
327327 (connectionService ) -> mockReaderFailoverHandler ,
328328 (connectionService ) -> mockWriterFailoverHandler );
329329
330- final SQLException exception = assertThrows (SQLException .class , () -> plugin .failoverWriter ());
330+ final SQLException exception = assertThrows (SQLException .class , () -> spyPlugin .failoverWriter ());
331331 assertEquals (SqlState .CONNECTION_UNABLE_TO_CONNECT .getState (), exception .getSQLState ());
332332
333333 verify (mockWriterFailoverHandler ).failover (eq (hosts ));
@@ -340,13 +340,13 @@ void test_failoverWriter_successFailover() throws SQLException {
340340 when (mockHostSpec .getAliases ()).thenReturn (new HashSet <>(Arrays .asList ("alias1" , "alias2" )));
341341
342342 initializePlugin ();
343- plugin .initHostProvider (
343+ spyPlugin .initHostProvider (
344344 mockHostListProviderService ,
345345 mockInitHostProviderFunc ,
346346 (connectionService ) -> mockReaderFailoverHandler ,
347347 (connectionService ) -> mockWriterFailoverHandler );
348348
349- final SQLException exception = assertThrows (FailoverSuccessSQLException .class , () -> plugin .failoverWriter ());
349+ final SQLException exception = assertThrows (FailoverSuccessSQLException .class , () -> spyPlugin .failoverWriter ());
350350 assertEquals (SqlState .COMMUNICATION_LINK_CHANGED .getState (), exception .getSQLState ());
351351
352352 verify (mockWriterFailoverHandler ).failover (eq (defaultHosts ));
@@ -356,7 +356,7 @@ void test_failoverWriter_successFailover() throws SQLException {
356356 void test_invalidCurrentConnection_withNoConnection () {
357357 when (mockPluginService .getCurrentConnection ()).thenReturn (null );
358358 initializePlugin ();
359- plugin .invalidateCurrentConnection ();
359+ spyPlugin .invalidateCurrentConnection ();
360360
361361 verify (mockPluginService , never ()).getCurrentHostSpec ();
362362 }
@@ -369,12 +369,12 @@ void test_invalidateCurrentConnection_inTransaction() throws SQLException {
369369 when (mockHostSpec .getRole ()).thenReturn (HostRole .READER );
370370
371371 initializePlugin ();
372- plugin .invalidateCurrentConnection ();
372+ spyPlugin .invalidateCurrentConnection ();
373373 verify (mockConnection ).rollback ();
374374
375375 // Assert SQL exceptions thrown during rollback do not get propagated.
376376 doThrow (new SQLException ()).when (mockConnection ).rollback ();
377- assertDoesNotThrow (() -> plugin .invalidateCurrentConnection ());
377+ assertDoesNotThrow (() -> spyPlugin .invalidateCurrentConnection ());
378378 }
379379
380380 @ Test
@@ -385,7 +385,7 @@ void test_invalidateCurrentConnection_notInTransaction() {
385385 when (mockHostSpec .getRole ()).thenReturn (HostRole .READER );
386386
387387 initializePlugin ();
388- plugin .invalidateCurrentConnection ();
388+ spyPlugin .invalidateCurrentConnection ();
389389
390390 verify (mockPluginService ).isInTransaction ();
391391 }
@@ -399,10 +399,10 @@ void test_invalidateCurrentConnection_withOpenConnection() throws SQLException {
399399 when (mockHostSpec .getRole ()).thenReturn (HostRole .READER );
400400
401401 initializePlugin ();
402- plugin .invalidateCurrentConnection ();
402+ spyPlugin .invalidateCurrentConnection ();
403403
404404 doThrow (new SQLException ()).when (mockConnection ).close ();
405- assertDoesNotThrow (() -> plugin .invalidateCurrentConnection ());
405+ assertDoesNotThrow (() -> spyPlugin .invalidateCurrentConnection ());
406406
407407 verify (mockConnection , times (2 )).isClosed ();
408408 verify (mockConnection , times (2 )).close ();
@@ -413,7 +413,7 @@ void test_execute_withFailoverDisabled() throws SQLException {
413413 properties .setProperty (FailoverConnectionPlugin .ENABLE_CLUSTER_AWARE_FAILOVER .name , "false" );
414414 initializePlugin ();
415415
416- plugin .execute (
416+ spyPlugin .execute (
417417 ResultSet .class ,
418418 SQLException .class ,
419419 MONITOR_METHOD_INVOKE_ON ,
@@ -428,7 +428,7 @@ void test_execute_withFailoverDisabled() throws SQLException {
428428 @ Test
429429 void test_execute_withDirectExecute () throws SQLException {
430430 initializePlugin ();
431- plugin .execute (
431+ spyPlugin .execute (
432432 ResultSet .class ,
433433 SQLException .class ,
434434 MONITOR_METHOD_INVOKE_ON ,
@@ -440,12 +440,12 @@ void test_execute_withDirectExecute() throws SQLException {
440440 }
441441
442442 private void initializePlugin () {
443- plugin = spy (new FailoverConnectionPlugin (mockContainer , properties ));
444- plugin .setWriterFailoverHandler (mockWriterFailoverHandler );
445- plugin .setReaderFailoverHandler (mockReaderFailoverHandler );
443+ spyPlugin = spy (new FailoverConnectionPlugin (mockContainer , properties ));
444+ spyPlugin .setWriterFailoverHandler (mockWriterFailoverHandler );
445+ spyPlugin .setReaderFailoverHandler (mockReaderFailoverHandler );
446446
447447 try {
448- doReturn (mockConnectionService ).when (plugin ).getConnectionService ();
448+ doReturn (mockConnectionService ).when (spyPlugin ).getConnectionService ();
449449 } catch (SQLException e ) {
450450 fail (
451451 "Encountered exception when trying to stub FailoverConnectionPlugin#getConnectionService: " + e .getMessage ());
0 commit comments