From 26a3c55833bf5a0534f7a5b841fd274d61355435 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Mon, 7 Feb 2022 08:03:06 -0500 Subject: [PATCH] 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 --- .../activemq/command/WireFormatInfo.java | 8 ++ .../openwire/OpenWireFormatFactory.java | 1 + .../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 9477a1298e..98166ce693 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 20836390b5..5261250886 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 70cfa0ea71..76bf221355 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())); + } }