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

[qpid-protonj2] branch main updated: PROTON-2593 Add frame decode handler tests for split frames

This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/main by this push:
     new 7c4ebc86 PROTON-2593 Add frame decode handler tests for split frames
7c4ebc86 is described below

commit 7c4ebc8602e2a16c2c0c9267f44a044e97de7029
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Tue Aug 23 17:15:58 2022 -0400

    PROTON-2593 Add frame decode handler tests for split frames
---
 .../impl/ProtonFrameDecodingHandlerTest.java       | 104 +++++++++++++++++++++
 1 file changed, 104 insertions(+)

diff --git a/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonFrameDecodingHandlerTest.java b/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonFrameDecodingHandlerTest.java
index ae37f966..785b7fdc 100644
--- a/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonFrameDecodingHandlerTest.java
+++ b/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonFrameDecodingHandlerTest.java
@@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.fail;
 
 import java.util.List;
 
+import org.apache.qpid.protonj2.buffer.ProtonBuffer;
 import org.apache.qpid.protonj2.buffer.ProtonByteBufferAllocator;
 import org.apache.qpid.protonj2.engine.EmptyEnvelope;
 import org.apache.qpid.protonj2.engine.Engine;
@@ -272,6 +273,107 @@ public class ProtonFrameDecodingHandlerTest {
         assertFalse(decoded.hasProperties());
     }
 
