28
28
import java .util .concurrent .CountDownLatch ;
29
29
import java .util .concurrent .TimeUnit ;
30
30
31
+ import static org .assertj .core .api .Assertions .assertThat ;
31
32
import static org .junit .jupiter .api .Assertions .assertTrue ;
32
33
import static org .junit .jupiter .api .Assertions .fail ;
33
34
34
- public class ConsumerCancelNotification extends BrokerTestCase {
35
+ public class ConsumerNotifications extends BrokerTestCase {
35
36
36
37
private final String queue = "cancel_notification_queue" ;
37
38
@@ -42,7 +43,7 @@ public class ConsumerCancelNotification extends BrokerTestCase {
42
43
channel .queueDeclare (queue , false , true , false , null );
43
44
Consumer consumer = new DefaultConsumer (channel ) {
44
45
@ Override
45
- public void handleCancel (String consumerTag ) throws IOException {
46
+ public void handleCancel (String consumerTag ) {
46
47
try {
47
48
result .put (true );
48
49
} catch (InterruptedException e ) {
@@ -55,7 +56,31 @@ public void handleCancel(String consumerTag) throws IOException {
55
56
assertTrue (result .take ());
56
57
}
57
58
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 {
59
84
private final String altQueue ;
60
85
private final CountDownLatch latch ;
61
86
@@ -81,18 +106,4 @@ public void handleCancel(String consumerTag) {
81
106
}
82
107
}
83
108
}
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
- }
98
109
}
0 commit comments