You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2017/12/18 08:26:18 UTC

qpid-broker-j git commit: QPID-8038: [Broker-J] [AMQP 0-10] Add exchange protocol tests

Repository: qpid-broker-j
Updated Branches:
  refs/heads/master 95d34b922 -> 8662f8cec


QPID-8038: [Broker-J] [AMQP 0-10] Add exchange protocol tests


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/8662f8ce
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/8662f8ce
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/8662f8ce

Branch: refs/heads/master
Commit: 8662f8cecbc3fa85bd22e141af5dba5ea92abe52
Parents: 95d34b9
Author: Keith Wall <kw...@apache.org>
Authored: Thu Dec 14 15:44:08 2017 +0000
Committer: Keith Wall <kw...@apache.org>
Committed: Mon Dec 18 08:24:26 2017 +0000

----------------------------------------------------------------------
 .../protocol/v0_10/ExchangeInteraction.java     | 127 ++++++++
 .../qpid/tests/protocol/v0_10/Interaction.java  |   7 +
 .../tests/protocol/v0_10/QueueInteraction.java  |  41 ++-
 .../qpid/tests/protocol/v0_10/ExchangeTest.java | 297 +++++++++++++++++++
 .../qpid/tests/protocol/v0_10/QueueTest.java    | 109 ++++++-
 5 files changed, 578 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/8662f8ce/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/ExchangeInteraction.java
