Skip to content

Commit 3dfb698

Browse files
sdeleuzesnicoll
authored andcommitted
Add WebFlux Coroutines smoke test
See gh-17701
1 parent 1acf78f commit 3dfb698

File tree

5 files changed

+143
-0
lines changed

5 files changed

+143
-0
lines changed

spring-boot-tests/spring-boot-smoke-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<module>spring-boot-smoke-test-web-static</module>
9999
<module>spring-boot-smoke-test-web-ui</module>
100100
<module>spring-boot-smoke-test-webflux</module>
101+
<module>spring-boot-smoke-test-webflux-coroutines</module>
101102
<module>spring-boot-smoke-test-websocket-jetty</module>
102103
<module>spring-boot-smoke-test-websocket-tomcat</module>
103104
<module>spring-boot-smoke-test-websocket-undertow</module>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<!-- Your own application should inherit from spring-boot-starter-parent -->
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-smoke-tests</artifactId>
9+
<version>${revision}</version>
10+
</parent>
11+
<artifactId>spring-boot-smoke-test-webflux-coroutines</artifactId>
12+
<name>Spring Boot WebFlux Coroutines Smoke Test</name>
13+
<description>Spring Boot WebFlux Coroutines Smoke Test</description>
14+
<properties>
15+
<main.basedir>${basedir}/../../..</main.basedir>
16+
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
17+
</properties>
18+
<dependencies>
19+
<!-- Compile -->
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-webflux</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.fasterxml.jackson.module</groupId>
26+
<artifactId>jackson-module-kotlin</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.jetbrains.kotlin</groupId>
30+
<artifactId>kotlin-reflect</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.jetbrains.kotlin</groupId>
34+
<artifactId>kotlin-stdlib-jdk8</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.jetbrains.kotlinx</groupId>
38+
<artifactId>kotlinx-coroutines-reactor</artifactId>
39+
</dependency>
40+
<!-- Test -->
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-test</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
<build>
48+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
49+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
<plugin>
56+
<groupId>org.jetbrains.kotlin</groupId>
57+
<artifactId>kotlin-maven-plugin</artifactId>
58+
<configuration>
59+
<args>
60+
<arg>-Xjsr305=strict</arg>
61+
</args>
62+
<compilerPlugins>
63+
<plugin>spring</plugin>
64+
</compilerPlugins>
65+
</configuration>
66+
<dependencies>
67+
<dependency>
68+
<groupId>org.jetbrains.kotlin</groupId>
69+
<artifactId>kotlin-maven-allopen</artifactId>
70+
<version>${kotlin.version}</version>
71+
</dependency>
72+
</dependencies>
73+
</plugin>
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-surefire-plugin</artifactId>
77+
<configuration>
78+
<useSystemClassLoader>false</useSystemClassLoader>
79+
</configuration>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package smoketest.coroutines
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication
4+
import org.springframework.boot.runApplication
5+
6+
@SpringBootApplication
7+
class CoroutinesApplication
8+
fun main(args: Array<String>) {
9+
runApplication<CoroutinesApplication>(*args)
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package smoketest.coroutines
2+
3+
import kotlinx.coroutines.delay
4+
import kotlinx.coroutines.flow.flow
5+
import org.springframework.web.bind.annotation.GetMapping
6+
import org.springframework.web.bind.annotation.RestController
7+
8+
@RestController
9+
class CoroutinesController {
10+
11+
@GetMapping("/suspending")
12+
suspend fun suspendingFunction(): String {
13+
delay(10)
14+
return "Hello World"
15+
}
16+
17+
@GetMapping("/flow")
18+
fun flow() = flow {
19+
delay(10)
20+
emit("Hello ")
21+
delay(10)
22+
emit("World")
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package smoketest.coroutines
2+
3+
import org.junit.jupiter.api.Test
4+
import org.springframework.beans.factory.annotation.Autowired
5+
import org.springframework.boot.test.context.SpringBootTest
6+
import org.springframework.boot.test.context.SpringBootTest.*
7+
import org.springframework.http.MediaType
8+
import org.springframework.test.web.reactive.server.WebTestClient
9+
import org.springframework.test.web.reactive.server.expectBody
10+
11+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
12+
class CoroutinesApplicationTests(@Autowired private val webClient: WebTestClient) {
13+
14+
@Test
15+
fun testSuspendingFunction() {
16+
webClient.get().uri("/suspending").accept(MediaType.TEXT_PLAIN).exchange()
17+
.expectBody<String>().isEqualTo("Hello World")
18+
}
19+
20+
@Test
21+
fun testFlow() {
22+
webClient.get().uri("/flow").accept(MediaType.TEXT_PLAIN).exchange()
23+
.expectBody<String>().isEqualTo("Hello World")
24+
}
25+
}

0 commit comments

Comments
 (0)