From e35ec7b1d6aa2c1f532c63bcc8d2f3cfffeb001f Mon Sep 17 00:00:00 2001 From: Darran Lofthouse Date: Mon, 23 Sep 2024 16:27:56 +0100 Subject: [PATCH] [WFCORE-7008] Split ManagementInterfaceResourcesTestCase for different stability levels. --- testsuite/manualmode/pom.xml | 18 +- ...tManagementInterfaceResourcesTestCase.java | 127 +++++++++++++ ...ntInterfaceResourcesCommunityTestCase.java | 81 +++++++++ .../ManagementInterfaceResourcesTestCase.java | 167 ++---------------- ...bilityServerSetupSnapshotRestoreTasks.java | 4 +- 5 files changed, 232 insertions(+), 165 deletions(-) create mode 100644 testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/AbstractManagementInterfaceResourcesTestCase.java create mode 100644 testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/ManagementInterfaceResourcesCommunityTestCase.java diff --git a/testsuite/manualmode/pom.xml b/testsuite/manualmode/pom.xml index 8d94751002b..4e46acb4daf 100644 --- a/testsuite/manualmode/pom.xml +++ b/testsuite/manualmode/pom.xml @@ -31,9 +31,9 @@ - + - + jakarta.inject @@ -583,7 +583,7 @@ org.jboss.as.test.manualmode.deployment.DeploymentScannerRedeploymentTestCase org.jboss.as.test.manualmode.deployment.DeploymentScannerUnitTestCase - + org.jboss.as.test.manualmode.logging.LoggingDependenciesTestCase org.jboss.as.test.manualmode.logging.LoggingPreferencesTestCase @@ -598,7 +598,7 @@ org.jboss.as.test.manualmode.provisioning.InstallationManagerBootTestCase org.jboss.as.test.manualmode.management.*TestCase - + org.jboss.as.test.manualmode.management.cli.ManagementOpTimeoutTestCase org.jboss.as.test.manualmode.management.cli.ShutdownTestCase @@ -615,21 +615,19 @@ org.jboss.as.test.manualmode.management.cli.RemoveManagementRealmTestCase org.jboss.as.test.manualmode.management.persistence.*TestCase - + org.jboss.as.test.manualmode.mgmt.elytron.ElytronModelControllerClientTestCase - + org.jboss.as.test.manualmode.expressions.CredentialStoreExpressionsTestCase - + - org.wildfly.core.test.standalone.mgmt.ManagementInterfaceResourcesTestCase org.jboss.as.test.manualmode.adminonly.auditlog.*TestCase.java org.jboss.as.test.manualmode.cli.boot.ops.CliBootOperationsTestCase.java - org.wildfly.core.test.standalone.mgmt.PreparedResponseTestCase - + org.wildfly.core.test.standalone.mgmt.events.*TestCase diff --git a/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/AbstractManagementInterfaceResourcesTestCase.java b/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/AbstractManagementInterfaceResourcesTestCase.java new file mode 100644 index 00000000000..4a01eec46f0 --- /dev/null +++ b/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/AbstractManagementInterfaceResourcesTestCase.java @@ -0,0 +1,127 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.core.test.standalone.mgmt; + +import static org.jboss.as.test.shared.TimeoutUtil.adjust; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketAddress; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jboss.as.test.shared.TestSuiteEnvironment; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.wildfly.common.function.ExceptionRunnable; +import org.wildfly.core.testrunner.ServerControl; +import org.wildfly.core.testrunner.ServerController; +import org.wildfly.core.testrunner.WildFlyRunner; + +import jakarta.inject.Inject; + +/** + * Test case to test resource limits and clean up of management interface connections. + * + * @author Darran Lofthouse + */ +@RunWith(WildFlyRunner.class) +@ServerControl(manual = true) +public abstract class AbstractManagementInterfaceResourcesTestCase { + protected static final Logger LOG = Logger.getLogger(ManagementInterfaceResourcesTestCase.class.getName()); + + + @Inject + protected static ServerController controller; + + /** + * Test that the management interface will not accept new connections when the number of active connections reaches the + * high water mark. After the number of open connections has been reduced to the low watermark it will test that connections + * are accepted again. + */ + @Test + public void testWatermarks() throws Exception { + runTest(60000, () -> { + String mgmtAddress = TestSuiteEnvironment.getServerAddress(); + int mgmtPort = TestSuiteEnvironment.getServerPort(); + LOG.info(mgmtAddress + ":" + mgmtPort); + SocketAddress targetAddress = new InetSocketAddress(mgmtAddress, mgmtPort); + + int socketsOpened = 0; + boolean oneFailed = false; + Socket[] sockets = new Socket[9]; + for (int i = 0 ; i < 9 ; i++) { + LOG.info("Opening socket " + i + " socketsOpened=" + socketsOpened); + try { + sockets[i] = new Socket(); + sockets[i].connect(targetAddress, 5000); + socketsOpened++; + } catch (IOException e) { + LOG.log(Level.SEVERE, "Probably an expected exception trying to open a new connection", e); + assertTrue("Less sockets than low watermark opened.", socketsOpened > 3); + oneFailed = true; + } + } + assertTrue("Opening of one socket was expected to fail.", oneFailed); + + // Now close the connections and we should be able to connect again. + for (int i = 0 ; i < socketsOpened ; i++) { + sockets[i].close(); + } + + Socket goodSocket = new Socket(); + // This needs a reasonable time to give the server time to respond to the closed connections. + goodSocket.connect(targetAddress, 10000); + goodSocket.close(); + }); + } + + @Test + public void testTimeout() throws Exception { + runTest(10000, () -> { + String mgmtAddress = TestSuiteEnvironment.getServerAddress(); + int mgmtPort = TestSuiteEnvironment.getServerPort(); + SocketAddress targetAddress = new InetSocketAddress(mgmtAddress, mgmtPort); + + int socketsOpened = 0; + boolean oneFailed = false; + Socket[] sockets = new Socket[9]; + for (int i = 0 ; i < 9 ; i++) { + LOG.info("Opening socket " + i + " socketsOpened=" + socketsOpened); + try { + sockets[i] = new Socket(); + sockets[i].connect(targetAddress, 5000); + socketsOpened++; + } catch (IOException e) { + LOG.log(Level.SEVERE, "Probably an expected exception trying to open a new connection", e); + assertTrue("Less sockets than low watermark opened.", socketsOpened > 3); + oneFailed = true; + } + } + assertTrue("Opening of one socket was expected to fail.", oneFailed); + + // Notice that the exception received when we tried to open a new socket could have been a timeout (SocketTimeoutException) + // or a connection refused (IOException). It depends on the OS and the network configuration. + // So, we could also have had 5000ms for each bad socket that triggered a SocketTimeoutException. + Thread.sleep(adjust(12000)); + + Socket goodSocket = new Socket(); + // This needs to be longer than 500ms to give the server time to respond to the closed connections. + goodSocket.connect(targetAddress, 10000); + goodSocket.close(); + + // Clean up remaining sockets + for (int i = 0 ; i < socketsOpened ; i++) { + sockets[i].close(); + } + }); + } + + protected abstract void runTest(int noRequestTimeout, ExceptionRunnable test) throws Exception; + +} diff --git a/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/ManagementInterfaceResourcesCommunityTestCase.java b/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/ManagementInterfaceResourcesCommunityTestCase.java new file mode 100644 index 00000000000..1541994c55b --- /dev/null +++ b/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/ManagementInterfaceResourcesCommunityTestCase.java @@ -0,0 +1,81 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.wildfly.core.test.standalone.mgmt; + +import static org.jboss.as.controller.client.helpers.Operations.createAddress; +import static org.jboss.as.controller.client.helpers.Operations.createWriteAttributeOperation; +import static org.jboss.as.test.integration.management.util.ServerReload.executeReloadAndWaitForCompletion; + +import org.jboss.as.test.integration.management.util.ServerReload; +import org.jboss.as.version.Stability; +import org.jboss.dmr.ModelNode; +import org.wildfly.common.function.ExceptionRunnable; +import org.wildfly.core.testrunner.ManagementClient; +import org.wildfly.core.testrunner.ServerSetupTask; +import org.wildfly.test.stability.StabilityServerSetupSnapshotRestoreTasks; + +/** + * Test case to test resource limits and clean up of management interface connections. + * + * This test case uses attributes defined directly on the HTTP management interface resource for configuration. + * + * @author Darran Lofthouse + */ +public class ManagementInterfaceResourcesCommunityTestCase extends AbstractManagementInterfaceResourcesTestCase { + + /* + * Attribute names + */ + private static final String BACKLOG_ATTRIBUTE = "backlog"; + private static final String CONNECTION_HIGH_WATER_ATTRIBUTE = "connection-high-water"; + private static final String CONNECTION_LOW_WATER_ATTRIBUTE = "connection-low-water"; + private static final String NO_REQUEST_TIMEOUT_ATTRIBUTE = "no-request-timeout"; + + private static final ModelNode HTTP_INTERFACE_ADDRESS = createAddress("core-service", "management", "management-interface", "http-interface"); + + protected void runTest(int noRequestTimeout, ExceptionRunnable test) throws Exception { + controller.start(); + ManagementClient client = controller.getClient(); + + ServerSetupTask task = new ManagementInterfaceSetUpTask(noRequestTimeout); + + try { + task.setup(client); + test.run(); + controller.reload(); + } finally { + task.tearDown(client); + controller.stop(); + } + } + + class ManagementInterfaceSetUpTask extends StabilityServerSetupSnapshotRestoreTasks.Community { + + private final int noRequestTimeout; + + public ManagementInterfaceSetUpTask(int noRequestTimeout) { + this.noRequestTimeout = noRequestTimeout; + } + + protected void doSetup(ManagementClient managementClient) throws Exception { + writeAttribute(managementClient, BACKLOG_ATTRIBUTE, 2); + writeAttribute(managementClient, CONNECTION_HIGH_WATER_ATTRIBUTE, 6); + writeAttribute(managementClient, CONNECTION_LOW_WATER_ATTRIBUTE, 3); + writeAttribute(managementClient, NO_REQUEST_TIMEOUT_ATTRIBUTE, noRequestTimeout); + + // Execute the reload + ServerReload.Parameters parameters = new ServerReload.Parameters() + .setStability(Stability.COMMUNITY); + executeReloadAndWaitForCompletion(managementClient.getControllerClient(), parameters); + } + + private void writeAttribute(final ManagementClient managementClient, final String attributeName, final int value) throws Exception { + ModelNode writeOp = createWriteAttributeOperation(HTTP_INTERFACE_ADDRESS, attributeName, value); + managementClient.executeForResult(writeOp); + } + + } +} diff --git a/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/ManagementInterfaceResourcesTestCase.java b/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/ManagementInterfaceResourcesTestCase.java index 6f9e00f6b14..515cf1ce609 100644 --- a/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/ManagementInterfaceResourcesTestCase.java +++ b/testsuite/manualmode/src/test/java/org/wildfly/core/test/standalone/mgmt/ManagementInterfaceResourcesTestCase.java @@ -5,36 +5,17 @@ package org.wildfly.core.test.standalone.mgmt; -import static org.jboss.as.test.shared.TimeoutUtil.adjust; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketAddress; -import java.util.logging.Level; -import java.util.logging.Logger; - -import jakarta.inject.Inject; - import org.jboss.as.test.integration.management.util.CLIWrapper; -import org.jboss.as.test.shared.TestSuiteEnvironment; -import org.junit.Test; -import org.junit.runner.RunWith; import org.wildfly.common.function.ExceptionRunnable; -import org.wildfly.core.testrunner.ServerControl; -import org.wildfly.core.testrunner.ServerController; -import org.wildfly.core.testrunner.WildFlyRunner; /** * Test case to test resource limits and clean up of management interface connections. * + * This test case uses system properties for configuration. + * * @author Darran Lofthouse */ -@RunWith(WildFlyRunner.class) -@ServerControl(manual = true) -public class ManagementInterfaceResourcesTestCase { - private static final Logger LOG = Logger.getLogger(ManagementInterfaceResourcesTestCase.class.getName()); +public class ManagementInterfaceResourcesTestCase extends AbstractManagementInterfaceResourcesTestCase { /* * System Properties @@ -43,134 +24,19 @@ public class ManagementInterfaceResourcesTestCase { private static final String CONNECTION_HIGH_WATER_PROPERTY = "org.wildfly.management.connection-high-water"; private static final String CONNECTION_LOW_WATER_PROPERTY = "org.wildfly.management.connection-low-water"; private static final String NO_REQUEST_TIMEOUT_PROPERTY = "org.wildfly.management.no-request-timeout"; - /* - * Attribute names - */ - private static final String BACKLOG_ATTRIBUTE = "backlog"; - private static final String CONNECTION_HIGH_WATER_ATTRIBUTE = "connection-high-water"; - private static final String CONNECTION_LOW_WATER_ATTRIBUTE = "connection-low-water"; - private static final String NO_REQUEST_TIMEOUT_ATTRIBUTE = "no-request-timeout"; /* * Command Templates */ - private static final String HTTP_INTERFACE_READ_ATTRIBUTE = "/core-service=management/management-interface=http-interface:read-attribute(name=%s)"; - private static final String HTTP_INTERFACE_WRITE_ATTRIBUTE = "/core-service=management/management-interface=http-interface:write-attribute(name=%s, value=%d)"; - private static final String HTTP_INTERFACE_UNDEFINE_ATTRIBUTE = "/core-service=management/management-interface=http-interface:undefine-attribute(name=%s)"; private static final String SYSTEM_PROPERTY_ADD = "/system-property=%s:add(value=%d)"; private static final String SYSTEM_PROPERTY_REMOVE = "/system-property=%s:remove()"; - @Inject - protected static ServerController controller; - - /** - * Test that the management interface will not accept new connections when the number of active connections reaches the - * high water mark. After the number of open connections has been reduced to the low watermark it will test that connections - * are accepted again. - */ - @Test - public void testWatermarks() throws Exception { - runTest(60000, () -> { - String mgmtAddress = TestSuiteEnvironment.getServerAddress(); - int mgmtPort = TestSuiteEnvironment.getServerPort(); - LOG.info(mgmtAddress + ":" + mgmtPort); - SocketAddress targetAddress = new InetSocketAddress(mgmtAddress, mgmtPort); - - int socketsOpened = 0; - boolean oneFailed = false; - Socket[] sockets = new Socket[9]; - for (int i = 0 ; i < 9 ; i++) { - LOG.info("Opening socket " + i + " socketsOpened=" + socketsOpened); - try { - sockets[i] = new Socket(); - sockets[i].connect(targetAddress, 5000); - socketsOpened++; - } catch (IOException e) { - LOG.log(Level.SEVERE, "Probably an expected exception trying to open a new connection", e); - assertTrue("Less sockets than low watermark opened.", socketsOpened > 3); - oneFailed = true; - } - } - assertTrue("Opening of one socket was expected to fail.", oneFailed); - - // Now close the connections and we should be able to connect again. - for (int i = 0 ; i < socketsOpened ; i++) { - sockets[i].close(); - } - - Socket goodSocket = new Socket(); - // This needs a reasonable time to give the server time to respond to the closed connections. - goodSocket.connect(targetAddress, 10000); - goodSocket.close(); - }); - } - - @Test - public void testTimeout() throws Exception { - runTest(10000, () -> { - String mgmtAddress = TestSuiteEnvironment.getServerAddress(); - int mgmtPort = TestSuiteEnvironment.getServerPort(); - SocketAddress targetAddress = new InetSocketAddress(mgmtAddress, mgmtPort); - - int socketsOpened = 0; - boolean oneFailed = false; - Socket[] sockets = new Socket[9]; - for (int i = 0 ; i < 9 ; i++) { - LOG.info("Opening socket " + i + " socketsOpened=" + socketsOpened); - try { - sockets[i] = new Socket(); - sockets[i].connect(targetAddress, 5000); - socketsOpened++; - } catch (IOException e) { - LOG.log(Level.SEVERE, "Probably an expected exception trying to open a new connection", e); - assertTrue("Less sockets than low watermark opened.", socketsOpened > 3); - oneFailed = true; - } - } - assertTrue("Opening of one socket was expected to fail.", oneFailed); - - // Notice that the exception received when we tried to open a new socket could have been a timeout (SocketTimeoutException) - // or a connection refused (IOException). It depends on the OS and the network configuration. - // So, we could also have had 5000ms for each bad socket that triggered a SocketTimeoutException. - Thread.sleep(adjust(12000)); - - Socket goodSocket = new Socket(); - // This needs to be longer than 500ms to give the server time to respond to the closed connections. - goodSocket.connect(targetAddress, 10000); - goodSocket.close(); - - // Clean up remaining sockets - for (int i = 0 ; i < socketsOpened ; i++) { - sockets[i].close(); - } - }); - } - - private void runTest(int noRequestTimeout, ExceptionRunnable test) throws Exception { - runTest(true, noRequestTimeout, test); - runTest(false, noRequestTimeout, test); - } - - private void runTest(boolean useSystemProperties, int noRequestTimeout, ExceptionRunnable test) throws Exception { - controller.startInAdminMode(); + protected void runTest(int noRequestTimeout, ExceptionRunnable test) throws Exception { + controller.start(); try (CLIWrapper cli = new CLIWrapper(true)) { - if (useSystemProperties) { - cli.sendLine(String.format(SYSTEM_PROPERTY_ADD, BACKLOG_PROPERTY, 2)); - cli.sendLine(String.format(SYSTEM_PROPERTY_ADD, CONNECTION_HIGH_WATER_PROPERTY, 6)); - cli.sendLine(String.format(SYSTEM_PROPERTY_ADD, CONNECTION_LOW_WATER_PROPERTY, 3)); - cli.sendLine(String.format(SYSTEM_PROPERTY_ADD, NO_REQUEST_TIMEOUT_PROPERTY, noRequestTimeout)); - } else { - cli.sendLine(String.format(HTTP_INTERFACE_READ_ATTRIBUTE, BACKLOG_ATTRIBUTE), true); - String response = cli.readOutput(); - if (response.contains("WFLYCTL0201")) { - LOG.info("Attribute \"backlog\" not found - assuming the attributes are not available at the server's stability level" ); - controller.stop(); - return; - } - cli.sendLine(String.format(HTTP_INTERFACE_WRITE_ATTRIBUTE, BACKLOG_ATTRIBUTE, 2)); - cli.sendLine(String.format(HTTP_INTERFACE_WRITE_ATTRIBUTE, CONNECTION_HIGH_WATER_ATTRIBUTE, 6)); - cli.sendLine(String.format(HTTP_INTERFACE_WRITE_ATTRIBUTE, CONNECTION_LOW_WATER_ATTRIBUTE, 3)); - cli.sendLine(String.format(HTTP_INTERFACE_WRITE_ATTRIBUTE, NO_REQUEST_TIMEOUT_ATTRIBUTE, noRequestTimeout)); - } + cli.sendLine(String.format(SYSTEM_PROPERTY_ADD, BACKLOG_PROPERTY, 2)); + cli.sendLine(String.format(SYSTEM_PROPERTY_ADD, CONNECTION_HIGH_WATER_PROPERTY, 6)); + cli.sendLine(String.format(SYSTEM_PROPERTY_ADD, CONNECTION_LOW_WATER_PROPERTY, 3)); + cli.sendLine(String.format(SYSTEM_PROPERTY_ADD, NO_REQUEST_TIMEOUT_PROPERTY, noRequestTimeout)); } try { @@ -181,17 +47,10 @@ private void runTest(boolean useSystemProperties, int noRequestTimeout, Exceptio controller.reload(); try (CLIWrapper cli = new CLIWrapper(true)) { - if (useSystemProperties) { - cli.sendLine(String.format(SYSTEM_PROPERTY_REMOVE, BACKLOG_PROPERTY)); - cli.sendLine(String.format(SYSTEM_PROPERTY_REMOVE, CONNECTION_HIGH_WATER_PROPERTY)); - cli.sendLine(String.format(SYSTEM_PROPERTY_REMOVE, CONNECTION_LOW_WATER_PROPERTY)); - cli.sendLine(String.format(SYSTEM_PROPERTY_REMOVE, NO_REQUEST_TIMEOUT_PROPERTY)); - } else { - cli.sendLine(String.format(HTTP_INTERFACE_UNDEFINE_ATTRIBUTE, BACKLOG_ATTRIBUTE)); - cli.sendLine(String.format(HTTP_INTERFACE_UNDEFINE_ATTRIBUTE, CONNECTION_HIGH_WATER_ATTRIBUTE)); - cli.sendLine(String.format(HTTP_INTERFACE_UNDEFINE_ATTRIBUTE, CONNECTION_LOW_WATER_ATTRIBUTE)); - cli.sendLine(String.format(HTTP_INTERFACE_UNDEFINE_ATTRIBUTE, NO_REQUEST_TIMEOUT_ATTRIBUTE)); - } + cli.sendLine(String.format(SYSTEM_PROPERTY_REMOVE, BACKLOG_PROPERTY)); + cli.sendLine(String.format(SYSTEM_PROPERTY_REMOVE, CONNECTION_HIGH_WATER_PROPERTY)); + cli.sendLine(String.format(SYSTEM_PROPERTY_REMOVE, CONNECTION_LOW_WATER_PROPERTY)); + cli.sendLine(String.format(SYSTEM_PROPERTY_REMOVE, NO_REQUEST_TIMEOUT_PROPERTY)); } controller.stop(); } diff --git a/testsuite/shared/src/main/java/org/wildfly/test/stability/StabilityServerSetupSnapshotRestoreTasks.java b/testsuite/shared/src/main/java/org/wildfly/test/stability/StabilityServerSetupSnapshotRestoreTasks.java index 4d02b4e9baf..ab77588cfa7 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/stability/StabilityServerSetupSnapshotRestoreTasks.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/stability/StabilityServerSetupSnapshotRestoreTasks.java @@ -87,7 +87,9 @@ protected void doSetup(ManagementClient managementClient) throws Exception { @Override public void tearDown(ManagementClient managementClient) throws Exception { - snapshot.close(); + if (snapshot != null) { + snapshot.close(); + } } private boolean checkReloadEnhancedOperationIsAvailable(ManagementClient managementClient) throws Exception {