ARTEMIS-638 Only allocate credits once Link Attach

Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/5dfa1c59
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/5dfa1c59
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/5dfa1c59

Branch: refs/heads/master
Commit: 5dfa1c59fb2d718b26d77931b4d562c40fd74256
Parents: df41a60
Author: Martyn Taylor <[email protected]>
Authored: Mon Jul 18 13:54:41 2016 +0100
Committer: Andy Taylor <[email protected]>
Committed: Wed Jul 20 10:33:44 2016 +0100

----------------------------------------------------------------------
 .../server/ProtonServerConnectionContext.java   |  1 -
 .../tests/integration/proton/ProtonTest.java    | 24 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/5dfa1c59/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContext.java
----------------------------------------------------------------------
diff --git 
a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContext.java
 
b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContext.java
index db04a8a..b7d2a98 100644
--- 
a/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContext.java
+++ 
b/artemis-protocols/artemis-proton-plug/src/main/java/org/proton/plug/context/server/ProtonServerConnectionContext.java
@@ -69,7 +69,6 @@ public class ProtonServerConnectionContext extends 
AbstractConnectionContext imp
          }
          else {
             protonSession.addReceiver(receiver);
-            receiver.flow(100);
          }
       }
       else {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/5dfa1c59/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java
----------------------------------------------------------------------
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java
index d803e9e..4d41ff5 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/proton/ProtonTest.java
@@ -157,6 +157,30 @@ public class ProtonTest extends ActiveMQTestBase {
    }
 
    @Test
+   public void testCreditsAreAllocatedOnlyOnceOnLinkCreate() throws Exception {
+      if (protocol != 0 && protocol != 3) return; // Only run this test for 
AMQP protocol
+
+      // Only allow 1 credit to be submitted at a time.
+      Field maxCreditAllocation = 
ProtonServerReceiverContext.class.getDeclaredField("maxCreditAllocation");
+      maxCreditAllocation.setAccessible(true);
+      int originalMaxCreditAllocation = maxCreditAllocation.getInt(null);
+      maxCreditAllocation.setInt(null, 1);
+
+      String destinationAddress = address + 1;
+      AmqpClient client = new AmqpClient(new URI("tcp://localhost:5672"), 
userName, password);
+      AmqpConnection amqpConnection = client.connect();
+      try {
+         AmqpSession session = amqpConnection.createSession();
+         AmqpSender sender = session.createSender(destinationAddress);
+         assertTrue(sender.getSender().getCredit() == 1);
+      }
+      finally {
+         amqpConnection.close();
+         maxCreditAllocation.setInt(null, originalMaxCreditAllocation);
+      }
+   }
+
+   @Test
    public void testTemporaryQueue() throws Throwable {
 
       Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);

Reply via email to