File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
tests/test-javalin-jsonb/src
main/java/org/example/myapp/web
test/java/org/example/myapp Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 5
5
import java .time .LocalDate ;
6
6
import java .util .ArrayList ;
7
7
import java .util .List ;
8
+ import java .util .concurrent .CompletableFuture ;
9
+ import java .util .concurrent .Executors ;
8
10
9
11
import javax .validation .Valid ;
10
12
@@ -142,6 +144,21 @@ List<HelloDto> getAll() {
142
144
return myService .findAll ();
143
145
}
144
146
147
+ @ Get ("/async" )
148
+ CompletableFuture <List <HelloDto >> getAllAsync () {
149
+ return CompletableFuture .supplyAsync (() -> {
150
+ // Simulate a delay as if an actual IO operation is being executed.
151
+ // This also helps ensure that we aren't just getting lucky with timings.
152
+ try {
153
+ Thread .sleep (10L );
154
+ } catch (InterruptedException e ) {
155
+ throw new RuntimeException (e );
156
+ }
157
+
158
+ return myService .findAll ();
159
+ }, Executors .newSingleThreadExecutor ()); // Example of how to use a custom executor.
160
+ }
161
+
145
162
// @Hidden
146
163
@ Delete (":id" )
147
164
void deleteById (int id ) {
Original file line number Diff line number Diff line change @@ -62,6 +62,25 @@ void hello2() {
62
62
assertThat (helloDtos ).hasSize (2 );
63
63
}
64
64
65
+ @ Test
66
+ void helloAsyncRequestHandling () {
67
+ TypeRef <List <HelloDto >> listDto = new TypeRef <List <HelloDto >>() { };
68
+ final List <HelloDto > beans = given ()
69
+ .get (baseUrl + "/hello/async" )
70
+ .then ()
71
+ .statusCode (200 )
72
+ .extract ()
73
+ .as (listDto );
74
+
75
+ assertThat (beans ).hasSize (2 );
76
+
77
+ final List <HelloDto > helloDtos = client .request ()
78
+ .path ("hello/async" )
79
+ .GET ().list (HelloDto .class );
80
+
81
+ assertThat (helloDtos ).hasSize (2 );
82
+ }
83
+
65
84
@ Test
66
85
void getWithPathParamAndQueryParam () {
67
86
You can’t perform that action at this time.
0 commit comments