1313// info@rabbitmq.com.
1414package com .rabbitmq .stream .impl ;
1515
16+ import static com .rabbitmq .stream .impl .TestUtils .BrokerVersion .RABBITMQ_3_11_14 ;
1617import static com .rabbitmq .stream .impl .TestUtils .ResponseConditions .ko ;
1718import static com .rabbitmq .stream .impl .TestUtils .ResponseConditions .ok ;
1819import static com .rabbitmq .stream .impl .TestUtils .ResponseConditions .responseCode ;
3536import com .rabbitmq .stream .impl .Client .CreditNotification ;
3637import com .rabbitmq .stream .impl .Client .MessageListener ;
3738import com .rabbitmq .stream .impl .Client .Response ;
39+ import com .rabbitmq .stream .impl .TestUtils .BrokerVersionAtLeast ;
3840import com .rabbitmq .stream .impl .TestUtils .BrokerVersionAtLeast311Condition ;
3941import com .rabbitmq .stream .impl .TestUtils .DisabledIfRabbitMqCtlNotSet ;
4042import java .nio .charset .StandardCharsets ;
43+ import java .time .Duration ;
4144import java .util .Collections ;
4245import java .util .HashMap ;
4346import java .util .List ;
@@ -578,6 +581,7 @@ void superStreamRebalancingShouldWorkWhilePublishing(TestInfo info) throws Excep
578581 } finally {
579582 keepPublishing .set (false );
580583 deleteSuperStreamTopology (c , superStream , 3 );
584+ c .close ();
581585 }
582586 }
583587
@@ -593,4 +597,38 @@ void singleActiveConsumerMustHaveName() {
593597 Collections .singletonMap ("single-active-consumer" , "true" ));
594598 assertThat (response ).is (ko ()).has (responseCode (Constants .RESPONSE_CODE_PRECONDITION_FAILED ));
595599 }
600+
601+ @ Test
602+ @ DisabledIfRabbitMqCtlNotSet
603+ @ BrokerVersionAtLeast (RABBITMQ_3_11_14 )
604+ void connectionShouldBeClosedIfConsumerUpdateTakesTooLong () throws Exception {
605+ Duration timeout = Duration .ofSeconds (1 );
606+ try {
607+ Host .setEnv ("request_timeout" , String .valueOf (timeout .getSeconds ()));
608+ CountDownLatch shutdownLatch = new CountDownLatch (1 );
609+ Client client =
610+ cf .get (
611+ new ClientParameters ()
612+ .consumerUpdateListener (
613+ (c , subscriptionId , active ) -> {
614+ try {
615+ Thread .sleep (timeout .multipliedBy (2 ).toMillis ());
616+ } catch (InterruptedException e ) {
617+ throw new RuntimeException (e );
618+ }
619+ return OffsetSpecification .first ();
620+ })
621+ .shutdownListener (shutdownContext -> shutdownLatch .countDown ()));
622+ Map <String , String > parameters = new HashMap <>();
623+ parameters .put ("single-active-consumer" , "true" );
624+ parameters .put ("name" , "foo" );
625+ Response response =
626+ client .subscribe (b (0 ), stream , OffsetSpecification .first (), 1 , parameters );
627+ assertThat (response ).is (ok ());
628+
629+ assertThat (latchAssert (shutdownLatch )).completes (timeout .multipliedBy (5 ));
630+ } finally {
631+ Host .setEnv ("request_timeout" , "60000" );
632+ }
633+ }
596634}
0 commit comments