1818
1919import static org .assertj .core .api .Assertions .assertThat ;
2020import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
21+ import static org .mockito .ArgumentMatchers .any ;
2122import static org .mockito .Mockito .doAnswer ;
2223import static org .mockito .Mockito .doReturn ;
2324import static org .mockito .Mockito .doThrow ;
4041import java .util .concurrent .atomic .AtomicInteger ;
4142import java .util .concurrent .atomic .AtomicReference ;
4243
43- import org .junit .Rule ;
4444import org .junit .Test ;
4545import org .mockito .InOrder ;
4646import org .mockito .Mockito ;
5656import org .springframework .integration .ip .tcp .TcpInboundGateway ;
5757import org .springframework .integration .ip .tcp .TcpOutboundGateway ;
5858import org .springframework .integration .ip .util .TestingUtilities ;
59- import org .springframework .integration .test .rule .Log4j2LevelAdjuster ;
6059import org .springframework .integration .test .util .TestUtils ;
6160import org .springframework .integration .util .SimplePool ;
6261import org .springframework .messaging .Message ;
@@ -86,12 +85,6 @@ public void publishEvent(Object event) {
8685
8786 };
8887
89- @ Rule
90- public Log4j2LevelAdjuster adjuster =
91- Log4j2LevelAdjuster .trace ()
92- .classes (SimplePool .class )
93- .categories ("org.springframework.integration.ip.tcp" );
94-
9588 @ Test
9689 public void testFailoverGood () throws Exception {
9790 AbstractClientConnectionFactory factory1 = mock (AbstractClientConnectionFactory .class );
@@ -117,15 +110,20 @@ public void testFailoverGood() throws Exception {
117110
118111 @ Test
119112 public void testRefreshShared () throws Exception {
120- testRefreshShared (false );
113+ testRefreshShared (false , 10_000 );
121114 }
122115
123116 @ Test
124117 public void testRefreshSharedCloseOnRefresh () throws Exception {
125- testRefreshShared (true );
118+ testRefreshShared (true , 10_000 );
119+ }
120+
121+ @ Test
122+ public void testRefreshSharedInfinite () throws Exception {
123+ testRefreshShared (false , Long .MAX_VALUE );
126124 }
127125
128- private void testRefreshShared (boolean closeOnRefresh ) throws Exception {
126+ private void testRefreshShared (boolean closeOnRefresh , long interval ) throws Exception {
129127 AbstractClientConnectionFactory factory1 = mock (AbstractClientConnectionFactory .class );
130128 AbstractClientConnectionFactory factory2 = mock (AbstractClientConnectionFactory .class );
131129 List <AbstractClientConnectionFactory > factories = new ArrayList <AbstractClientConnectionFactory >();
@@ -150,21 +148,29 @@ private void testRefreshShared(boolean closeOnRefresh) throws Exception {
150148 failoverFactory .start ();
151149 TcpConnectionSupport connection = failoverFactory .getConnection ();
152150 assertThat (TestUtils .getPropertyValue (failoverFactory , "theConnection" )).isNotNull ();
153- failoverFactory .setRefreshSharedInterval (10_000 );
151+ failoverFactory .setRefreshSharedInterval (interval );
152+ InOrder inOrder = inOrder (factory1 , factory2 , conn1 , conn2 );
153+ inOrder .verify (factory1 ).getConnection ();
154+ inOrder .verify (factory2 ).getConnection ();
155+ inOrder .verify (conn1 ).registerListener (any ());
156+ inOrder .verify (conn1 ).isOpen ();
154157 assertThat (failoverFactory .getConnection ()).isSameAs (connection );
158+ inOrder .verifyNoMoreInteractions ();
155159 failoverFactory .setRefreshSharedInterval (-1 );
156160 assertThat (failoverFactory .getConnection ()).isNotSameAs (connection );
157- InOrder inOrder = inOrder (factory1 , factory2 , conn1 );
158- inOrder .verify (factory1 ).getConnection ();
159- inOrder .verify (factory2 ).getConnection ();
160161 inOrder .verify (factory1 ).getConnection ();
161162 inOrder .verify (factory2 ).getConnection ();
162163 if (closeOnRefresh ) {
164+ inOrder .verify (conn2 ).registerListener (any ());
165+ inOrder .verify (conn2 ).isOpen ();
163166 inOrder .verify (conn1 ).close ();
164167 }
165168 else {
169+ inOrder .verify (conn1 ).registerListener (any ());
170+ inOrder .verify (conn1 ).isOpen ();
166171 inOrder .verify (conn1 , never ()).close ();
167172 }
173+ inOrder .verifyNoMoreInteractions ();
168174 }
169175
170176 @ Test (expected = UncheckedIOException .class )
0 commit comments