Skip to content

Commit 6081628

Browse files
committed
Log warning when receiving basic.cancel for unknown consumer
Fixes #525 (cherry picked from commit be13273)
1 parent be57b26 commit 6081628

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/main/java/com/rabbitmq/client/impl/ChannelN.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ private void releaseChannel() {
402402
consumerTag,
403403
"handleCancel");
404404
}
405+
} else {
406+
LOGGER.warn("Could not cancel consumer with unknown tag {}", consumerTag);
405407
}
406408
return true;
407409
} else {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2019 Pivotal Software, Inc. All rights reserved.
2+
//
3+
// This software, the RabbitMQ Java client library, is triple-licensed under the
4+
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5+
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6+
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7+
// please see LICENSE-APACHE2.
8+
//
9+
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10+
// either express or implied. See the LICENSE file for specific language governing
11+
// rights and limitations of this software.
12+
//
13+
// If you have any questions regarding licensing, please contact us at
14+
15+
16+
package com.rabbitmq.client.test;
17+
18+
import com.rabbitmq.client.Method;
19+
import com.rabbitmq.client.impl.*;
20+
import org.junit.After;
21+
import org.junit.Before;
22+
import org.junit.Test;
23+
import org.mockito.Mockito;
24+
25+
import java.util.concurrent.ExecutorService;
26+
import java.util.concurrent.Executors;
27+
28+
public class ChannelNTest {
29+
30+
ConsumerWorkService consumerWorkService;
31+
ExecutorService executorService;
32+
33+
@Before public void init() {
34+
executorService = Executors.newSingleThreadExecutor();
35+
consumerWorkService = new ConsumerWorkService(executorService, null, 1000, 1000);
36+
}
37+
38+
@After public void tearDown() {
39+
consumerWorkService.shutdown();
40+
executorService.shutdownNow();
41+
}
42+
43+
@Test
44+
public void cancelUnknownConsumerDoesNotThrowException() throws Exception {
45+
AMQConnection connection = Mockito.mock(AMQConnection.class);
46+
ChannelN channel = new ChannelN(connection, 1, consumerWorkService);
47+
Method method = new AMQImpl.Basic.Cancel.Builder().consumerTag("does-not-exist").build();
48+
channel.processAsync(new AMQCommand(method));
49+
}
50+
51+
}

src/test/java/com/rabbitmq/client/test/ClientTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
GeneratedClassesTest.class,
7171
RpcTopologyRecordingTest.class,
7272
ConnectionTest.class,
73-
TlsUtilsTest.class
73+
TlsUtilsTest.class,
74+
ChannelNTest.class
7475
})
7576
public class ClientTests {
7677

0 commit comments

Comments
 (0)