Search in sources :

Example 1 with AnnotationConfigReactiveWebServerApplicationContext

use of org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext in project spring-boot by spring-projects.

the class ReactiveManagementContextFactoryTests method createManagementContextShouldCreateChildContextWithConfigClasses.

@Test
void createManagementContextShouldCreateChildContextWithConfigClasses() {
    this.parent.register(ParentConfiguration.class);
    this.parent.refresh();
    AnnotationConfigReactiveWebServerApplicationContext childContext = (AnnotationConfigReactiveWebServerApplicationContext) this.factory.createManagementContext(this.parent, TestConfiguration1.class, TestConfiguration2.class);
    childContext.refresh();
    assertThat(childContext.getBean(TestConfiguration1.class)).isNotNull();
    assertThat(childContext.getBean(TestConfiguration2.class)).isNotNull();
    assertThat(childContext.getBean(ReactiveWebServerFactoryAutoConfiguration.class)).isNotNull();
    childContext.close();
    this.parent.close();
}
Also used : AnnotationConfigReactiveWebServerApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext) Test(org.junit.jupiter.api.Test)

Example 2 with AnnotationConfigReactiveWebServerApplicationContext

use of org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext in project spring-boot by spring-projects.

the class TomcatMetricsAutoConfigurationTests method autoConfiguresTomcatMetricsWithEmbeddedReactiveTomcat.

@Test
void autoConfiguresTomcatMetricsWithEmbeddedReactiveTomcat() {
    resetTomcatState();
    new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(TomcatMetricsAutoConfiguration.class, ReactiveWebServerFactoryAutoConfiguration.class)).withUserConfiguration(ReactiveWebServerConfiguration.class, MeterRegistryConfiguration.class).withPropertyValues("server.tomcat.mbeanregistry.enabled=true").run((context) -> {
        context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
        SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
        assertThat(registry.find("tomcat.sessions.active.max").meter()).isNotNull();
        assertThat(registry.find("tomcat.threads.current").meter()).isNotNull();
    });
}
Also used : AnnotationConfigReactiveWebServerApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 3 with AnnotationConfigReactiveWebServerApplicationContext

use of org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext in project spring-boot by spring-projects.

the class ReactiveManagementContextFactory method createManagementContext.

@Override
public ConfigurableWebServerApplicationContext createManagementContext(ApplicationContext parent, Class<?>... configClasses) {
    AnnotationConfigReactiveWebServerApplicationContext child = new AnnotationConfigReactiveWebServerApplicationContext();
    child.setParent(parent);
    Class<?>[] combinedClasses = ObjectUtils.addObjectToArray(configClasses, ReactiveWebServerFactoryAutoConfiguration.class);
    child.register(combinedClasses);
    registerReactiveWebServerFactory(parent, child);
    return child;
}
Also used : AnnotationConfigReactiveWebServerApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext)

Example 4 with AnnotationConfigReactiveWebServerApplicationContext

use of org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext in project spring-boot by spring-projects.

the class ReactiveWebServerFactoryAutoConfigurationTests method tomcatContextCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void tomcatContextCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)).withUserConfiguration(HttpHandlerConfiguration.class, DoubleRegistrationTomcatContextCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        TomcatReactiveWebServerFactory factory = context.getBean(TomcatReactiveWebServerFactory.class);
        TomcatContextCustomizer customizer = context.getBean("contextCustomizer", TomcatContextCustomizer.class);
        assertThat(factory.getTomcatContextCustomizers()).contains(customizer);
        then(customizer).should().customize(any(Context.class));
    });
}
Also used : TomcatContextCustomizer(org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer) AnnotationConfigReactiveWebServerApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext) AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext) Context(org.apache.catalina.Context) TomcatReactiveWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 5 with AnnotationConfigReactiveWebServerApplicationContext

use of org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext in project spring-boot by spring-projects.

the class RSocketWebSocketNettyRouteProviderTests method webEndpointsShouldWork.

@Test
void webEndpointsShouldWork() {
    new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(HttpHandlerAutoConfiguration.class, WebFluxAutoConfiguration.class, ErrorWebFluxAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, JacksonAutoConfiguration.class, CodecsAutoConfiguration.class, RSocketStrategiesAutoConfiguration.class, RSocketServerAutoConfiguration.class, RSocketMessagingAutoConfiguration.class, RSocketRequesterAutoConfiguration.class)).withUserConfiguration(WebConfiguration.class).withPropertyValues("spring.rsocket.server.transport=websocket", "spring.rsocket.server.mapping-path=/rsocket").run((context) -> {
        ReactiveWebServerApplicationContext serverContext = (ReactiveWebServerApplicationContext) context.getSourceApplicationContext();
        RSocketRequester requester = createRSocketRequester(context, serverContext.getWebServer());
        TestProtocol rsocketResponse = requester.route("websocket").data(new TestProtocol("rsocket")).retrieveMono(TestProtocol.class).block(Duration.ofSeconds(3));
        assertThat(rsocketResponse.getName()).isEqualTo("rsocket");
        WebTestClient client = createWebTestClient(serverContext.getWebServer());
        client.get().uri("/protocol").exchange().expectStatus().isOk().expectBody().jsonPath("name", "http");
    });
}
Also used : RSocketRequester(org.springframework.messaging.rsocket.RSocketRequester) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) AnnotationConfigReactiveWebServerApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext) AnnotationConfigReactiveWebServerApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext) ReactiveWebServerApplicationContext(org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Aggregations

AnnotationConfigReactiveWebServerApplicationContext (org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext)9 Test (org.junit.jupiter.api.Test)6 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 Context (org.apache.catalina.Context)2 TomcatContextCustomizer (org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer)2 TomcatReactiveWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory)2 AnnotationConfigReactiveWebApplicationContext (org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext)2 ReactiveWebServerApplicationContext (org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext)1 RSocketRequester (org.springframework.messaging.rsocket.RSocketRequester)1 WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)1