Repository: qpid-broker-j
Updated Branches:
  refs/heads/master 612c2cb6c -> ff2980e2d


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/MessageTest.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/MessageTest.java
 
b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/MessageTest.java
new file mode 100644
index 0000000..9a477dc
--- /dev/null
+++ 
b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/MessageTest.java
@@ -0,0 +1,260 @@
+/*
+ *
+ * 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.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.protocol.v0_10.transport.MessageAcceptMode;
+import org.apache.qpid.server.protocol.v0_10.transport.MessageAcquireMode;
+import org.apache.qpid.server.protocol.v0_10.transport.MessageCreditUnit;
+import org.apache.qpid.server.protocol.v0_10.transport.MessageTransfer;
+import org.apache.qpid.server.protocol.v0_10.transport.Method;
+import org.apache.qpid.server.protocol.v0_10.transport.Range;
+import org.apache.qpid.server.protocol.v0_10.transport.RangeSet;
+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.SessionConfirmed;
+import org.apache.qpid.server.protocol.v0_10.transport.SessionFlush;
+import org.apache.qpid.tests.protocol.Response;
+import org.apache.qpid.tests.protocol.SpecificationTest;
+import org.apache.qpid.tests.utils.BrokerAdmin;
+import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
+
+public class MessageTest extends BrokerAdminUsingTestBase
+{
+    private InetSocketAddress _brokerAddress;
+
+    @Before
+    public void setUp()
+    {
+        _brokerAddress = 
getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
+        getBrokerAdmin().createQueue(BrokerAdmin.TEST_QUEUE_NAME);
+    }
+
+    @Test
+    @SpecificationTest(section = "10.message.transfer",
+            description = "This command transfers a message between two 
peers.")
+    public void sendTransfer() throws Exception
+    {
+        try (FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            byte[] sessionName = "test".getBytes(UTF_8);
+            SessionCompleted completed = interaction.openAnonymousConnection()
+                                                    .channelId(1)
+                                                    .attachSession(sessionName)
+                                                    .message()
+                                                    
.transferDesitnation(BrokerAdmin.TEST_QUEUE_NAME)
+                                                    .transferId(0)
+                                                    .transfer()
+                                                    .session()
+                                                    .flushCompleted()
+                                                    .flush()
+                                                    .consumeResponse()
+                                                    
.getLatestResponse(SessionCompleted.class);
+
+            assertThat(completed.getCommands().includes(0), is(equalTo(true)));
+            int queueDepthMessages = 
getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME);
+            assertThat(queueDepthMessages, is(equalTo(1)));
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.message.subscribe",
+            description = "This command asks the server to start a 
\"subscription\","
+                          + " which is a request for messages from a specific 
queue.")
+    public void subscribe() throws Exception
+    {
+        try (FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            byte[] sessionName = "testSession".getBytes(UTF_8);
+            final String subscriberName = "testSubscriber";
+            interaction.openAnonymousConnection()
+                       .channelId(1)
+                       .attachSession(sessionName)
+                       .message()
+                       .subscribeDestination(subscriberName)
+                       .subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME)
+                       .subscribeId(0)
+                       .subscribe()
+                       .session()
+                       .flushCompleted()
+                       .flush();
+
+            SessionCompleted completed = consumeResponse(interaction,
+                                                         
SessionCompleted.class,
+                                                         
SessionCommandPoint.class,
+                                                         
SessionConfirmed.class);
+
+            assertThat(completed.getCommands(), is(notNullValue()));
+            assertThat(completed.getCommands().includes(0), is(equalTo(true)));
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.message.transfer",
+            description = "The client may request a broker to transfer 
messages to it, from a particular queue,"
+                          + " by issuing a subscribe command. The subscribe 
command specifies the destination"
+                          + " that the broker should use for any resulting 
transfers.")
+    public void receiveTransfer() throws Exception
+    {
+        String testMessageBody = "testMessage";
+        getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, 
testMessageBody);
+        try (FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            byte[] sessionName = "testSession".getBytes(UTF_8);
+            final String subscriberName = "testSubscriber";
+            interaction.openAnonymousConnection()
+                       .channelId(1)
+                       .attachSession(sessionName)
+                       .message()
+                       .subscribeDestination(subscriberName)
+                       .subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME)
+                       .subscribeId(0)
+                       .subscribe()
+                       .message()
+                       .flowId(1)
+                       .flowDestination(subscriberName)
+                       .flowUnit(MessageCreditUnit.MESSAGE)
+                       .flowValue(1)
+                       .flow()
+                       .message()
+                       .flowId(2)
+                       .flowDestination(subscriberName)
+                       .flowUnit(MessageCreditUnit.BYTE)
+                       .flowValue(-1)
+                       .flow();
+
+            MessageTransfer transfer = consumeResponse(interaction,
+                                                       MessageTransfer.class,
+                                                       SessionCompleted.class,
+                                                       
SessionCommandPoint.class,
+                                                       SessionConfirmed.class);
+
+            try (QpidByteBuffer buffer = transfer.getBody())
+            {
+                final byte[] dst = new byte[buffer.remaining()];
+                buffer.get(dst);
+                assertThat(new String(dst, UTF_8), 
is(equalTo(testMessageBody)));
+            }
+        }
+    }
+
+    @Test
+    @SpecificationTest(section = "10.message.accept",
+            description = "Accepts the message.")
+    public void acceptTransfer() throws Exception
+    {
+        String testMessageBody = "testMessage";
+        getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, 
testMessageBody);
+        try (FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            byte[] sessionName = "testSession".getBytes(UTF_8);
+            final String subscriberName = "testSubscriber";
+            interaction.openAnonymousConnection()
+                       .channelId(1)
+                       .attachSession(sessionName)
+                       .message()
+                       .subscribeAcceptMode(MessageAcceptMode.EXPLICIT)
+                       .subscribeAcquireMode(MessageAcquireMode.PRE_ACQUIRED)
+                       .subscribeDestination(subscriberName)
+                       .subscribeQueue(BrokerAdmin.TEST_QUEUE_NAME)
+                       .subscribeId(0)
+                       .subscribe()
+                       .message()
+                       .flowId(1)
+                       .flowDestination(subscriberName)
+                       .flowUnit(MessageCreditUnit.MESSAGE)
+                       .flowValue(1)
+                       .flow()
+                       .message()
+                       .flowId(2)
+                       .flowDestination(subscriberName)
+                       .flowUnit(MessageCreditUnit.BYTE)
+                       .flowValue(-1)
+                       .flow();
+
+            MessageTransfer transfer = consumeResponse(interaction,
+                                                       MessageTransfer.class,
+                                                       SessionCompleted.class,
+                                                       
SessionCommandPoint.class,
+                                                       SessionConfirmed.class);
+
+            
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), 
is(equalTo(1)));
+
+            RangeSet transfers = Range.newInstance(transfer.getId());
+            
interaction.message().acceptId(3).acceptTransfers(transfers).accept()
+                       .session()
+                       .flushCompleted()
+                       .flush();
+
+            SessionCompleted completed = consumeResponse(interaction,
+                                                         
SessionCompleted.class,
+                                                         
SessionCommandPoint.class,
+                                                         
SessionConfirmed.class,
+                                                         SessionFlush.class);
+
+            assertThat(completed.getCommands(), is(notNullValue()));
+            assertThat(completed.getCommands().includes(3), is(equalTo(true)));
+
+            
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), 
is(equalTo(0)));
+        }
+    }
+
+    private <T extends Method> T consumeResponse(final Interaction interaction,
+                                                 final Class<T> expected,
+                                                 final Class<? extends 
Method>... ignore)
+            throws Exception
+    {
+        List<Class<? extends Method>> possibleResponses = new 
ArrayList<>(Arrays.asList(ignore));
+        possibleResponses.add(expected);
+
+        T completed = null;
+        do
+        {
+            interaction.consumeResponse(possibleResponses.toArray(new 
Class[possibleResponses.size()]));
+            Response<?> response = interaction.getLatestResponse();
+            if (expected.isAssignableFrom(response.getBody().getClass()))
+            {
+                completed = (T) response.getBody();
+            }
+        }
+        while (completed == null);
+        return completed;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/SessionTest.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/SessionTest.java
 
b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/SessionTest.java
new file mode 100644
index 0000000..51de2c2
--- /dev/null
+++ 
b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/SessionTest.java
@@ -0,0 +1,123 @@
+/*
+ *
+ * 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 org.hamcrest.MatcherAssert.assertThat;
+
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+
+import org.hamcrest.core.IsEqual;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.apache.qpid.server.protocol.v0_10.transport.SessionAttached;
+import org.apache.qpid.server.protocol.v0_10.transport.SessionDetached;
+import org.apache.qpid.tests.protocol.SpecificationTest;
+import org.apache.qpid.tests.utils.BrokerAdmin;
+import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
+
+public class SessionTest extends BrokerAdminUsingTestBase
+{
+    private InetSocketAddress _brokerAddress;
+
+    @Before
+    public void setUp()
+    {
+        _brokerAddress = 
getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
+    }
+
+    @Test
+    @SpecificationTest(section = "9.session.attach",
+            description = "Requests that the current transport be attached to 
the named session.")
+    public void attach() throws Exception
+    {
+        try(FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            byte[] sessionName = "test".getBytes(StandardCharsets.UTF_8);
+            SessionAttached sessionAttached = 
interaction.openAnonymousConnection()
+                                                         .channelId(1)
+                                                         .session()
+                                                         
.attachName(sessionName)
+                                                         .attach()
+                                                         .consumeResponse()
+                                                         
.getLatestResponse(SessionAttached.class);
+            assertThat(sessionAttached.getName(), 
IsEqual.equalTo(sessionName));
+        }
+    }
+
+
+    @Test
+    @SpecificationTest(section = "9.session.detach",
+            description = "Detaches the current transport from the named 
session.")
+    public void detach() throws Exception
+    {
+        try (FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            byte[] sessionName = "test".getBytes(StandardCharsets.UTF_8);
+            SessionDetached sessionDetached = 
interaction.openAnonymousConnection()
+                                                         .channelId(1)
+                                                         .session()
+                                                         
.attachName(sessionName)
+                                                         .attach()
+                                                         
.consumeResponse(SessionAttached.class)
+                                                         .session()
+                                                         
.detachName(sessionName)
+                                                         .detach()
+                                                         .consumeResponse()
+                                                         
.getLatestResponse(SessionDetached.class);
+
+            assertThat(sessionDetached.getName(), 
IsEqual.equalTo(sessionName));
+        }
+    }
+
+
+    @Ignore("QPID-8047")
+    @Test
+    @SpecificationTest(section = "9.session",
+            description = "The transport MUST be attached in order to use any 
control other than"
+                          + " \"attach\", \"attached\", \"detach\", or 
\"detached\"."
+                          + " A peer receiving any other control on a detached 
transport MUST discard it and send a"
+                          + " session.detached with the \"not-attached\" 
reason code.")
+    public void detachUnknownSession() throws Exception
+    {
+        try (FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            byte[] sessionName = "test".getBytes(StandardCharsets.UTF_8);
+            SessionDetached sessionDetached = 
interaction.openAnonymousConnection()
+                                                         .channelId(1)
+                                                         .session()
+                                                         
.detachName(sessionName)
+                                                         .detach()
+                                                         .consumeResponse()
+                                                         
.getLatestResponse(SessionDetached.class);
+
+            assertThat(sessionDetached.getName(), 
IsEqual.equalTo(sessionName));
+        }
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/TransactionTest.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/TransactionTest.java
 
b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/TransactionTest.java
new file mode 100644
index 0000000..337ada3
--- /dev/null
+++ 
b/systests/protocol-tests-amqp-0-10/src/test/java/org/apache/qpid/tests/protocol/v0_10/TransactionTest.java
@@ -0,0 +1,92 @@
+/*
+ *
+ * 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 java.net.InetSocketAddress;
+
+import org.junit.Before;
+import org.junit.Test;
+
+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 TransactionTest extends BrokerAdminUsingTestBase
+{
+    private InetSocketAddress _brokerAddress;
+
+    @Before
+    public void setUp()
+    {
+        _brokerAddress = 
getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
+        getBrokerAdmin().createQueue(BrokerAdmin.TEST_QUEUE_NAME);
+    }
+
+    @Test
+    @SpecificationTest(section = "10.tx.commit",
+            description = "This command commits all messages published and 
accepted in the current transaction.")
+    public void messageSendCommit() throws Exception
+    {
+        try (FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            byte[] sessionName = "test".getBytes(UTF_8);
+            interaction.openAnonymousConnection()
+                       .channelId(1)
+                       .attachSession(sessionName)
+                       .tx().selectId(0).select()
+                       .message()
+                       .transferDesitnation(BrokerAdmin.TEST_QUEUE_NAME)
+                       .transferId(1)
+                       .transfer()
+                       .session()
+                       .flushCompleted()
+                       .flush();
+
+            SessionCompleted completed;
+            do
+            {
+                completed = 
interaction.consumeResponse().getLatestResponse(SessionCompleted.class);
+            }
+            while (!completed.getCommands().includes(1));
+
+            int queueDepthMessages = 
getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME);
+            assertThat(queueDepthMessages, is(equalTo(0)));
+
+            interaction.tx().commitId(2).commit()
+                       .session()
+                       .flushCompleted()
+                       .flush();
+
+            completed = 
interaction.consumeResponse().getLatestResponse(SessionCompleted.class);
+            assertThat(completed.getCommands().includes(2), is(equalTo(true)));
+
+            queueDepthMessages = 
getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME);
+            assertThat(queueDepthMessages, is(equalTo(1)));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/ExchangeInteraction.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/ExchangeInteraction.java
 
b/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/ExchangeInteraction.java
new file mode 100644
index 0000000..f4ed0a2
--- /dev/null
+++ 
b/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/ExchangeInteraction.java
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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_8;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.server.protocol.v0_8.AMQShortString;
+import org.apache.qpid.server.protocol.v0_8.FieldTable;
+import org.apache.qpid.server.protocol.v0_8.transport.ExchangeDeclareBody;
+
+public class ExchangeInteraction
+{
+    private Interaction _interaction;
+    private String _decalreExchange = "amq.direct";
+    private String _declareType = "direct";
+    private boolean _declarePassive = true;
+    private boolean _declareDurable = true;
+    private boolean _declareAutoDelete = false;
+    private boolean _declareNoWait = false;
+    private Map<String, Object> _declareArguments = new HashMap<>();
+
+    public ExchangeInteraction(final Interaction interaction)
+    {
+        _interaction = interaction;
+    }
+
+    public Interaction declare() throws Exception
+    {
+        return _interaction.sendPerformative(new ExchangeDeclareBody(0,
+                                                                     
AMQShortString.valueOf(_decalreExchange),
+                                                                     
AMQShortString.valueOf(_declareType),
+                                                                     
_declarePassive,
+                                                                     
_declareDurable,
+                                                                     
_declareAutoDelete,
+                                                                     false,
+                                                                     
_declareNoWait,
+                                                                     
FieldTable.convertToFieldTable(_declareArguments)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/FrameTransport.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/FrameTransport.java
 
b/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/FrameTransport.java
index 52cd7a0..0b5c4e4 100644
--- 
a/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/FrameTransport.java
+++ 
b/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/FrameTransport.java
@@ -26,18 +26,20 @@ import org.apache.qpid.server.model.Protocol;
 import org.apache.qpid.server.plugin.ProtocolEngineCreator;
 import org.apache.qpid.server.plugin.QpidServiceLoader;
 import org.apache.qpid.server.protocol.ProtocolVersion;
+import org.apache.qpid.tests.protocol.AbstractFrameTransport;
 
 
-public class FrameTransport extends 
org.apache.qpid.tests.protocol.FrameTransport
+public class FrameTransport extends AbstractFrameTransport<Interaction>
 {
     private final byte[] _protocolHeader;
     private ProtocolVersion _protocolVersion;
 
-    public FrameTransport(final InetSocketAddress brokerAddress)
+    FrameTransport(final InetSocketAddress brokerAddress)
     {
         this(brokerAddress, Protocol.AMQP_0_9_1);
     }
-    public FrameTransport(final InetSocketAddress brokerAddress, Protocol 
protocol)
+
+    FrameTransport(final InetSocketAddress brokerAddress, Protocol protocol)
     {
         super(brokerAddress, new FrameDecoder(getProtocolVersion(protocol)), 
new FrameEncoder());
         _protocolVersion = getProtocolVersion(protocol);
@@ -74,12 +76,12 @@ public class FrameTransport extends 
org.apache.qpid.tests.protocol.FrameTranspor
         return _protocolHeader;
     }
 
-    public ProtocolVersion getProtocolVersion()
+    ProtocolVersion getProtocolVersion()
     {
         return _protocolVersion;
     }
 
-    public static ProtocolVersion getProtocolVersion(Protocol protocol)
+    private static ProtocolVersion getProtocolVersion(Protocol protocol)
     {
         final ProtocolVersion protocolVersion;
         switch (protocol)

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/Interaction.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/Interaction.java
 
b/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/Interaction.java
index 35f4bf5..b990eae 100644
--- 
a/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/Interaction.java
+++ 
b/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/Interaction.java
@@ -26,8 +26,9 @@ import 
org.apache.qpid.server.protocol.v0_8.transport.AMQFrame;
 import org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody;
 import org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody;
 import org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody;
+import org.apache.qpid.tests.protocol.AbstractInteraction;
 
-public class Interaction extends 
org.apache.qpid.tests.protocol.Interaction<Interaction>
+public class Interaction extends AbstractInteraction<Interaction>
 {
 
     private int _channelId;
@@ -36,6 +37,8 @@ public class Interaction extends 
org.apache.qpid.tests.protocol.Interaction<Inte
     private ChannelInteraction _channelInteraction;
     private QueueInteraction _queueInteraction;
     private BasicInteraction _basicInteraction;
+    private TxInteraction _txInteraction;
+    private ExchangeInteraction _exchangeInteraction;
 
     Interaction(final FrameTransport transport)
     {
@@ -44,6 +47,8 @@ public class Interaction extends 
org.apache.qpid.tests.protocol.Interaction<Inte
         _channelInteraction = new ChannelInteraction(this);
         _queueInteraction = new QueueInteraction(this);
         _basicInteraction = new BasicInteraction(this);
+        _txInteraction = new TxInteraction(this);
+        _exchangeInteraction = new ExchangeInteraction(this);
     }
 
     @Override
@@ -52,12 +57,6 @@ public class Interaction extends 
org.apache.qpid.tests.protocol.Interaction<Inte
         return getTransport().getProtocolHeader();
     }
 
-    @Override
-    protected Interaction getInteraction()
-    {
-        return this;
-    }
-
     public Interaction sendPerformative(final AMQBody amqBody) throws Exception
     {
         return sendPerformative(_channelId, amqBody);
@@ -120,4 +119,14 @@ public class Interaction extends 
org.apache.qpid.tests.protocol.Interaction<Inte
     {
         return _basicInteraction;
     }
+
+    public TxInteraction tx()
+    {
+        return _txInteraction;
+    }
+
+    public ExchangeInteraction exchange()
+    {
+        return _exchangeInteraction;
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/TxInteraction.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/TxInteraction.java
 
b/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/TxInteraction.java
new file mode 100644
index 0000000..63a078a
--- /dev/null
+++ 
b/systests/protocol-tests-amqp-0-8/src/main/java/org/apache/qpid/tests/protocol/v0_8/TxInteraction.java
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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_8;
+
+import org.apache.qpid.server.protocol.v0_8.transport.TxCommitBody;
+import org.apache.qpid.server.protocol.v0_8.transport.TxSelectBody;
+
+public class TxInteraction
+{
+    private Interaction _interaction;
+
+    public TxInteraction(final Interaction interaction)
+    {
+        _interaction = interaction;
+    }
+
+    public Interaction select() throws Exception
+    {
+        return _interaction.sendPerformative(TxSelectBody.INSTANCE);
+    }
+
+    public Interaction commit() throws Exception
+    {
+        return _interaction.sendPerformative(TxCommitBody.INSTANCE);
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ChannelTest.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ChannelTest.java
 
b/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ChannelTest.java
index b5cf60d..40d1918 100644
--- 
a/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ChannelTest.java
+++ 
b/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ChannelTest.java
@@ -58,7 +58,7 @@ public class ChannelTest extends BrokerAdminUsingTestBase
 
     @Test
     @SpecificationTest(section = "1.5.2.5", description = "request a channel 
close")
-    public void channelClose() throws Exception
+    public void noFrameCanBeSentOnClosedChannel() throws Exception
     {
         try (FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
         {

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ConnectionTest.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ConnectionTest.java
 
b/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ConnectionTest.java
index b4909c6..fa4a692 100644
--- 
a/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ConnectionTest.java
+++ 
b/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/ConnectionTest.java
@@ -31,8 +31,10 @@ import org.junit.Test;
 
 import org.apache.qpid.server.protocol.v0_8.transport.ConnectionCloseBody;
 import org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody;
+import org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody;
 import org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody;
 import org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody;
+import org.apache.qpid.tests.protocol.ChannelClosedResponse;
 import org.apache.qpid.tests.protocol.SpecificationTest;
 import org.apache.qpid.tests.utils.BrokerAdmin;
 import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
@@ -119,7 +121,8 @@ public class ConnectionTest extends BrokerAdminUsingTestBase
                        .tuneOkFrameMax(1024)
                        .tuneOkHeartbeat(response.getHeartbeat())
                        .tuneOk()
-                       
.consumeResponse().getLatestResponse(ConnectionCloseBody.class);
+                       .connection().open()
+                       .consumeResponse(ConnectionCloseBody.class, 
ChannelClosedResponse.class);
         }
     }
 
@@ -144,7 +147,8 @@ public class ConnectionTest extends BrokerAdminUsingTestBase
                        .tuneOkFrameMax(Long.MAX_VALUE)
                        .tuneOkHeartbeat(response.getHeartbeat())
                        .tuneOk()
-                       
.consumeResponse().getLatestResponse(ConnectionCloseBody.class);
+                       .connection().open()
+                       .consumeResponse(ConnectionCloseBody.class, 
ChannelClosedResponse.class);
         }
     }
 
@@ -180,4 +184,22 @@ public class ConnectionTest extends 
BrokerAdminUsingTestBase
     }
 
 
+    @Test
+    @SpecificationTest(section = "9",
+            description = "open-connection = C:protocol-header S:START 
C:START-OK *challenge S:TUNE C:TUNE-OK C:OPEN S:OPEN-OK")
+    public void authenticationBypassAfterSendingStartOk() throws Exception
+    {
+        InetSocketAddress brokerAddress = 
getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
+        try(FrameTransport transport = new 
FrameTransport(brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            interaction.negotiateProtocol()
+                       .consumeResponse(ConnectionStartBody.class)
+                       
.connection().startOkMechanism("PLAIN").startOk().consumeResponse(ConnectionSecureBody.class)
+                       .connection().tuneOk()
+                       .connection().open()
+                       .consumeResponse(ConnectionCloseBody.class, 
ChannelClosedResponse.class);
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/TransactionTest.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/TransactionTest.java
 
b/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/TransactionTest.java
new file mode 100644
index 0000000..df677e8
--- /dev/null
+++ 
b/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/TransactionTest.java
@@ -0,0 +1,79 @@
+/*
+ *
+ * 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_8;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.net.InetSocketAddress;
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody;
+import org.apache.qpid.server.protocol.v0_8.transport.ExchangeDeclareOkBody;
+import org.apache.qpid.server.protocol.v0_8.transport.TxCommitOkBody;
+import org.apache.qpid.server.protocol.v0_8.transport.TxSelectOkBody;
+import org.apache.qpid.tests.protocol.SpecificationTest;
+import org.apache.qpid.tests.utils.BrokerAdmin;
+import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
+
+public class TransactionTest extends BrokerAdminUsingTestBase
+{
+    private InetSocketAddress _brokerAddress;
+
+    @Before
+    public void setUp()
+    {
+        _brokerAddress = 
getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
+        getBrokerAdmin().createQueue(BrokerAdmin.TEST_QUEUE_NAME);
+    }
+
+    @Test
+    @SpecificationTest(section = "1.9.2.3", description = "commit the current 
transaction")
+    public void publishMessage() throws Exception
+    {
+        try(FrameTransport transport = new 
FrameTransport(_brokerAddress).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+            interaction.openAnonymousConnection()
+                       
.channel().open().consumeResponse(ChannelOpenOkBody.class)
+                       .tx().select().consumeResponse(TxSelectOkBody.class)
+                       
.basic().contentHeaderPropertiesContentType("text/plain")
+                       
.contentHeaderPropertiesHeaders(Collections.singletonMap("test", "testValue"))
+                       .contentHeaderPropertiesDeliveryMode((byte)1)
+                       .contentHeaderPropertiesPriority((byte)1)
+                       .publishExchange("")
+                       .publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME)
+                       .content("Test")
+                       .publishMessage()
+                       
.exchange().declare().consumeResponse(ExchangeDeclareOkBody.class);
+            
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), 
is(equalTo(0)));
+
+            interaction.tx().commit().consumeResponse(TxCommitOkBody.class);
+
+            
assertThat(getBrokerAdmin().getQueueDepthMessages(BrokerAdmin.TEST_QUEUE_NAME), 
is(equalTo(1)));
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/FrameTransport.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/FrameTransport.java
 
b/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/FrameTransport.java
index dd59757..219c423 100644
--- 
a/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/FrameTransport.java
+++ 
b/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/FrameTransport.java
@@ -23,7 +23,9 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 
 import java.net.InetSocketAddress;
 
-public class FrameTransport extends 
org.apache.qpid.tests.protocol.FrameTransport
+import org.apache.qpid.tests.protocol.AbstractFrameTransport;
+
+public class FrameTransport extends AbstractFrameTransport<Interaction>
 {
     public FrameTransport(final InetSocketAddress brokerAddress)
     {

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/Interaction.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/Interaction.java
 
b/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/Interaction.java
index 4aad6ee..b2f8147 100644
--- 
a/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/Interaction.java
+++ 
b/systests/protocol-tests-amqp-1-0/src/main/java/org/apache/qpid/tests/protocol/v1_0/Interaction.java
@@ -77,9 +77,10 @@ import 
org.apache.qpid.server.protocol.v1_0.type.transport.ReceiverSettleMode;
 import org.apache.qpid.server.protocol.v1_0.type.transport.Role;
 import org.apache.qpid.server.protocol.v1_0.type.transport.SenderSettleMode;
 import org.apache.qpid.server.protocol.v1_0.type.transport.Transfer;
+import org.apache.qpid.tests.protocol.AbstractInteraction;
 import org.apache.qpid.tests.protocol.Response;
 
-public class Interaction extends 
org.apache.qpid.tests.protocol.Interaction<Interaction>
+public class Interaction extends AbstractInteraction<Interaction>
 {
     private static final Set<String> CONTAINER_IDS = 
Collections.newSetFromMap(new ConcurrentHashMap<>());
     private final Begin _begin;
@@ -177,12 +178,6 @@ public class Interaction extends 
org.apache.qpid.tests.protocol.Interaction<Inte
         return _protocolHeader;
     }
 
-    @Override
-    protected Interaction getInteraction()
-    {
-        return this;
-    }
-
     //////////
     // SASL //
     //////////

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/AbstractFrameTransport.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/AbstractFrameTransport.java
 
b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/AbstractFrameTransport.java
new file mode 100644
index 0000000..cad8415
--- /dev/null
+++ 
b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/AbstractFrameTransport.java
@@ -0,0 +1,175 @@
+/*
+ * 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;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.anyOf;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.JdkFutureAdapters;
+import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.ChannelPromise;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioSocketChannel;
+
+public abstract class AbstractFrameTransport<I extends AbstractInteraction<I>> 
implements AutoCloseable
+{
+    static final long RESPONSE_TIMEOUT =
+            Long.getLong("qpid.tests.protocol.frameTransport.responseTimeout", 
6000);
+    private static final Response CHANNEL_CLOSED_RESPONSE = new 
ChannelClosedResponse();
+
+    private final BlockingQueue<Response<?>> _queue = new 
ArrayBlockingQueue<>(1000);
+    private final EventLoopGroup _workerGroup;
+    private final InetSocketAddress _brokerAddress;
+    private final InputHandler _inputHandler;
+    private final OutputHandler _outputHandler;
+
+    private volatile Channel _channel;
+    private volatile boolean _channelClosedSeen = false;
+
+    public AbstractFrameTransport(final InetSocketAddress brokerAddress, 
InputDecoder inputDecoder, OutputEncoder outputEncoder)
+    {
+        _brokerAddress = brokerAddress;
+        _inputHandler = new InputHandler(_queue, inputDecoder);
+        _outputHandler = new OutputHandler(outputEncoder);
+        _workerGroup = new NioEventLoopGroup();
+    }
+
+    public InetSocketAddress getBrokerAddress()
+    {
+        return _brokerAddress;
+    }
+
+    public AbstractFrameTransport<I> connect()
+    {
+        try
+        {
+            Bootstrap b = new Bootstrap();
+            b.group(_workerGroup);
+            b.channel(NioSocketChannel.class);
+            b.option(ChannelOption.SO_KEEPALIVE, true);
+            b.handler(new ChannelInitializer<SocketChannel>()
+            {
+                @Override
+                public void initChannel(SocketChannel ch) throws Exception
+                {
+                    ChannelPipeline pipeline = ch.pipeline();
+                    buildInputOutputPipeline(pipeline);
+                }
+            });
+
+            _channel = b.connect(_brokerAddress).sync().channel();
+            _channel.closeFuture().addListener(future ->
+                                               {
+                                                   _channelClosedSeen = true;
+                                                   
_queue.add(CHANNEL_CLOSED_RESPONSE);
+                                               });
+        }
+        catch (InterruptedException e)
+        {
+            throw new RuntimeException(e);
+        }
+        return this;
+    }
+
+    protected void buildInputOutputPipeline(final ChannelPipeline pipeline)
+    {
+        pipeline.addLast(_inputHandler).addLast(_outputHandler);
+    }
+
+    @Override
+    public void close() throws Exception
+    {
+        try
+        {
+            if (_channel != null)
+            {
+                _channel.disconnect().sync();
+                _channel.close().sync();
+                _channel = null;
+            }
+        }
+        finally
+        {
+            _workerGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS).sync();
+        }
+    }
+
+    ListenableFuture<Void> sendProtocolHeader(final byte[] bytes) throws 
Exception
+    {
+        Preconditions.checkState(_channel != null, "Not connected");
+        ChannelPromise promise = _channel.newPromise();
+        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
+        buffer.writeBytes(bytes);
+        _channel.write(buffer, promise);
+        return JdkFutureAdapters.listenInPoolThread(promise);
+    }
+
+    public ListenableFuture<Void> sendPerformative(final Object data) throws 
Exception
+    {
+        Preconditions.checkState(_channel != null, "Not connected");
+        ChannelPromise promise = _channel.newPromise();
+        _channel.write(data, promise);
+        return JdkFutureAdapters.listenInPoolThread(promise);
+    }
+
+    <T extends Response<?>> T getNextResponse() throws Exception
+    {
+        return (T) _queue.poll(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS);
+    }
+
+    public void assertNoMoreResponses() throws Exception
+    {
+        Response response = getNextResponse();
+        assertThat(response, anyOf(nullValue(), 
instanceOf(ChannelClosedResponse.class)));
+    }
+
+    public void assertNoMoreResponsesAndChannelClosed() throws Exception
+    {
+        assertNoMoreResponses();
+        assertThat(_channelClosedSeen, is(true));
+    }
+
+    public void flush()
+    {
+        _channel.flush();
+    }
+
+    public abstract byte[] getProtocolHeader();
+
+    public abstract I newInteraction();
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/AbstractInteraction.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/AbstractInteraction.java
 
b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/AbstractInteraction.java
new file mode 100644
index 0000000..4b41ca9
--- /dev/null
+++ 
b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/AbstractInteraction.java
@@ -0,0 +1,150 @@
+/*
+ *
+ * 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;
+
+import static com.google.common.util.concurrent.Futures.allAsList;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import com.google.common.util.concurrent.ListenableFuture;
+
+public abstract class AbstractInteraction<I extends AbstractInteraction<I>>
+{
+    private final AbstractFrameTransport<I> _transport;
+    private ListenableFuture<?> _latestFuture;
+    private Response<?> _latestResponse;
+
+    public AbstractInteraction(final AbstractFrameTransport<I> frameTransport)
+    {
+        _transport = frameTransport;
+    }
+
+    public I consumeResponse(final Class<?>... responseTypes) throws Exception
+    {
+        sync();
+        _latestResponse = getNextResponse();
+        final Set<Class<?>> acceptableResponseClasses = new 
HashSet<>(Arrays.asList(responseTypes));
+        if ((acceptableResponseClasses.isEmpty() && _latestResponse != null)
+            || (acceptableResponseClasses.contains(null) && _latestResponse == 
null))
+        {
+            return getInteraction();
+        }
+        acceptableResponseClasses.remove(null);
+        if (_latestResponse != null)
+        {
+            for (Class<?> acceptableResponseClass : acceptableResponseClasses)
+            {
+                if 
(acceptableResponseClass.isAssignableFrom(_latestResponse.getBody().getClass()))
+                {
+                    return getInteraction();
+                }
+            }
+        }
+        throw new IllegalStateException(String.format("Unexpected response. 
Expected one of '%s' got '%s'.",
+                                                      
acceptableResponseClasses,
+                                                      _latestResponse == null 
? null : _latestResponse.getBody()));
+    }
+
+    protected Response<?> getNextResponse() throws Exception
+    {
+        return _transport.getNextResponse();
+    }
+
+    public I sync() throws InterruptedException, ExecutionException, 
TimeoutException
+    {
+        _transport.flush();
+        if (_latestFuture != null)
+        {
+            _latestFuture.get(AbstractFrameTransport.RESPONSE_TIMEOUT, 
TimeUnit.MILLISECONDS);
+            _latestFuture = null;
+        }
+        return getInteraction();
+    }
+
+    public Response<?> getLatestResponse() throws Exception
+    {
+        return _latestResponse;
+    }
+
+    public <T> T getLatestResponse(Class<T> type) throws Exception
+    {
+        if (_latestResponse.getBody() == null)
+        {
+            throw new IllegalStateException(String.format("Unexpected 
response. Expected '%s' got '%s'.",
+                                                          type.getSimpleName(),
+                                                          
_latestResponse.getClass()));
+        }
+
+        if (!type.isAssignableFrom(_latestResponse.getBody().getClass()))
+        {
+            throw new IllegalStateException(String.format("Unexpected 
response. Expected '%s' got '%s'.",
+                                                          type.getSimpleName(),
+                                                          
_latestResponse.getBody()));
+        }
+
+        return (T) _latestResponse.getBody();
+    }
+
+    protected ListenableFuture<Void> sendPerformativeAndChainFuture(final 
Object frameBody) throws Exception
+    {
+        final ListenableFuture<Void> future = 
_transport.sendPerformative(frameBody);
+        if (_latestFuture != null)
+        {
+            _latestFuture = allAsList(_latestFuture, future);
+        }
+        else
+        {
+            _latestFuture = future;
+        }
+        return future;
+    }
+
+    public I negotiateProtocol() throws Exception
+    {
+        final ListenableFuture<Void> future = 
_transport.sendProtocolHeader(getProtocolHeader());
+        if (_latestFuture != null)
+        {
+            _latestFuture = allAsList(_latestFuture, future);
+        }
+        else
+        {
+            _latestFuture = future;
+        }
+        return getInteraction();
+    }
+
+    protected AbstractFrameTransport getTransport()
+    {
+        return _transport;
+    }
+
+    protected abstract byte[] getProtocolHeader();
+
+    private I getInteraction()
+    {
+        return (I) this;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/ChannelClosedResponse.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/ChannelClosedResponse.java
 
b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/ChannelClosedResponse.java
new file mode 100644
index 0000000..b701023
--- /dev/null
+++ 
b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/ChannelClosedResponse.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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;
+
+public class ChannelClosedResponse implements Response<ChannelClosedResponse>
+{
+    @Override
+    public String toString()
+    {
+        return "ChannelClosed";
+    }
+
+    @Override
+    public ChannelClosedResponse getBody()
+    {
+        return this;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/FrameTransport.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/FrameTransport.java
 
b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/FrameTransport.java
deleted file mode 100644
index 28dc02e..0000000
--- 
a/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/FrameTransport.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * 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;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.anyOf;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-
-import java.net.InetSocketAddress;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.JdkFutureAdapters;
-import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.bootstrap.Bootstrap;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufAllocator;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.ChannelPipeline;
-import io.netty.channel.ChannelPromise;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.channel.socket.nio.NioSocketChannel;
-
-public abstract class FrameTransport implements AutoCloseable
-{
-    public static final long RESPONSE_TIMEOUT =
-            Long.getLong("qpid.tests.protocol.frameTransport.responseTimeout", 
6000);
-    private static final Response CHANNEL_CLOSED_RESPONSE = new 
ChannelClosedResponse();
-
-    private final BlockingQueue<Response<?>> _queue = new 
ArrayBlockingQueue<>(1000);
-    private final EventLoopGroup _workerGroup;
-    private final InetSocketAddress _brokerAddress;
-    private final InputHandler _inputHandler;
-    private final OutputHandler _outputHandler;
-
-    private volatile Channel _channel;
-    private volatile boolean _channelClosedSeen = false;
-
-    public FrameTransport(final InetSocketAddress brokerAddress, InputDecoder 
inputDecoder, OutputEncoder outputEncoder)
-    {
-        _brokerAddress = brokerAddress;
-        _inputHandler = new InputHandler(_queue, inputDecoder);
-        _outputHandler = new OutputHandler(outputEncoder);
-        _workerGroup = new NioEventLoopGroup();
-    }
-
-    public InetSocketAddress getBrokerAddress()
-    {
-        return _brokerAddress;
-    }
-
-    public FrameTransport connect()
-    {
-        try
-        {
-            Bootstrap b = new Bootstrap();
-            b.group(_workerGroup);
-            b.channel(NioSocketChannel.class);
-            b.option(ChannelOption.SO_KEEPALIVE, true);
-            b.handler(new ChannelInitializer<SocketChannel>()
-            {
-                @Override
-                public void initChannel(SocketChannel ch) throws Exception
-                {
-                    ChannelPipeline pipeline = ch.pipeline();
-                    buildInputOutputPipeline(pipeline);
-                }
-            });
-
-            _channel = b.connect(_brokerAddress).sync().channel();
-            _channel.closeFuture().addListener(future ->
-                                               {
-                                                   _channelClosedSeen = true;
-                                                   
_queue.add(CHANNEL_CLOSED_RESPONSE);
-                                               });
-        }
-        catch (InterruptedException e)
-        {
-            throw new RuntimeException(e);
-        }
-        return this;
-    }
-
-    protected void buildInputOutputPipeline(final ChannelPipeline pipeline)
-    {
-        pipeline.addLast(_inputHandler).addLast(_outputHandler);
-    }
-
-    @Override
-    public void close() throws Exception
-    {
-        try
-        {
-            if (_channel != null)
-            {
-                _channel.disconnect().sync();
-                _channel.close().sync();
-                _channel = null;
-            }
-        }
-        finally
-        {
-            _workerGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS).sync();
-        }
-    }
-
-    public ListenableFuture<Void> sendProtocolHeader(final byte[] bytes) 
throws Exception
-    {
-        Preconditions.checkState(_channel != null, "Not connected");
-        ChannelPromise promise = _channel.newPromise();
-        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
-        buffer.writeBytes(bytes);
-        _channel.write(buffer, promise);
-        return JdkFutureAdapters.listenInPoolThread(promise);
-    }
-
-    public ListenableFuture<Void> sendPerformative(final Object data) throws 
Exception
-    {
-        Preconditions.checkState(_channel != null, "Not connected");
-        ChannelPromise promise = _channel.newPromise();
-        _channel.write(data, promise);
-        return JdkFutureAdapters.listenInPoolThread(promise);
-    }
-
-    public <T extends Response<?>> T getNextResponse() throws Exception
-    {
-        return (T) _queue.poll(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS);
-    }
-
-    public void assertNoMoreResponses() throws Exception
-    {
-        Response response = getNextResponse();
-        assertThat(response, anyOf(nullValue(), 
instanceOf(ChannelClosedResponse.class)));
-    }
-
-    public void assertNoMoreResponsesAndChannelClosed() throws Exception
-    {
-        assertNoMoreResponses();
-        assertThat(_channelClosedSeen, is(true));
-    }
-
-    public void flush()
-    {
-        _channel.flush();
-    }
-
-    private static class ChannelClosedResponse implements Response<Void>
-    {
-        @Override
-        public String toString()
-        {
-            return "ChannelClosed";
-        }
-
-        @Override
-        public Void getBody()
-        {
-            return null;
-        }
-    }
-
-    public abstract byte[] getProtocolHeader();
-
-    protected abstract Interaction newInteraction();
-}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/ff2980e2/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/Interaction.java
----------------------------------------------------------------------
diff --git 
a/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/Interaction.java
 
b/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/Interaction.java
deleted file mode 100644
index b6e631d..0000000
--- 
a/systests/protocol-tests-core/src/main/java/org/apache/qpid/tests/protocol/Interaction.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- *
- * 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;
-
-import static com.google.common.util.concurrent.Futures.allAsList;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import com.google.common.util.concurrent.ListenableFuture;
-
-public abstract class Interaction<I extends Interaction>
-{
-    private final FrameTransport _transport;
-    private ListenableFuture<?> _latestFuture;
-    private Response<?> _latestResponse;
-
-    public Interaction(final FrameTransport frameTransport)
-    {
-        _transport = frameTransport;
-    }
-
-    public I consumeResponse(final Class<?>... responseTypes) throws Exception
-    {
-        sync();
-        _latestResponse = getNextResponse();
-        final Set<Class<?>> acceptableResponseClasses = new 
HashSet<>(Arrays.asList(responseTypes));
-        if ((acceptableResponseClasses.isEmpty() && _latestResponse != null)
-            || (acceptableResponseClasses.contains(null) && _latestResponse == 
null))
-        {
-            return getInteraction();
-        }
-        acceptableResponseClasses.remove(null);
-        if (_latestResponse != null)
-        {
-            for (Class<?> acceptableResponseClass : acceptableResponseClasses)
-            {
-                if 
(acceptableResponseClass.isAssignableFrom(_latestResponse.getBody().getClass()))
-                {
-                    return getInteraction();
-                }
-            }
-        }
-        throw new IllegalStateException(String.format("Unexpected response. 
Expected one of '%s' got '%s'.",
-                                                      
acceptableResponseClasses,
-                                                      _latestResponse == null 
? null : _latestResponse.getBody()));
-    }
-
-    protected Response<?> getNextResponse() throws Exception
-    {
-        return _transport.getNextResponse();
-    }
-
-    public I sync() throws InterruptedException, ExecutionException, 
TimeoutException
-    {
-        _transport.flush();
-        if (_latestFuture != null)
-        {
-            _latestFuture.get(FrameTransport.RESPONSE_TIMEOUT, 
TimeUnit.MILLISECONDS);
-            _latestFuture = null;
-        }
-        return getInteraction();
-    }
-
-    public Response<?> getLatestResponse() throws Exception
-    {
-        return _latestResponse;
-    }
-
-    public <T> T getLatestResponse(Class<T> type) throws Exception
-    {
-        if (_latestResponse.getBody() == null)
-        {
-            throw new IllegalStateException(String.format("Unexpected 
response. Expected '%s' got '%s'.",
-                                                          type.getSimpleName(),
-                                                          
_latestResponse.getClass()));
-        }
-
-        if (!type.isAssignableFrom(_latestResponse.getBody().getClass()))
-        {
-            throw new IllegalStateException(String.format("Unexpected 
response. Expected '%s' got '%s'.",
-                                                          type.getSimpleName(),
-                                                          
_latestResponse.getBody()));
-        }
-
-        return (T) _latestResponse.getBody();
-    }
-
-    protected ListenableFuture<Void> sendPerformativeAndChainFuture(final 
Object frameBody) throws Exception
-    {
-        final ListenableFuture<Void> future = 
_transport.sendPerformative(frameBody);
-        if (_latestFuture != null)
-        {
-            _latestFuture = allAsList(_latestFuture, future);
-        }
-        else
-        {
-            _latestFuture = future;
-        }
-        return future;
-    }
-
-    public I negotiateProtocol() throws Exception
-    {
-        final ListenableFuture<Void> future = 
_transport.sendProtocolHeader(getProtocolHeader());
-        if (_latestFuture != null)
-        {
-            _latestFuture = allAsList(_latestFuture, future);
-        }
-        else
-        {
-            _latestFuture = future;
-        }
-        return getInteraction();
-    }
-
-    protected FrameTransport getTransport()
-    {
-        return _transport;
-    }
-
-    protected abstract byte[] getProtocolHeader();
-
-    protected abstract I getInteraction();
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to