2828import java .util .concurrent .CountDownLatch ;
2929import java .util .concurrent .TimeUnit ;
3030
31+ import static org .assertj .core .api .Assertions .assertThat ;
3132import static org .junit .jupiter .api .Assertions .assertTrue ;
3233import static org .junit .jupiter .api .Assertions .fail ;
3334
34- public class ConsumerCancelNotification extends BrokerTestCase {
35+ public class ConsumerNotifications extends BrokerTestCase {
3536
3637 private final String queue = "cancel_notification_queue" ;
3738
@@ -42,7 +43,7 @@ public class ConsumerCancelNotification extends BrokerTestCase {
4243 channel .queueDeclare (queue , false , true , false , null );
4344 Consumer consumer = new DefaultConsumer (channel ) {
4445 @ Override
45- public void handleCancel (String consumerTag ) throws IOException {
46+ public void handleCancel (String consumerTag ) {
4647 try {
4748 result .put (true );
4849 } catch (InterruptedException e ) {
@@ -55,7 +56,31 @@ public void handleCancel(String consumerTag) throws IOException {
5556 assertTrue (result .take ());
5657 }
5758
58- class AlteringConsumer extends DefaultConsumer {
59+ @ Test public void consumerCancellationHandlerUsesBlockingOperations ()
60+ throws IOException , InterruptedException {
61+ final String altQueue = "basic.cancel.fallback" ;
62+ channel .queueDeclare (queue , false , true , false , null );
63+
64+ CountDownLatch latch = new CountDownLatch (1 );
65+ final AlteringConsumer consumer = new AlteringConsumer (channel , altQueue , latch );
66+
67+ channel .basicConsume (queue , consumer );
68+ channel .queueDelete (queue );
69+
70+ latch .await (2 , TimeUnit .SECONDS );
71+ }
72+
73+ @ Test
74+ void handleShutdownShouldBeCalledWhenChannelIsClosed () throws Exception {
75+ Channel ch = connection .createChannel ();
76+ String q = ch .queueDeclare ().getQueue ();
77+ CountDownLatch latch = new CountDownLatch (1 );
78+ ch .basicConsume (q , (ctag , msg ) -> {}, (ctag , r ) -> latch .countDown ());
79+ ch .close ();
80+ assertThat (latch .await (10 , TimeUnit .SECONDS )).isTrue ();
81+ }
82+
83+ private static class AlteringConsumer extends DefaultConsumer {
5984 private final String altQueue ;
6085 private final CountDownLatch latch ;
6186
@@ -81,18 +106,4 @@ public void handleCancel(String consumerTag) {
81106 }
82107 }
83108 }
84-
85- @ Test public void consumerCancellationHandlerUsesBlockingOperations ()
86- throws IOException , InterruptedException {
87- final String altQueue = "basic.cancel.fallback" ;
88- channel .queueDeclare (queue , false , true , false , null );
89-
90- CountDownLatch latch = new CountDownLatch (1 );
91- final AlteringConsumer consumer = new AlteringConsumer (channel , altQueue , latch );
92-
93- channel .basicConsume (queue , consumer );
94- channel .queueDelete (queue );
95-
96- latch .await (2 , TimeUnit .SECONDS );
97- }
98109}
0 commit comments