You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2016/08/24 21:00:54 UTC

qpid-proton git commit: PROTON-1290 Don't send extra flow on receiver detach

Repository: qpid-proton
Updated Branches:
  refs/heads/master 4d4495cc7 -> 752e848b3


PROTON-1290 Don't send extra flow on receiver detach

Prevent erroneous flow frame from being written when receiver is
detached when a pending drain is waiting completion.

Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/752e848b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/752e848b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/752e848b

Branch: refs/heads/master
Commit: 752e848b3e12f9bbecbdb3521f998414b6a196d0
Parents: 4d4495c
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed Aug 24 17:00:18 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed Aug 24 17:00:38 2016 -0400

----------------------------------------------------------------------
 .../qpid/proton/engine/impl/TransportImpl.java  |  2 +-
 .../proton/engine/impl/TransportImplTest.java   | 60 +++++++++++++++++++-
 2 files changed, 60 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/752e848b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
index 63dc826..b8003ac 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
@@ -689,7 +689,7 @@ public class TransportImpl extends EndpointImpl
                     TransportLink<?> transportLink = getTransportState(receiver);
                     TransportSession transportSession = getTransportState(receiver.getSession());
 
-                    if(receiver.getLocalState() == EndpointState.ACTIVE && transportSession.isLocalChannelSet())
+                    if(receiver.getLocalState() == EndpointState.ACTIVE && transportSession.isLocalChannelSet() && !receiver.detached())
                     {
                         int credits = receiver.clearUnsentCredits();
                         if(credits != 0 || receiver.getDrain() ||

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/752e848b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
index a0b266e..412d0ff 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/TransportImplTest.java
@@ -24,8 +24,8 @@ import static org.apache.qpid.proton.engine.impl.TransportTestHelper.stringOfLen
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -44,6 +44,7 @@ import org.apache.qpid.proton.amqp.messaging.Released;
 import org.apache.qpid.proton.amqp.transport.Attach;
 import org.apache.qpid.proton.amqp.transport.Begin;
 import org.apache.qpid.proton.amqp.transport.Close;
+import org.apache.qpid.proton.amqp.transport.Detach;
 import org.apache.qpid.proton.amqp.transport.End;
 import org.apache.qpid.proton.amqp.transport.Flow;
 import org.apache.qpid.proton.amqp.transport.FrameBody;
@@ -1103,6 +1104,63 @@ public class TransportImplTest
     }
 
     /**
+     * Verify that no Flow frame is emitted by the Transport should a Receiver
+     * have pending drain when a detach is sent for that receiver.
+     */
+    @Test
+    public void testNoReceiverFlowAfterDetachSentWhileDraining()
+    {
+        MockTransportImpl transport = new MockTransportImpl();
+        Connection connection = Proton.connection();
+        transport.bind(connection);
+
+        connection.open();
+
+        Session session = connection.session();
+        session.open();
+
+        String linkName = "myReceiver";
+        Receiver receiver = session.receiver(linkName);
+        receiver.open();
+
+        pumpMockTransport(transport);
+
+        assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
+
+        assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
+        assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
+        assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);
+
+        // Send the necessary responses to open/begin/attach
+        transport.handleFrame(new TransportFrame(0, new Open(), null));
+
+        Begin begin = new Begin();
+        begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
+        transport.handleFrame(new TransportFrame(0, begin, null));
+
+        Attach attach = new Attach();
+        attach.setHandle(UnsignedInteger.ZERO);
+        attach.setRole(Role.RECEIVER);
+        attach.setName(linkName);
+        attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
+        transport.handleFrame(new TransportFrame(0, attach, null));
+
+        assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
+
+        // Start a drain for the Receiver and verify the transport doesn't
+        // send any Flow frame, due to the detach being initiated.
+        receiver.drain(10);
+        pumpMockTransport(transport);
+
+        // Cause the Detach frame to be sent
+        receiver.detach();
+        pumpMockTransport(transport);
+
+        assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
+        assertTrue("Unexpected frame type", transport.writes.get(4) instanceof Detach);
+    }
+
+    /**
      * Verify that no Flow frame is emitted by the Transport should a Sender
      * have credit drained added after the Close frame was sent.
      */


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org