You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2018/06/12 14:12:36 UTC
[2/2] activemq-artemis git commit: ARTEMIS-1893: Treat the detach of
a link with expiry policy of link-detatch as if closed flag were true.
ARTEMIS-1893: Treat the detach of a link with expiry policy of link-detatch as if closed flag were true.
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/89f6350c
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/89f6350c
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/89f6350c
Branch: refs/heads/master
Commit: 89f6350c1c730eee1faf2a699d1e88f452e5147f
Parents: 12afc0b
Author: Keith Wall <kw...@apache.org>
Authored: Mon Jun 11 08:48:50 2018 +0100
Committer: Clebert Suconic <cl...@apache.org>
Committed: Tue Jun 12 10:12:19 2018 -0400
----------------------------------------------------------------------
.../amqp/proton/AMQPConnectionContext.java | 21 +++--
.../amqp/AmqpNonDurableReceiverTest.java | 81 ++++++++++++++++++++
2 files changed, 96 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/89f6350c/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java
index 4612a97..3552106 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java
@@ -46,6 +46,8 @@ import org.apache.activemq.artemis.spi.core.remoting.ReadyListener;
import org.apache.activemq.artemis.utils.ByteUtil;
import org.apache.activemq.artemis.utils.VersionLoader;
import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.messaging.Source;
+import org.apache.qpid.proton.amqp.messaging.TerminusExpiryPolicy;
import org.apache.qpid.proton.amqp.transaction.Coordinator;
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
import org.apache.qpid.proton.engine.Connection;
@@ -485,12 +487,19 @@ public class AMQPConnectionContext extends ProtonInitializable implements EventH
@Override
public void onRemoteDetach(Link link) throws Exception {
- lock();
- try {
- link.detach();
- link.free();
- } finally {
- unlock();
+ boolean handleAsClose = link.getSource() != null
+ && ((Source) link.getSource()).getExpiryPolicy() == TerminusExpiryPolicy.LINK_DETACH;
+
+ if (handleAsClose) {
+ onRemoteClose(link);
+ } else {
+ lock();
+ try {
+ link.detach();
+ link.free();
+ } finally {
+ unlock();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/89f6350c/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpNonDurableReceiverTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpNonDurableReceiverTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpNonDurableReceiverTest.java
new file mode 100644
index 0000000..69f8b53
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpNonDurableReceiverTest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.amqp;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.transport.amqp.client.AmqpClient;
+import org.apache.activemq.transport.amqp.client.AmqpConnection;
+import org.apache.activemq.transport.amqp.client.AmqpReceiver;
+import org.apache.activemq.transport.amqp.client.AmqpSession;
+import org.apache.activemq.transport.amqp.client.AmqpValidator;
+import org.junit.Test;
+
+import org.apache.qpid.proton.amqp.messaging.Terminus;
+import org.apache.qpid.proton.amqp.messaging.TerminusExpiryPolicy;
+import org.apache.qpid.proton.engine.Receiver;
+
+public class AmqpNonDurableReceiverTest extends AmqpClientTestSupport {
+
+ @Test(timeout = 60000)
+ public void testLinkDetachReleasesResources() throws Exception {
+
+ AmqpClient client = createAmqpClient();
+ AmqpConnection connection = addConnection(client.createConnection());
+ connection.connect();
+
+ AmqpSession session = connection.createSession();
+
+ SimpleString simpleTopicName = SimpleString.toSimpleString(getTopicName());
+ final int bindingsBefore = server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().size();
+
+
+ AmqpReceiver receiver = session.createReceiver(getTopicName());
+
+ AtomicBoolean remoteLinkClosed = new AtomicBoolean();
+ assertEquals("Unexpected source expiry policy", TerminusExpiryPolicy.LINK_DETACH,
+ ((Terminus) receiver.getEndpoint().getSource()).getExpiryPolicy());
+
+ receiver.setStateInspector(new AmqpValidator() {
+ @Override
+ public void inspectDetachedResource(final Receiver receiver) {
+ super.inspectDetachedResource(receiver);
+ fail("Remote link detached in unexpected manner");
+ }
+
+ @Override
+ public void inspectClosedResource(final Receiver receiver) {
+ super.inspectClosedResource(receiver);
+ remoteLinkClosed.set(true);
+ }
+ });
+
+ assertEquals("Unexpected number of bindings before attach",
+ bindingsBefore + 1, server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().size());
+
+ receiver.detach();
+
+ assertEquals("Unexpected number of bindings after detach",
+ bindingsBefore,
+ server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().size());
+
+ assertTrue("Remote link was not closed", remoteLinkClosed.get());
+
+ receiver.getStateInspector().assertValid();
+ }
+}