This is an automated email from the ASF dual-hosted git repository. cshannon pushed a commit to branch activemq-5.16.x in repository https://gitbox.apache.org/repos/asf/activemq.git
commit 42e65f88e38ffaa7aebc775ce7b0c91888948b21 Author: Christopher L. Shannon (cshannon) <christopher.l.shan...@gmail.com> AuthorDate: Mon Feb 7 08:03:06 2022 -0500 AMQ-8412 - Add wireformat negotiation test for maxFrameSizeEnabled Verify that maxFrameSizeEnabled being configured on the client or the server is not negotiated and won't affect the other (cherry picked from commit 26a3c55833bf5a0534f7a5b841fd274d61355435) --- .../apache/activemq/command/WireFormatInfo.java | 8 ++ .../activemq/openwire/OpenWireFormatFactory.java | 1 + .../transport/tcp/WireformatNegociationTest.java | 93 ++++++++++++++++++++++ 3 files changed, 102 insertions(+) diff --git a/activemq-client/src/main/java/org/apache/activemq/command/WireFormatInfo.java b/activemq-client/src/main/java/org/apache/activemq/command/WireFormatInfo.java index 8d61578..7544017 100644 --- a/activemq-client/src/main/java/org/apache/activemq/command/WireFormatInfo.java +++ b/activemq-client/src/main/java/org/apache/activemq/command/WireFormatInfo.java @@ -354,6 +354,14 @@ public class WireFormatInfo implements Command, MarshallAware { setProperty("PlatformDetails", platformDetails); } + public boolean isMaxFrameSizeEnabled() throws IOException { + return Boolean.TRUE == getProperty("MaxFrameSizeEnabled"); + } + + public void setMaxFrameSizeEnabled(boolean maxFrameSizeEnabled) throws IOException { + setProperty("MaxFrameSizeEnabled", maxFrameSizeEnabled ? Boolean.TRUE : Boolean.FALSE); + } + @Override public Response visit(CommandVisitor visitor) throws Exception { return visitor.processWireFormat(this); diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java index 2083639..5261250 100644 --- a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java +++ b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java @@ -63,6 +63,7 @@ public class OpenWireFormatFactory implements WireFormatFactory { info.setMaxInactivityDurationInitalDelay(maxInactivityDurationInitalDelay); info.setCacheSize(cacheSize); info.setMaxFrameSize(maxFrameSize); + info.setMaxFrameSizeEnabled(maxFrameSizeEnabled); if( host!=null ) { info.setHost(host); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/WireformatNegociationTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/WireformatNegociationTest.java index 70cfa0e..76bf221 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/WireformatNegociationTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/transport/tcp/WireformatNegociationTest.java @@ -233,4 +233,97 @@ public class WireformatNegociationTest extends CombinationTestSupport { assertEquals(1048576, serverWF.get().getMaxFrameSize()); } + + /** + * The property maxFrameSizeEnabled should NOT be negotiated as we don't want to allow + * clients to override a server setting. Verify both sides can change their setting and it won't + * affect the other side. + * + * @throws Exception + */ + public void testWireFormatMaxFrameSizeBothEnabled() throws Exception { + + startServer("tcp://localhost:61616"); + startClient("tcp://localhost:61616"); + + assertTrue("Connect timeout", negociationCounter.await(10, TimeUnit.SECONDS)); + assertNull("Async error: " + asyncError, asyncError.get()); + + //both should be enabled + assertNotNull(clientWF.get()); + assertTrue(Boolean.valueOf(clientWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + + assertNotNull(serverWF.get()); + assertTrue(Boolean.valueOf(serverWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + } + + //Make sure settin the flag to true explicitly and not default works + public void testWireFormatMaxFrameSizeBothEnabledExplicit() throws Exception { + + startServer("tcp://localhost:61616?wireFormat.maxFrameSizeEnabled=true"); + startClient("tcp://localhost:61616?wireFormat.maxFrameSizeEnabled=true"); + + assertTrue("Connect timeout", negociationCounter.await(10, TimeUnit.SECONDS)); + assertNull("Async error: " + asyncError, asyncError.get()); + + //both should be enabled + assertNotNull(clientWF.get()); + assertTrue(Boolean.valueOf(clientWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + + assertNotNull(serverWF.get()); + assertTrue(Boolean.valueOf(serverWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + } + + //Verify disabling client doesn't change server + public void testWireFormatMaxFrameSizeClientDisabled() throws Exception { + + startServer("tcp://localhost:61616"); + startClient("tcp://localhost:61616?wireFormat.maxFrameSizeEnabled=false"); + + assertTrue("Connect timeout", negociationCounter.await(10, TimeUnit.SECONDS)); + assertNull("Async error: " + asyncError, asyncError.get()); + + //Verify client disabled + assertNotNull(clientWF.get()); + assertTrue(Boolean.valueOf(clientWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + + //Make sure server is still enabled + assertNotNull(serverWF.get()); + assertFalse(Boolean.valueOf(serverWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + } + + //Verify disabling server doesn't change client + public void testWireFormatMaxFrameSizeServerDisabled() throws Exception { + + startServer("tcp://localhost:61616?wireFormat.maxFrameSizeEnabled=false"); + startClient("tcp://localhost:61616"); + + assertTrue("Connect timeout", negociationCounter.await(10, TimeUnit.SECONDS)); + assertNull("Async error: " + asyncError, asyncError.get()); + + //Verify client enabled + assertNotNull(clientWF.get()); + assertFalse(Boolean.valueOf(clientWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + + //Make server disabled + assertNotNull(serverWF.get()); + assertTrue(Boolean.valueOf(serverWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + } + + //Verify disabling server and client + public void testWireFormatMaxFrameSizeBothDisabled() throws Exception { + + startServer("tcp://localhost:61616?wireFormat.maxFrameSizeEnabled=false"); + startClient("tcp://localhost:61616?wireFormat.maxFrameSizeEnabled=false"); + + assertTrue("Connect timeout", negociationCounter.await(10, TimeUnit.SECONDS)); + assertNull("Async error: " + asyncError, asyncError.get()); + + //Make both disabled + assertNotNull(clientWF.get()); + assertFalse(Boolean.valueOf(clientWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + + assertNotNull(serverWF.get()); + assertFalse(Boolean.valueOf(serverWF.get().getProperties().get("MaxFrameSizeEnabled").toString())); + } }