Skip to content

Commit

Permalink
Log warning when receiving basic.cancel for unknown consumer
Browse files Browse the repository at this point in the history
Fixes #525

(cherry picked from commit be13273)
  • Loading branch information
acogoluegnes committed Mar 22, 2019
1 parent be57b26 commit 6081628
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/com/rabbitmq/client/impl/ChannelN.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ private void releaseChannel() {
consumerTag,
"handleCancel");
}
} else {
LOGGER.warn("Could not cancel consumer with unknown tag {}", consumerTag);
}
return true;
} else {
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/com/rabbitmq/client/test/ChannelNTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2019 Pivotal Software, Inc. All rights reserved.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
// please see LICENSE-APACHE2.
//
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
// either express or implied. See the LICENSE file for specific language governing
// rights and limitations of this software.
//
// If you have any questions regarding licensing, please contact us at
// info@rabbitmq.com.

package com.rabbitmq.client.test;

import com.rabbitmq.client.Method;
import com.rabbitmq.client.impl.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ChannelNTest {

ConsumerWorkService consumerWorkService;
ExecutorService executorService;

@Before public void init() {
executorService = Executors.newSingleThreadExecutor();
consumerWorkService = new ConsumerWorkService(executorService, null, 1000, 1000);
}

@After public void tearDown() {
consumerWorkService.shutdown();
executorService.shutdownNow();
}

@Test
public void cancelUnknownConsumerDoesNotThrowException() throws Exception {
AMQConnection connection = Mockito.mock(AMQConnection.class);
ChannelN channel = new ChannelN(connection, 1, consumerWorkService);
Method method = new AMQImpl.Basic.Cancel.Builder().consumerTag("does-not-exist").build();
channel.processAsync(new AMQCommand(method));
}

}
3 changes: 2 additions & 1 deletion src/test/java/com/rabbitmq/client/test/ClientTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
GeneratedClassesTest.class,
RpcTopologyRecordingTest.class,
ConnectionTest.class,
TlsUtilsTest.class
TlsUtilsTest.class,
ChannelNTest.class
})
public class ClientTests {

Expand Down

0 comments on commit 6081628

Please sign in to comment.