This is an automated email from the ASF dual-hosted git repository.
vavrtom pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git
The following commit(s) were added to refs/heads/main by this push:
new 0e2e36dd06 QPID-8572: [Broker-J] The binding is broken when queue and
exchange have the same name (#131)
0e2e36dd06 is described below
commit 0e2e36dd06f47acd9c0439369e2db35a9cc6c1df
Author: Daniil Kirilyuk <[email protected]>
AuthorDate: Thu Jul 14 12:21:40 2022 +0200
QPID-8572: [Broker-J] The binding is broken when queue and exchange have
the same name (#131)
---
.../qpid/server/exchange/AbstractExchange.java | 7 ++++---
.../qpid/server/exchange/TopicExchangeTest.java | 23 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git
a/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
b/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
index 7491c44b7d..17f62f91fe 100644
---
a/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
+++
b/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
@@ -30,6 +30,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -798,12 +799,12 @@ public abstract class AbstractExchange<T extends
AbstractExchange<T>>
private MessageDestination getOpenedMessageDestination(final String name)
{
MessageDestination destination =
getVirtualHost().getSystemDestination(name);
- if(destination == null)
+ if (destination == null)
{
destination = getVirtualHost().getChildByName(Exchange.class,
name);
}
-
- if(destination == null)
+ // handle same exchange and queue name (QPID-8572)
+ if (destination == null || Objects.equals(this, destination))
{
destination = getVirtualHost().getChildByName(Queue.class, name);
}
diff --git
a/broker-core/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
b/broker-core/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
index 9bbb4da842..1e64ee916b 100644
---
a/broker-core/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
+++
b/broker-core/src/test/java/org/apache/qpid/server/exchange/TopicExchangeTest.java
@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -37,6 +38,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.apache.qpid.server.binding.BindingImpl;
import org.apache.qpid.server.message.AMQMessageHeader;
import org.apache.qpid.server.message.InstanceProperties;
import org.apache.qpid.server.message.RoutingResult;
@@ -657,6 +659,27 @@ public class TopicExchangeTest extends UnitTestBase
assertTrue("Message should be be possible to route using old binding",
result2.hasRoutes());
}
+ @Test
+ public void testBindingWithSameDestinationName()
+ {
+ String name = "test123";
+
+ Map<String, Object> queueAttributes = new HashMap<>();
+ queueAttributes.put(Queue.NAME, name);
+ queueAttributes.put(Queue.DURABLE, false);
+ Queue<?> queue = (Queue<?>) _vhost.createChild(Queue.class,
queueAttributes);
+
+ Map<String, Object> exchangeAttributes = new HashMap<>();
+ exchangeAttributes.put(Exchange.NAME, name);
+ exchangeAttributes.put(Exchange.DURABLE, false);
+ exchangeAttributes.put(Exchange.TYPE,
ExchangeDefaults.TOPIC_EXCHANGE_CLASS);
+ exchangeAttributes.put(Exchange.DURABLE_BINDINGS, Arrays.asList(new
BindingImpl("#", name, new HashMap<>())));
+ Exchange<?> exchange = (Exchange<?>)
_vhost.createChild(Exchange.class, exchangeAttributes);
+
+ assertEquals(1, queue.getBindingCount());
+ assertEquals(1, exchange.getBindingCount());
+ }
+
private ServerMessage<?> createTestMessage(Map<String, Object>
headerValues)
{
AMQMessageHeader header = mock(AMQMessageHeader.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]