@@ -230,7 +230,7 @@ public void testDurableSubscriber() throws Exception {
230230 JMSDestination destination = setupJMSDestination (ei );
231231 destination .setMessageObserver (createMessageObserver ());
232232 // The JMSBroker (ActiveMQ 5.x) need to take some time to setup the DurableSubscriber
233- Thread .sleep (500L );
233+ Thread .sleep (2000L );
234234 sendOneWayMessage (conduit , outMessage );
235235 Message destMessage = waitForReceiveDestMessage ();
236236
@@ -515,7 +515,7 @@ public void onMessage(Message m) {
515515 conduit .getJmsConfig ().resetCachedReplyDestination ();
516516 // The queue deletion events (as well as others) are propagated asynchronously
517517 await ()
518- .atMost (1 , TimeUnit .SECONDS )
518+ .atMost (5 , TimeUnit .SECONDS )
519519 .untilAsserted (() -> assertThat (ReflectionUtil .accessDeclaredField ("tempQueues" , ActiveMQConnection .class ,
520520 connection , Set .class ).size (), equalTo (0 )));
521521
@@ -648,7 +648,7 @@ public void onMessage(Message message) {
648648 });
649649
650650 final Message outMessage = createMessage ();
651- Thread .sleep (500L );
651+ Thread .sleep (2000L );
652652
653653 sendOneWayMessage (conduit , outMessage );
654654 latch .await (5 , TimeUnit .SECONDS );
@@ -660,11 +660,12 @@ public void onMessage(Message message) {
660660 @ Test
661661 public void testConnectionFactoryExceptionHandling () throws Exception {
662662 EndpointInfo ei = setupServiceInfo ("HelloWorldPubSubService" , "HelloWorldPubSubPort" );
663+ final FaultyConnectionFactory faultyCf = new FaultyConnectionFactory (cf , 3 );
663664 final Function <ConnectionFactory , ConnectionFactory > wrapper =
664665 new Function <ConnectionFactory , ConnectionFactory >() {
665666 @ Override
666667 public ConnectionFactory apply (ConnectionFactory cf ) {
667- return new FaultyConnectionFactory ( cf , 3 ) ;
668+ return faultyCf ;
668669 }
669670 };
670671 JMSConduit conduit = setupJMSConduitWithObserver (ei );
@@ -673,7 +674,10 @@ public ConnectionFactory apply(ConnectionFactory cf) {
673674 destination .setMessageObserver (createMessageObserver ());
674675
675676 final Message outMessage = createMessage ();
676- Thread .sleep (4000L );
677+ // Wait until the faulty connection factory has successfully created a connection
678+ // (3 faults x 1000ms retry = at least 3s)
679+ await ().atMost (30 , TimeUnit .SECONDS )
680+ .until (() -> faultyCf .connectionsCreated .get () > 0 );
677681
678682 sendOneWayMessage (conduit , outMessage );
679683
@@ -694,11 +698,20 @@ public void testBrokerExceptionHandling() throws Exception {
694698 destination .getJmsConfig ().setRetryInterval (1000 );
695699 destination .setMessageObserver (createMessageObserver ());
696700
697- Thread .sleep (500L );
701+ Thread .sleep (2000L );
698702 broker .stop ();
699703
700704 broker .start ();
701- Thread .sleep (2000L );
705+ // Wait until broker is accepting connections again
706+ await ().atMost (30 , TimeUnit .SECONDS ).pollInterval (500 , TimeUnit .MILLISECONDS ).until (() -> {
707+ try (Connection testConn = cf1 .createConnection ()) {
708+ return true ;
709+ } catch (Exception e ) {
710+ return false ;
711+ }
712+ });
713+ // Allow additional time for the destination's async reconnect to complete
714+ Thread .sleep (5000L );
702715
703716 final Message outMessage = createMessage ();
704717 sendOneWayMessage (conduit , outMessage );
@@ -748,7 +761,10 @@ public ConnectionFactory apply(ConnectionFactory cf) {
748761 destination .setMessageObserver (createMessageObserver ());
749762
750763 final Message outMessage = createMessage ();
751- Thread .sleep (4000L );
764+ // Wait until the faulty connection factory has created the expected connections
765+ // (5 session faults x 1000ms retry = at least 5s)
766+ await ().atMost (30 , TimeUnit .SECONDS )
767+ .until (() -> faultyConnectionFactory .connectionsCreated .get () >= 2 );
752768
753769 sendOneWayMessage (conduit , outMessage );
754770
@@ -759,7 +775,7 @@ public ConnectionFactory apply(ConnectionFactory cf) {
759775
760776 conduit .close ();
761777 destination .shutdown ();
762-
778+
763779 assertEquals ("Only two createConnection() calls allowed because restartConnection() should be "
764780 + "called only once." , 2 , faultyConnectionFactory .connectionsCreated .get ());
765781 }
0 commit comments