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

qpid-broker-j git commit: QPID-7947: [Java Broker][AMQP 1.0] Add unit tests

Repository: qpid-broker-j
Updated Branches:
  refs/heads/master cf759cffd -> 1de6cd5dc


 QPID-7947: [Java Broker][AMQP 1.0] Add unit 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/1de6cd5d
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/1de6cd5d
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/1de6cd5d

Branch: refs/heads/master
Commit: 1de6cd5dc9d3a83f12aa829e0201d53a5c519914
Parents: cf759cf
Author: Alex Rudyy <or...@apache.org>
Authored: Tue Oct 10 09:25:10 2017 +0100
Committer: Alex Rudyy <or...@apache.org>
Committed: Tue Oct 10 09:25:32 2017 +0100

----------------------------------------------------------------------
 .../protocol/v1_0/framing/FrameHandlerTest.java | 101 +++++++++++++++++++
 1 file changed, 101 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/1de6cd5d/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandlerTest.java
----------------------------------------------------------------------
diff --git a/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandlerTest.java b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandlerTest.java
new file mode 100644
index 0000000..acb7465
--- /dev/null
+++ b/broker-plugins/amqp-1-0-protocol/src/test/java/org/apache/qpid/server/protocol/v1_0/framing/FrameHandlerTest.java
@@ -0,0 +1,101 @@
+/*
+ *
+ * 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.server.protocol.v1_0.framing;
+
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.mockito.ArgumentCaptor;
+
+import org.apache.qpid.server.bytebuffer.QpidByteBuffer;
+import org.apache.qpid.server.protocol.v1_0.ConnectionHandler;
+import org.apache.qpid.server.protocol.v1_0.codec.ValueHandler;
+import org.apache.qpid.server.protocol.v1_0.type.UnsignedShort;
+import org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry;
+import org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError;
+import org.apache.qpid.server.protocol.v1_0.type.transport.Error;
+import org.apache.qpid.test.utils.QpidTestCase;
+
+public class FrameHandlerTest extends QpidTestCase
+{
+    private static final int MAX_FRAME_SIZE = 4096;
+    private ValueHandler _valueHandler;
+
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        _valueHandler = new ValueHandler(AMQPDescribedTypeRegistry.newInstance());
+    }
+
+    public void testSaslHeartbeat()
+    {
+        ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
+        when(connectionHandler.getMaxFrameSize()).thenReturn(MAX_FRAME_SIZE);
+        FrameHandler handler = new  FrameHandler(_valueHandler, connectionHandler, true);
+
+        QpidByteBuffer body = QpidByteBuffer.allocate(false, 8);
+        body.putInt(8);    // size
+        body.put((byte)2); // DOFF
+        body.put((byte)1); // AMQP Frame Type
+        body.putShort(UnsignedShort.ZERO.shortValue());  // channel
+        body.flip();
+
+        handler.parse(body);
+
+        ArgumentCaptor<Error> errorCaptor = ArgumentCaptor.forClass(Error.class);
+        verify(connectionHandler).handleError(errorCaptor.capture());
+
+        Error error = errorCaptor.getValue();
+        assertNotNull(error);
+        assertEquals(ConnectionError.FRAMING_ERROR, error.getCondition());
+        assertEquals("Empty (heartbeat) frames are not permitted during SASL negotiation", error.getDescription());
+    }
+
+    public void testOversizedFrame()
+    {
+        ConnectionHandler connectionHandler = mock(ConnectionHandler.class);
+        when(connectionHandler.getMaxFrameSize()).thenReturn(MAX_FRAME_SIZE);
+        FrameHandler handler = new FrameHandler(_valueHandler, connectionHandler, true);
+
+        QpidByteBuffer body = QpidByteBuffer.allocate(false, MAX_FRAME_SIZE + 8);
+        body.putInt(body.capacity()); // size
+        body.put((byte) 2); // DOFF
+        body.put((byte) 1); // AMQP Frame Type
+        body.putShort(UnsignedShort.ZERO.shortValue()); // channel
+        body.position(body.capacity());
+        body.flip();
+
+        handler.parse(body);
+
+        ArgumentCaptor<Error> errorCaptor = ArgumentCaptor.forClass(Error.class);
+        verify(connectionHandler).handleError(errorCaptor.capture());
+
+        Error error = errorCaptor.getValue();
+        assertNotNull(error);
+        assertEquals(ConnectionError.FRAMING_ERROR, error.getCondition());
+        assertEquals(String.format("specified frame size %s larger than maximum frame header size %s",
+                                   body.capacity(),
+                                   MAX_FRAME_SIZE), error.getDescription());
+    }
+}


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