1616 */
1717package org .apache .activemq .jms .pool ;
1818
19- import static org .junit .Assert .assertNotSame ;
20- import static org .junit .Assert .assertTrue ;
21- import static org .junit .Assert .fail ;
22-
23- import java .util .ArrayList ;
24- import java .util .List ;
25-
2619import jakarta .jms .Connection ;
2720import jakarta .jms .ExceptionListener ;
2821import jakarta .jms .JMSException ;
2922import jakarta .jms .JMSSecurityException ;
3023import jakarta .jms .MessageProducer ;
3124import jakarta .jms .Queue ;
3225import jakarta .jms .Session ;
33-
3426import org .apache .activemq .ActiveMQConnectionFactory ;
3527import org .apache .activemq .broker .BrokerPlugin ;
3628import org .apache .activemq .broker .BrokerService ;
5042import org .slf4j .Logger ;
5143import org .slf4j .LoggerFactory ;
5244
45+ import java .util .ArrayList ;
46+ import java .util .List ;
47+
48+ import static org .junit .Assert .assertNotSame ;
49+ import static org .junit .Assert .assertTrue ;
50+ import static org .junit .Assert .fail ;
51+
5352/**
5453 * Test Pooled connections ability to handle security exceptions
5554 */
@@ -112,7 +111,6 @@ public void onException(JMSException exception) {
112111 @ Test
113112 public void testFailureGetsNewConnectionOnRetryLooped () throws Exception {
114113 for (int i = 0 ; i < 10 ; ++i ) {
115- LOG .info ("Iteration: {}" , i );
116114 testFailureGetsNewConnectionOnRetry ();
117115 }
118116 }
@@ -135,11 +133,8 @@ public void testFailureGetsNewConnectionOnRetry() throws Exception {
135133
136134 @ Override
137135 public boolean isSatisified () throws Exception {
138- PooledConnection newConnection = (PooledConnection ) pooledConnFact .createConnection ("invalid" , "credentials" );
139- try {
136+ try (final PooledConnection newConnection = (PooledConnection ) pooledConnFact .createConnection ("invalid" , "credentials" )) {
140137 return connection1 .getConnection () != newConnection .getConnection ();
141- } finally {
142- newConnection .close ();
143138 }
144139 }
145140 }));
@@ -237,8 +232,9 @@ public void testFailoverWithInvalidCredentials() throws Exception {
237232
238233 @ Override
239234 public boolean isSatisified () throws Exception {
240- return connection1 .getConnection () !=
241- ((PooledConnection ) pooledConnFact .createConnection ("invalid" , "credentials" )).getConnection ();
235+ try (final PooledConnection newConnection = (PooledConnection ) pooledConnFact .createConnection ("invalid" , "credentials" )) {
236+ return connection1 .getConnection () != newConnection .getConnection ();
237+ }
242238 }
243239 }));
244240
0 commit comments