----------------------------------------------------------------------
diff --git a/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/ExchangeInteraction.java b/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/ExchangeInteraction.java
new file mode 100644
index 0000000..e241bf9
--- /dev/null
+++ b/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/ExchangeInteraction.java
@@ -0,0 +1,127 @@
+/*
+ *
+ * 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.qpid.tests.protocol.v0_10;
+
+import org.apache.qpid.server.protocol.v0_10.transport.ExchangeDeclare;
+import org.apache.qpid.server.protocol.v0_10.transport.ExchangeDelete;
+import org.apache.qpid.server.protocol.v0_10.transport.ExchangeQuery;
+
+public class ExchangeInteraction
+{
+    private final Interaction _interaction;
+    private final ExchangeDeclare _declare;
+    private final ExchangeDelete _delete;
+    private final ExchangeQuery _query;
+
+    public ExchangeInteraction(final Interaction interaction)
+    {
+        _interaction = interaction;
+        _declare = new ExchangeDeclare();
+        _delete = new ExchangeDelete();
+        _query = new ExchangeQuery();
+    }
+
+    public ExchangeInteraction declareExchange(final String exchange)
+    {
+        _declare.setExchange(exchange);
+        return this;
+    }
+
+    public ExchangeInteraction declareId(final int id)
+    {
+        _declare.setId(id);
+        return this;
+    }
+    public ExchangeInteraction declareType(final String type)
+    {
+        _declare.setType(type);
+        return this;
+    }
+
+    public ExchangeInteraction declarePassive(final boolean passive)
+    {
+        _declare.setPassive(passive);
+        return this;
+    }
+
+    public ExchangeInteraction declareDurable(final boolean durable)
+    {
+        _declare.setDurable(durable);
+        return this;
+    }
+
+    public ExchangeInteraction declareAlternateExchange(final String alternateExchange)
+    {
+        _declare.setAlternateExchange(alternateExchange);
+        return this;
+    }
+
+    public ExchangeInteraction declareAutoDelete(final boolean autoDelete)
+    {
+        _declare.setAutoDelete(autoDelete);
+        return this;
+    }
+
+    public Interaction declare() throws Exception
+    {
+        return _interaction.sendPerformative(_declare);
+    }
+
+    public ExchangeInteraction deleteExchange(final String exchangeName)
+    {
+        _delete.setExchange(exchangeName);
+        return this;
+    }
+
+    public ExchangeInteraction deleteId(final int id)
+    {
+        _delete.setId(id);
+        return this;
+    }
+
+    public ExchangeInteraction deleteIfUnused(final boolean ifUnused)
+    {
+        _delete.ifUnused(ifUnused);
+        return this;
+    }
+
+    public Interaction delete() throws Exception
+    {
+        return _interaction.sendPerformative(_delete);
+    }
+
+    public ExchangeInteraction queryExchange(final String name)
+    {
+        _query.setName(name);
+        return this;
+    }
+
+    public ExchangeInteraction queryId(final int id)
+    {
+        _query.setId(id);
+        return this;
+    }
+
+    public Interaction query() throws Exception
+    {
+        return _interaction.sendPerformative(_query);
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/8662f8ce/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/Interaction.java
----------------------------------------------------------------------
diff --git a/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/Interaction.java b/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/Interaction.java
index 0679386..771fad1 100644
--- a/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/Interaction.java
+++ b/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/Interaction.java
@@ -39,6 +39,7 @@ public class Interaction extends AbstractInteraction<Interaction>
     private MessageInteraction _messageInteraction;
     private ExecutionInteraction _executionInteraction;
     private QueueInteraction _queueInteraction;
+    private ExchangeInteraction _exchangeInteraction;
     private int _channelId;
     private TxInteraction _txInteraction;
 
@@ -51,6 +52,7 @@ public class Interaction extends AbstractInteraction<Interaction>
         _executionInteraction = new ExecutionInteraction(this);
         _txInteraction = new TxInteraction(this);
         _queueInteraction = new QueueInteraction(this);
+        _exchangeInteraction = new ExchangeInteraction(this);
     }
 
     @Override
@@ -143,4 +145,9 @@ public class Interaction extends AbstractInteraction<Interaction>
     {
         return _queueInteraction;
     }
+
+    public ExchangeInteraction exchange()
+    {
+        return _exchangeInteraction;
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/8662f8ce/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/QueueInteraction.java
----------------------------------------------------------------------
diff --git a/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/QueueInteraction.java b/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/QueueInteraction.java
index 7e15099..ca3edee 100644
--- a/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/QueueInteraction.java
+++ b/systests/protocol-tests-amqp-0-10/src/main/java/org/apache/qpid/tests/protocol/v0_10/QueueInteraction.java
@@ -22,20 +22,24 @@ package org.apache.qpid.tests.protocol.v0_10;
 
 import org.apache.qpid.server.protocol.v0_10.transport.QueueDeclare;
 import org.apache.qpid.server.protocol.v0_10.transport.QueueDelete;
-import org.apache.qpid.server.protocol.v0_10.transport.TxCommit;
-import org.apache.qpid.server.protocol.v0_10.transport.TxSelect;
+import org.apache.qpid.server.protocol.v0_10.transport.QueuePurge;
+import org.apache.qpid.server.protocol.v0_10.transport.QueueQuery;
 
 public class QueueInteraction
 {
     private final Interaction _interaction;
     private final QueueDeclare _declare;
     private final QueueDelete _delete;
+    private final QueuePurge _purge;
+    private final QueueQuery _query;
 
     public QueueInteraction(final Interaction interaction)
     {
         _interaction = interaction;
         _declare = new QueueDeclare();
         _delete = new QueueDelete();
+        _purge = new QueuePurge();
+        _query = new QueueQuery();
     }
 
     public QueueInteraction declareQueue(final String queue)
@@ -106,4 +110,37 @@ public class QueueInteraction
     {
         return _interaction.sendPerformative(_delete);
     }
+
+    public QueueInteraction purgeQueue(final String queueName)
+    {
+        _purge.setQueue(queueName);
+        return this;
+    }
+
+    public QueueInteraction purgeId(final int id)
+    {
+        _purge.setId(id);
+        return this;
+    }
+    public Interaction purge() throws Exception
+    {
+        return _interaction.sendPerformative(_purge);
+    }
+
+    public QueueInteraction queryQueue(final String queueName)
+    {
+        _query.setQueue(queueName);
+        return this;
+    }
+
+    public QueueInteraction queryId(final int id)
+    {
+        _query.setId(id);
+        return this;
+    }
+
+    public Interaction query() throws Exception
+    {
+        return _interaction.sendPerformative(_query);
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/8662f8ce/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/ExchangeTest.java
----------------------------------------------------------------------
diff --git a/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/ExchangeTest.java b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/ExchangeTest.java
new file mode 100644
index 0000000..9ce99e7
--- /dev/null
+++ b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/ExchangeTest.java
@@ -0,0 +1,297 @@
+/*
+ *
+ * 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.qpid.tests.protocol.v0_10;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assume.assumeThat;
+
+import java.net.InetSocketAddress;
+
+import org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.qpid.server.exchange.ExchangeDefaults;
+import org.apache.qpid.server.protocol.v0_10.transport.ExchangeQueryResult;
+import org.apache.qpid.server.protocol.v0_10.transport.ExecutionErrorCode;
+import org.apache.qpid.server.protocol.v0_10.transport.ExecutionException;
+import org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult;
+import org.apache.qpid.server.protocol.v0_10.transport.SessionCommandPoint;
+import org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted;
+import org.apache.qpid.tests.protocol.SpecificationTest;
+import org.apache.qpid.tests.utils.BrokerAdmin;
+import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
+
+public class ExchangeTest extends BrokerAdminUsingTestBase
+{
+    private InetSocketAddress _brokerAddress;
+    private static final byte[] SESSION_NAME = "test".getBytes(UTF_8);
+
+    @Before
+    public void setUp()
+    {
+        _brokerAddress = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
+    }
+
+    @Test
+    @SpecificationTest(section = "10.exchange.declare", description = "verify exchange exists, create if needed.")
+    public void exchangeDeclare() throws Exception
+    {
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            SessionCompleted completed = interaction.openAnonymousConnection()
+                                                    .channelId(1)
+                                                    .attachSession(SESSION_NAME)
+                                                    .exchange()
+                                                    .declareExchange("myexch")
+                                                    .declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)
+                                                    .declareId(0)
+                                                    .declare()
+                                                    .session()
+                                                    .flushCompleted()
+                                                    .flush()
+                                                    .consumeResponse()
+                                                    .getLatestResponse(SessionCompleted.class);
+
+            assertThat(completed.getCommands().includes(0), is(equalTo(true)));
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.exchange.declare",
+            description = "In the event that a message cannot be routed, this is the name of the exchange to which the"
+                          + " message will be sent.")
+    public void exchangeDeclareWithAlternateExchange() throws Exception
+    {
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            interaction.openAnonymousConnection()
+                       .channelId(1)
+                       .attachSession(SESSION_NAME)
+                       .exchange()
+                       .declareExchange("myexch")
+                       .declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)
+                       .declareAlternateExchange(ExchangeDefaults.DIRECT_EXCHANGE_NAME)
+                       .declareId(0)
+                       .declare()
+                       .session()
+                       .flushCompleted()
+                       .flush()
+                       .consumeResponse(SessionCompleted.class);
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.exchange.declare",
+            description = "if the alternate-exchange does not match the name of any existing exchange on the server, "
+                          + "then an exception must be raised.")
+    public void exchangeDeclareAlternateExchangeNotFound() throws Exception
+    {
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            ExecutionException response = interaction.openAnonymousConnection()
+                                                     .channelId(1)
+                                                     .attachSession(SESSION_NAME)
+                                                     .exchange()
+                                                     .declareExchange("myexch")
+                                                     .declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)
+                                                     .declareAlternateExchange("unknownExchange")
+                                                     .declareId(0)
+                                                     .declare()
+                                                     .session()
+                                                     .flushCompleted()
+                                                     .flush()
+                                                     .consumeResponse(SessionCommandPoint.class)
+                                                     .consumeResponse()
+                                                     .getLatestResponse(ExecutionException.class);
+
+            assertThat(response.getErrorCode(), is(equalTo(ExecutionErrorCode.NOT_FOUND)));
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.exchange.declare",
+            description = "If set [durable] when creating a new exchange, the exchange will be marked as durable. "
+                          + "Durable exchanges remain active when a server restarts. ")
+    public void exchangeDeclareDurable() throws Exception
+    {
+        String exchangeName = "myexch";
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            interaction.openAnonymousConnection()
+                       .channelId(1)
+                       .attachSession(SESSION_NAME)
+                       .exchange()
+                       .declareExchange(exchangeName)
+                       .declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)
+                       .declareId(0)
+                       .declareDurable(true)
+                       .declare()
+                       .session()
+                       .flushCompleted()
+                       .flush()
+                       .consumeResponse(SessionCompleted.class);
+        }
+
+        assumeThat(getBrokerAdmin().supportsRestart(), Matchers.is(true));
+        getBrokerAdmin().restart();
+
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            interaction.openAnonymousConnection()
+                       .channelId(1)
+                       .attachSession(SESSION_NAME)
+                       .exchange()
+                       .declareExchange(exchangeName)
+                       .declarePassive(true)
+                       .declareId(0)
+                       .declare()
+                       .session()
+                       .flushCompleted()
+                       .flush()
+                       .consumeResponse()
+                       .getLatestResponse(SessionCompleted.class);
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.exchange.delete", description = "delete an exchange")
+    public void exchangeDelete() throws Exception
+    {
+        String exchangeName = "myexch";
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            interaction.openAnonymousConnection()
+                       .channelId(1)
+                       .attachSession(SESSION_NAME)
+                       .exchange()
+                       .declareExchange(exchangeName)
+                       .declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)
+                       .declareId(0)
+                       .declare()
+                       .session()
+                       .flushCompleted()
+                       .flush()
+                       .consumeResponse(SessionCompleted.class);
+
+            interaction.exchange()
+                       .deleteExchange(exchangeName)
+                       .deleteId(1)
+                       .delete()
+                       .session()
+                       .flushCompleted()
+                       .flush()
+                       .consumeResponse(SessionCompleted.class);
+
+            ExecutionResult result = interaction.exchange()
+                                                .queryExchange(exchangeName)
+                                                .queryId(2)
+                                                .query()
+                                                .session()
+                                                .flushCompleted()
+                                                .flush()
+                                                .consumeResponse(SessionCommandPoint.class)
+                                                .consumeResponse().getLatestResponse(ExecutionResult.class);
+            ExchangeQueryResult queryResult = (ExchangeQueryResult) result.getValue();
+            assertThat(queryResult.getNotFound(), is(equalTo(true)));
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.exchange.delete",
+            description = "An exchange MUST NOT be deleted if it is in use as an alternate-exchange by a queue or by "
+                          + "another exchange.")
+    public void exchangeDeleteInUseAsAlternate() throws Exception
+    {
+        String exchangeName1 = "myexch1";
+        String exchangeName2 = "myexch2";
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            ExecutionException response = interaction.openAnonymousConnection()
+                                                     .channelId(1)
+                                                     .attachSession(SESSION_NAME)
+                                                     .exchange()
+                                                     .declareExchange(exchangeName1)
+                                                     .declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)
+                                                     .declareId(0)
+                                                     .declare()
+                                                     .exchange()
+                                                     .declareExchange(exchangeName2)
+                                                     .declareAlternateExchange(exchangeName1)
+                                                     .declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)
+                                                     .declareId(1)
+                                                     .declare()
+                                                     .exchange()
+                                                     .deleteExchange(exchangeName1)
+                                                     .deleteId(2)
+                                                     .delete()
+                                                     .session()
+                                                     .flushCompleted()
+                                                     .flush()
+                                                     .consumeResponse(SessionCommandPoint.class)
+                                                     .consumeResponse()
+                                                     .getLatestResponse(ExecutionException.class);
+
+            assertThat(response.getErrorCode(), is(equalTo(ExecutionErrorCode.NOT_ALLOWED)));
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.exchange.query", description = "request information about an exchange")
+    public void exchangeQuery() throws Exception
+    {
+        String exchangeName = "myexch";
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            ExecutionResult result = interaction.openAnonymousConnection()
+                                                .channelId(1)
+                                                .attachSession(SESSION_NAME)
+                                                .exchange()
+                                                .declareId(0)
+                                                .declareExchange(exchangeName)
+                                                .declareType(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)
+                                                .declare()
+                                                .exchange()
+                                                .queryId(1)
+                                                .queryExchange(exchangeName)
+                                                .query()
+                                                .session()
+                                                .flushCompleted()
+                                                .flush()
+                                                .consumeResponse(SessionCommandPoint.class)
+                                                .consumeResponse().getLatestResponse(ExecutionResult.class);
+            ExchangeQueryResult queryResult = (ExchangeQueryResult) result.getValue();
+            assertThat(queryResult.getNotFound(), is(equalTo(false)));
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/8662f8ce/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/QueueTest.java
----------------------------------------------------------------------
diff --git a/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/QueueTest.java b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/QueueTest.java
index f65111f..32ac9b9 100644
--- a/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/QueueTest.java
+++ b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/QueueTest.java
@@ -22,6 +22,7 @@ package org.apache.qpid.tests.protocol.v0_10;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assume.assumeThat;
@@ -34,9 +35,12 @@ import org.junit.Test;
 
 import org.apache.qpid.server.protocol.v0_10.transport.ExecutionErrorCode;
 import org.apache.qpid.server.protocol.v0_10.transport.ExecutionException;
+import org.apache.qpid.server.protocol.v0_10.transport.ExecutionResult;
+import org.apache.qpid.server.protocol.v0_10.transport.QueueQueryResult;
 import org.apache.qpid.server.protocol.v0_10.transport.SessionCommandPoint;
 import org.apache.qpid.server.protocol.v0_10.transport.SessionCompleted;
 import org.apache.qpid.server.protocol.v0_10.transport.SessionDetached;
+import org.apache.qpid.server.protocol.v0_10.transport.SessionFlush;
 import org.apache.qpid.tests.protocol.SpecificationTest;
 import org.apache.qpid.tests.utils.BrokerAdmin;
 import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
@@ -529,7 +533,6 @@ public class QueueTest extends BrokerAdminUsingTestBase
             assertThat(response.getErrorCode(), is(equalTo(ExecutionErrorCode.NOT_FOUND)));
         }
     }
-
     @Test
     @SpecificationTest(section = "10.queue.delete",
             description = "If set, the server will only delete the queue if it has no consumers. If the queue has "
@@ -594,4 +597,108 @@ public class QueueTest extends BrokerAdminUsingTestBase
                                .consumeResponse(SessionCompleted.class);
         }
     }
+
+    @Test
+    @SpecificationTest(section = "10.queue.purge", description = "This command removes all messages from a queue.")
+    public void queuePurge() throws Exception
+    {
+        getBrokerAdmin().createQueue(BrokerAdmin.TEST_QUEUE_NAME);
+        getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, "message");
+
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            ExecutionResult result = interaction.openAnonymousConnection()
+                                                .channelId(1)
+                                                .attachSession(SESSION_NAME)
+                                                .queue()
+                                                .queryQueue(BrokerAdmin.TEST_QUEUE_NAME)
+                                                .queryId(1)
+                                                .query()
+                                                .session()
+                                                .flushCompleted()
+                                                .flush()
+                                                .consumeResponse(SessionCommandPoint.class)
+                                                .consumeResponse().getLatestResponse(ExecutionResult.class);
+            assertThat(((QueueQueryResult) result.getValue()).getMessageCount(), is(1L));
+
+            interaction.queue()
+                    .purgeQueue(BrokerAdmin.TEST_QUEUE_NAME)
+                    .purgeId(0)
+                    .purge()
+                    .session()
+                    .flushCompleted()
+                    .flush()
+                    .consumeResponse(SessionFlush.class)
+                    .consumeResponse(SessionCompleted.class);
+
+            result = interaction.queue()
+                                .queryQueue(BrokerAdmin.TEST_QUEUE_NAME)
+                                .queryId(1)
+                                .query()
+                                .session()
+                                .flushCompleted()
+                                .flush()
+                                .consumeResponse(SessionCompleted.class)
+                                .consumeResponse().getLatestResponse(ExecutionResult.class);
+            assertThat(((QueueQueryResult) result.getValue()).getMessageCount(), is(0L));
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.queue.purge",
+            description = "The queue must exist. If the client attempts to purge a non-existing queue the server "
+                          + "MUST raise an exception.")
+    public void queuePurgeQueueNotFound() throws Exception
+    {
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            ExecutionException response = interaction.openAnonymousConnection()
+                                                     .channelId(1)
+                                                     .attachSession(SESSION_NAME)
+                                                     .queue()
+                                                     .purgeQueue(BrokerAdmin.TEST_QUEUE_NAME)
+                                                     .purgeId(0)
+                                                     .purge()
+                                                     .session()
+                                                     .flushCompleted()
+                                                     .flush()
+                                                     .consumeResponse(SessionCommandPoint.class)
+                                                     .consumeResponse()
+                                                     .getLatestResponse(ExecutionException.class);
+
+            assertThat(response.getErrorCode(), is(equalTo(ExecutionErrorCode.NOT_FOUND)));
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.queue.query",
+            description = "This command requests information about a queue.")
+    public void queueQuery() throws Exception
+    {
+        getBrokerAdmin().createQueue(BrokerAdmin.TEST_QUEUE_NAME);
+        getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, "message");
+
+        try (FrameTransport transport = new FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            ExecutionResult result = interaction.openAnonymousConnection()
+                                                        .channelId(1)
+                                                        .attachSession(SESSION_NAME)
+                                                        .queue()
+                                                        .queryQueue(BrokerAdmin.TEST_QUEUE_NAME)
+                                                        .queryId(0)
+                                                        .query()
+                                                        .session()
+                                                        .flushCompleted()
+                                                        .flush()
+                                                        .consumeResponse(SessionCommandPoint.class)
+                                                        .consumeResponse().getLatestResponse(ExecutionResult.class);
+            QueueQueryResult queryResult = (QueueQueryResult) result.getValue();
+            assertThat(queryResult.getQueue(), is(equalTo(BrokerAdmin.TEST_QUEUE_NAME)));
+            assertThat(queryResult.getAlternateExchange(), is(nullValue()));
+            assertThat(queryResult.getMessageCount(), is(1L));
+        }
+    }
 }


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