+    @Test
+    public void testDecodePipelinedHeaderAndOpenEncodedFrameSplitAcrossTwoReads() throws Exception {
+        // Frame data for: Open
+        //   Open{ containerId='container', hostname='localhost', maxFrameSize=16384, channelMax=65535,
+        //         idleTimeOut=30000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null,
+        //         desiredCapabilities=null, properties=null}
+        final byte[] basicOpen1 = new byte[] {
+                'A', 'M', 'Q', 'P', 0, 1, 0, 0, // HEADER
+                0, 0, 0, 49, 2, 0, 0, 0, 0, 83, 16, -64, 36, 5, -95, 9, 99, 111 };
+        final byte[] basicOpen2 = new byte[] {
+                110, 116, 97, 105, 110, 101, 114, -95, 9, 108, 111, 99, 97, 108,
+                104, 111, 115, 116, 112, 0, 0, 64, 0, 96, -1, -1, 112, 0, 0, 117, 48 };
+        ArgumentCaptor<IncomingAMQPEnvelope> argument = ArgumentCaptor.forClass(IncomingAMQPEnvelope.class);
+
+        ProtonFrameDecodingHandler handler = createFrameDecoder();
+        ProtonEngineHandlerContext context = Mockito.mock(ProtonEngineHandlerContext.class);
+
+        final ProtonBuffer buffer1 = ProtonByteBufferAllocator.DEFAULT.wrap(basicOpen1);
+        final ProtonBuffer buffer2 = ProtonByteBufferAllocator.DEFAULT.wrap(basicOpen2);
+
+        handler.handleRead(context, buffer1);
+        handler.handleRead(context, buffer2);
+
+        Mockito.verify(context).fireRead(Mockito.any(HeaderEnvelope.class));
+        Mockito.verify(context).interestMask(ProtonEngineHandlerContext.HANDLER_READS);
+        Mockito.verify(context).fireRead(argument.capture());
+        Mockito.verifyNoMoreInteractions(context);
+
+        assertNotNull(argument.getValue());
+        assertTrue(argument.getValue().getBody() instanceof Open);
+
+        Open decoded = (Open) argument.getValue().getBody();
+
+        assertTrue(decoded.hasContainerId());
+        assertEquals("container", decoded.getContainerId());
+        assertTrue(decoded.hasHostname());
+        assertEquals("localhost", decoded.getHostname());
+        assertTrue(decoded.hasMaxFrameSize());
+        assertEquals(16384, decoded.getMaxFrameSize());
+        assertTrue(decoded.hasChannelMax());
+        assertTrue(decoded.hasIdleTimeout());
+        assertEquals(30000, decoded.getIdleTimeout());
+        assertFalse(decoded.hasOutgoingLocales());
+        assertFalse(decoded.hasIncomingLocales());
+        assertFalse(decoded.hasOfferedCapabilities());
+        assertFalse(decoded.hasDesiredCapabilities());
+        assertFalse(decoded.hasProperties());
+    }
+
+    @Test
+    public void testDecodePipelinedHeaderAndOpenEncodedFrameSplitAcrossThreeReads() throws Exception {
+        // Frame data for: Open
+        //   Open{ containerId='container', hostname='localhost', maxFrameSize=16384, channelMax=65535,
+        //         idleTimeOut=30000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null,
+        //         desiredCapabilities=null, properties=null}
+        final byte[] basicOpen1 = new byte[] {
+                'A', 'M', 'Q', 'P', 0, 1, 0, 0, // HEADER
+                0, 0, 0, 49, 2, 0, 0, 0, 0, 83, 16, -64, 36, 5, -95, 9, 99, 111 };
+        final byte[] basicOpen2 = new byte[] {
+                110, 116, 97, 105, 110, 101, 114, -95, 9, 108, 111, 99, 97, 108 };
+        final byte[] basicOpen3 = new byte[] {
+                104, 111, 115, 116, 112, 0, 0, 64, 0, 96, -1, -1, 112, 0, 0, 117, 48 };
+        ArgumentCaptor<IncomingAMQPEnvelope> argument = ArgumentCaptor.forClass(IncomingAMQPEnvelope.class);
+
+        ProtonFrameDecodingHandler handler = createFrameDecoder();
+        ProtonEngineHandlerContext context = Mockito.mock(ProtonEngineHandlerContext.class);
+
+        final ProtonBuffer buffer1 = ProtonByteBufferAllocator.DEFAULT.wrap(basicOpen1);
+        final ProtonBuffer buffer2 = ProtonByteBufferAllocator.DEFAULT.wrap(basicOpen2);
+        final ProtonBuffer buffer3 = ProtonByteBufferAllocator.DEFAULT.wrap(basicOpen3);
+
+        handler.handleRead(context, buffer1);
+        handler.handleRead(context, buffer2);
+        handler.handleRead(context, buffer3);
+
+        Mockito.verify(context).fireRead(Mockito.any(HeaderEnvelope.class));
+        Mockito.verify(context).interestMask(ProtonEngineHandlerContext.HANDLER_READS);
+        Mockito.verify(context).fireRead(argument.capture());
+        Mockito.verifyNoMoreInteractions(context);
+
+        assertNotNull(argument.getValue());
+        assertTrue(argument.getValue().getBody() instanceof Open);
+
+        Open decoded = (Open) argument.getValue().getBody();
+
+        assertTrue(decoded.hasContainerId());
+        assertEquals("container", decoded.getContainerId());
+        assertTrue(decoded.hasHostname());
+        assertEquals("localhost", decoded.getHostname());
+        assertTrue(decoded.hasMaxFrameSize());
+        assertEquals(16384, decoded.getMaxFrameSize());
+        assertTrue(decoded.hasChannelMax());
+        assertTrue(decoded.hasIdleTimeout());
+        assertEquals(30000, decoded.getIdleTimeout());
+        assertFalse(decoded.hasOutgoingLocales());
+        assertFalse(decoded.hasIncomingLocales());
+        assertFalse(decoded.hasOfferedCapabilities());
+        assertFalse(decoded.hasDesiredCapabilities());
+        assertFalse(decoded.hasProperties());
+    }
+
     /*
      * Test that empty frames, as used for heartbeating, decode as expected.
      */
@@ -451,6 +553,8 @@ public class ProtonFrameDecodingHandlerTest {
     private ProtonFrameDecodingHandler createFrameDecoder() {
         ProtonEngineConfiguration configuration = Mockito.mock(ProtonEngineConfiguration.class);
         Mockito.when(configuration.getInboundMaxFrameSize()).thenReturn(Long.valueOf(65535));
+        Mockito.when(configuration.getOutboundMaxFrameSize()).thenReturn(Long.valueOf(65535));
+        Mockito.when(configuration.getBufferAllocator()).thenReturn(ProtonByteBufferAllocator.DEFAULT);
         ProtonEngine engine = Mockito.mock(ProtonEngine.class);
         Mockito.when(engine.configuration()).thenReturn(configuration);
         Mockito.when(engine.isWritable()).thenReturn(Boolean.TRUE);


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