Search in sources :

Example 6 with NettyReactiveWebServerFactory

use of org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory in project spring-boot by spring-projects.

the class NettyWebServerFactoryCustomizerTests method setIdleTimeout.

@Test
void setIdleTimeout() {
    this.serverProperties.getNetty().setIdleTimeout(Duration.ofSeconds(1));
    NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
    this.customizer.customize(factory);
    verifyIdleTimeout(factory, Duration.ofSeconds(1));
}
Also used : NettyReactiveWebServerFactory(org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory) Test(org.junit.jupiter.api.Test)

Example 7 with NettyReactiveWebServerFactory

use of org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory in project spring-boot by spring-projects.

the class ReactiveWebServerFactoryAutoConfigurationTests method nettyServerCustomizerBeanIsAddedToFactory.

@Test
void nettyServerCustomizerBeanIsAddedToFactory() {
    new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebApplicationContext::new).withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)).withClassLoader(new FilteredClassLoader(Tomcat.class, Server.class, Undertow.class)).withUserConfiguration(NettyServerCustomizerConfiguration.class, HttpHandlerConfiguration.class).run((context) -> {
        NettyReactiveWebServerFactory factory = context.getBean(NettyReactiveWebServerFactory.class);
        assertThat(factory.getServerCustomizers()).hasSize(1);
    });
}
Also used : NettyReactiveWebServerFactory(org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory) Tomcat(org.apache.catalina.startup.Tomcat) Server(org.eclipse.jetty.server.Server) HttpServer(reactor.netty.http.server.HttpServer) Undertow(io.undertow.Undertow) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 8 with NettyReactiveWebServerFactory

use of org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory in project spring-boot by spring-projects.

the class NettyWebServerFactoryCustomizerTests method configureHttpRequestDecoder.

@Test
void configureHttpRequestDecoder() {
    ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
    nettyProperties.setValidateHeaders(false);
    nettyProperties.setInitialBufferSize(DataSize.ofBytes(512));
    nettyProperties.setH2cMaxContentLength(DataSize.ofKilobytes(1));
    nettyProperties.setMaxChunkSize(DataSize.ofKilobytes(16));
    nettyProperties.setMaxInitialLineLength(DataSize.ofKilobytes(32));
    NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
    this.customizer.customize(factory);
    then(factory).should().addServerCustomizers(this.customizerCaptor.capture());
    NettyServerCustomizer serverCustomizer = this.customizerCaptor.getValue();
    HttpServer httpServer = serverCustomizer.apply(HttpServer.create());
    HttpRequestDecoderSpec decoder = httpServer.configuration().decoder();
    assertThat(decoder.validateHeaders()).isFalse();
    assertThat(decoder.initialBufferSize()).isEqualTo(nettyProperties.getInitialBufferSize().toBytes());
    assertThat(decoder.h2cMaxContentLength()).isEqualTo(nettyProperties.getH2cMaxContentLength().toBytes());
    assertThat(decoder.maxChunkSize()).isEqualTo(nettyProperties.getMaxChunkSize().toBytes());
    assertThat(decoder.maxInitialLineLength()).isEqualTo(nettyProperties.getMaxInitialLineLength().toBytes());
}
Also used : NettyReactiveWebServerFactory(org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory) NettyServerCustomizer(org.springframework.boot.web.embedded.netty.NettyServerCustomizer) HttpRequestDecoderSpec(reactor.netty.http.server.HttpRequestDecoderSpec) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) HttpServer(reactor.netty.http.server.HttpServer) Test(org.junit.jupiter.api.Test)

Example 9 with NettyReactiveWebServerFactory

use of org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory in project spring-boot by spring-projects.

the class NettyWebServerFactoryCustomizerTests method setConnectionTimeout.

@Test
void setConnectionTimeout() {
    this.serverProperties.getNetty().setConnectionTimeout(Duration.ofSeconds(1));
    NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
    this.customizer.customize(factory);
    verifyConnectionTimeout(factory, 1000);
}
Also used : NettyReactiveWebServerFactory(org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory) Test(org.junit.jupiter.api.Test)

Example 10 with NettyReactiveWebServerFactory

use of org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory in project spring-boot by spring-projects.

the class ReactiveWebServerFactoryAutoConfigurationTests method nettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void nettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)).withClassLoader(new FilteredClassLoader(Tomcat.class, Server.class, Undertow.class)).withUserConfiguration(DoubleRegistrationNettyServerCustomizerConfiguration.class, HttpHandlerConfiguration.class).withPropertyValues("server.port: 0").run((context) -> {
        NettyReactiveWebServerFactory factory = context.getBean(NettyReactiveWebServerFactory.class);
        NettyServerCustomizer customizer = context.getBean("serverCustomizer", NettyServerCustomizer.class);
        assertThat(factory.getServerCustomizers()).contains(customizer);
        then(customizer).should().apply(any(HttpServer.class));
    });
}
Also used : NettyReactiveWebServerFactory(org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory) NettyServerCustomizer(org.springframework.boot.web.embedded.netty.NettyServerCustomizer) HttpServer(reactor.netty.http.server.HttpServer) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)10 NettyReactiveWebServerFactory (org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory)10 HttpServer (reactor.netty.http.server.HttpServer)3 FilteredClassLoader (org.springframework.boot.test.context.FilteredClassLoader)2 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)2 NettyServerCustomizer (org.springframework.boot.web.embedded.netty.NettyServerCustomizer)2 Undertow (io.undertow.Undertow)1 Tomcat (org.apache.catalina.startup.Tomcat)1 Server (org.eclipse.jetty.server.Server)1 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)1 AnnotationConfigReactiveWebApplicationContext (org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext)1 HttpRequestDecoderSpec (reactor.netty.http.server.HttpRequestDecoderSpec)1