Skip to content

Commit

Permalink
Fix Jetty ConnectionLimit configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
okohub authored and mhalbritter committed Jan 10, 2024
1 parent 793801b commit 7113c10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
* @author Venil Noronha
* @author Henri Kerola
* @author Moritz Halbritter
* @author Onur Kagan Ozcan
* @since 2.0.0
* @see #setPort(int)
* @see #setConfigurations(Collection)
Expand Down Expand Up @@ -183,7 +184,7 @@ public WebServer getWebServer(ServletContextInitializer... initializers) {
server.setHandler(addHandlerWrappers(context));
this.logger.info("Server initialized with port: " + port);
if (this.maxConnections > -1) {
server.addBean(new ConnectionLimit(this.maxConnections, server));
server.addBean(new ConnectionLimit(this.maxConnections, server.getConnectors()));
}
if (Ssl.isEnabled(getSsl())) {
customizeSsl(server, address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.InstanceOfAssertFactories.LIST;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.inOrder;
Expand All @@ -85,6 +86,7 @@
* @author Andy Wilkinson
* @author Henri Kerola
* @author Moritz Halbritter
* @author Onur Kagan Ozcan
*/
class JettyServletWebServerFactoryTests extends AbstractServletWebServerFactoryTests {

Expand Down Expand Up @@ -541,6 +543,17 @@ void shouldApplyMaxConnections() {
assertThat(connectionLimit.getMaxConnections()).isOne();
}

@Test
void shouldApplyingMaxConnectionUseConnector() throws Exception {
JettyServletWebServerFactory factory = getFactory();
factory.setMaxConnections(1);
this.webServer = factory.getWebServer();
Server server = ((JettyWebServer) this.webServer).getServer();
assertThat(server.getConnectors()).isEmpty();
ConnectionLimit connectionLimit = server.getBean(ConnectionLimit.class);
assertThat(connectionLimit).extracting("_connectors", LIST).hasSize(1);
}

@Override
protected String startedLogMessage() {
return ((JettyWebServer) this.webServer).getStartedLogMessage();
Expand Down

0 comments on commit 7113c10

Please sign in to comment.