|
| 1 | +/* |
| 2 | + * Copyright 2012-2024 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.autoconfigure.web.embedded; |
| 18 | + |
| 19 | +import io.undertow.servlet.api.DeploymentInfo; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | +import org.junit.jupiter.api.condition.EnabledForJreRange; |
| 22 | +import org.junit.jupiter.api.condition.JRE; |
| 23 | + |
| 24 | +import org.springframework.boot.autoconfigure.AutoConfigurations; |
| 25 | +import org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration.UndertowWebServerFactoryCustomizerConfiguration; |
| 26 | +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
| 27 | +import org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer; |
| 28 | +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext; |
| 29 | +import org.springframework.core.task.VirtualThreadTaskExecutor; |
| 30 | + |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; |
| 32 | + |
| 33 | +/** |
| 34 | + * Tests for {@link UndertowWebServerFactoryCustomizerConfiguration}. |
| 35 | + * |
| 36 | + * @author Moritz Halbritter |
| 37 | + */ |
| 38 | +class UndertowWebServerFactoryCustomizerConfigurationTests { |
| 39 | + |
| 40 | + private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner( |
| 41 | + AnnotationConfigServletWebApplicationContext::new) |
| 42 | + .withConfiguration(AutoConfigurations.of(EmbeddedWebServerFactoryCustomizerAutoConfiguration.class)); |
| 43 | + |
| 44 | + @EnabledForJreRange(min = JRE.JAVA_21) |
| 45 | + @Test |
| 46 | + void shouldUseVirtualThreadsIfEnabled() { |
| 47 | + this.contextRunner.withPropertyValues("spring.threads.virtual.enabled=true").run((context) -> { |
| 48 | + assertThat(context).hasSingleBean(UndertowDeploymentInfoCustomizer.class); |
| 49 | + assertThat(context).hasBean("virtualThreadsUndertowDeploymentInfoCustomizer"); |
| 50 | + UndertowDeploymentInfoCustomizer customizer = context.getBean(UndertowDeploymentInfoCustomizer.class); |
| 51 | + DeploymentInfo deploymentInfo = new DeploymentInfo(); |
| 52 | + customizer.customize(deploymentInfo); |
| 53 | + assertThat(deploymentInfo.getExecutor()).isInstanceOf(VirtualThreadTaskExecutor.class); |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | +} |
0 commit comments