13
13
14
14
package com .rabbitmq .stream .impl ;
15
15
16
+ import static com .rabbitmq .stream .impl .TestUtils .BrokerVersion .RABBITMQ_3_11_14 ;
16
17
import static com .rabbitmq .stream .impl .TestUtils .ResponseConditions .ko ;
17
18
import static com .rabbitmq .stream .impl .TestUtils .ResponseConditions .ok ;
18
19
import static com .rabbitmq .stream .impl .TestUtils .ResponseConditions .responseCode ;
35
36
import com .rabbitmq .stream .impl .Client .CreditNotification ;
36
37
import com .rabbitmq .stream .impl .Client .MessageListener ;
37
38
import com .rabbitmq .stream .impl .Client .Response ;
39
+ import com .rabbitmq .stream .impl .TestUtils .BrokerVersionAtLeast ;
38
40
import com .rabbitmq .stream .impl .TestUtils .BrokerVersionAtLeast311Condition ;
39
41
import com .rabbitmq .stream .impl .TestUtils .DisabledIfRabbitMqCtlNotSet ;
40
42
import java .nio .charset .StandardCharsets ;
43
+ import java .time .Duration ;
41
44
import java .util .Collections ;
42
45
import java .util .HashMap ;
43
46
import java .util .List ;
@@ -578,6 +581,7 @@ void superStreamRebalancingShouldWorkWhilePublishing(TestInfo info) throws Excep
578
581
} finally {
579
582
keepPublishing .set (false );
580
583
deleteSuperStreamTopology (c , superStream , 3 );
584
+ c .close ();
581
585
}
582
586
}
583
587
@@ -593,4 +597,38 @@ void singleActiveConsumerMustHaveName() {
593
597
Collections .singletonMap ("single-active-consumer" , "true" ));
594
598
assertThat (response ).is (ko ()).has (responseCode (Constants .RESPONSE_CODE_PRECONDITION_FAILED ));
595
599
}
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
+ }
596
634
}
0 commit comments