Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFCORE-7008] Use concrete log per child class, request sockets to be closed inmediately #6209

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions testsuite/manualmode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
<!--
<byteman.jvm.args>-javaagent:${org.jboss.byteman:byteman:jar}=port:${byteman.port},address:${byteman.host},boot:${org.jboss.byteman:byteman:jar} -Dorg.jboss.byteman.transform.all -Dorg.jboss.byteman.verbose=true</byteman.jvm.args>
-->

</properties>

<dependencies>
<dependency>
<groupId>jakarta.inject</groupId>
Expand Down Expand Up @@ -583,7 +583,7 @@
<!-- restart the server -->
<exclude>org.jboss.as.test.manualmode.deployment.DeploymentScannerRedeploymentTestCase</exclude>
<exclude>org.jboss.as.test.manualmode.deployment.DeploymentScannerUnitTestCase</exclude>

<!-- restart the server -->
<exclude>org.jboss.as.test.manualmode.logging.LoggingDependenciesTestCase</exclude>
<exclude>org.jboss.as.test.manualmode.logging.LoggingPreferencesTestCase</exclude>
Expand All @@ -598,7 +598,7 @@
<exclude>org.jboss.as.test.manualmode.provisioning.InstallationManagerBootTestCase</exclude>
<!-- restart the server -->
<exclude>org.jboss.as.test.manualmode.management.*TestCase</exclude>

<exclude>org.jboss.as.test.manualmode.management.cli.ManagementOpTimeoutTestCase</exclude>
<exclude>org.jboss.as.test.manualmode.management.cli.ShutdownTestCase</exclude>

Expand All @@ -615,21 +615,20 @@
<exclude>org.jboss.as.test.manualmode.management.cli.RemoveManagementRealmTestCase</exclude>
<!-- no git support -->
<exclude>org.jboss.as.test.manualmode.management.persistence.*TestCase</exclude>

<!-- replace config file -->
<exclude>org.jboss.as.test.manualmode.mgmt.elytron.ElytronModelControllerClientTestCase</exclude>

<!--- remove a module after having closed the server -->
<exclude>org.jboss.as.test.manualmode.expressions.CredentialStoreExpressionsTestCase</exclude>

<!-- admin mode -->
<exclude>org.wildfly.core.test.standalone.mgmt.ManagementInterfaceResourcesTestCase</exclude>
<exclude>org.jboss.as.test.manualmode.adminonly.auditlog.*TestCase.java</exclude>
<exclude>org.jboss.as.test.manualmode.cli.boot.ops.CliBootOperationsTestCase.java</exclude>

<!-- start /stop, and install extension before start -->
<exclude>org.wildfly.core.test.standalone.mgmt.PreparedResponseTestCase</exclude>

<!-- start/stop/start the server -->
<exclude>org.wildfly.core.test.standalone.mgmt.events.*TestCase</exclude>
<!-- Requires modification of the process-uuid file inside the Jar -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* 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 <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
@RunWith(WildFlyRunner.class)
@ServerControl(manual = true)
public abstract class AbstractManagementInterfaceResourcesTestCase {
@Inject
protected static ServerController controller;

@Test
public void testNothing() throws Exception {
runTest(60000, () -> {});
}

/**
* 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);
sockets[i].setSoLinger(true, 0);
assertTrue("Socket is connected.", sockets[i].isConnected());
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);
sockets[i].setSoLinger(true, 0);
assertTrue("Socket is connected.", sockets[i].isConnected());
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<Exception> test) throws Exception;

abstract Logger log();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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 java.util.logging.Logger;

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.
* <p>
* This test case uses attributes defined directly on the HTTP management interface resource for configuration.
*
* @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
*/
public class ManagementInterfaceResourcesCommunityTestCase extends AbstractManagementInterfaceResourcesTestCase {
protected static final Logger LOG = Logger.getLogger(ManagementInterfaceResourcesCommunityTestCase.class.getName());

/*
* 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<Exception> test) throws Exception {
controller.start();
ManagementClient client = controller.getClient();

ServerSetupTask task = new ManagementInterfaceSetUpTask(noRequestTimeout);

try {
task.setup(client);
test.run();
} finally {
controller.reload();
task.tearDown(client);
controller.stop();
}
}

static 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);
}

}

@Override
Logger log() {
return LOG;
}
}
Loading
Loading