1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .http .client .reactive ;
18
18
19
+ import java .net .URI ;
19
20
import java .util .function .Function ;
20
21
21
22
import org .junit .jupiter .api .Test ;
23
+ import reactor .core .publisher .Mono ;
22
24
import reactor .netty .http .client .HttpClient ;
23
25
26
+ import org .springframework .http .HttpMethod ;
24
27
import org .springframework .http .client .ReactorResourceFactory ;
25
28
26
29
import static org .assertj .core .api .Assertions .assertThat ;
27
30
28
31
/**
29
32
* @author Sebastien Deleuze
33
+ * @author Juergen Hoeller
30
34
* @since 6.1
31
35
*/
32
36
class ReactorClientHttpConnectorTests {
@@ -41,6 +45,8 @@ void restartWithDefaultConstructor() {
41
45
assertThat (connector .isRunning ()).isTrue ();
42
46
connector .start ();
43
47
assertThat (connector .isRunning ()).isTrue ();
48
+ connector .stop ();
49
+ assertThat (connector .isRunning ()).isTrue ();
44
50
}
45
51
46
52
@ Test
@@ -54,6 +60,8 @@ void restartWithHttpClient() {
54
60
assertThat (connector .isRunning ()).isTrue ();
55
61
connector .start ();
56
62
assertThat (connector .isRunning ()).isTrue ();
63
+ connector .stop ();
64
+ assertThat (connector .isRunning ()).isTrue ();
57
65
}
58
66
59
67
@ Test
@@ -69,6 +77,8 @@ void restartWithExternalResourceFactory() {
69
77
assertThat (connector .isRunning ()).isFalse ();
70
78
connector .start ();
71
79
assertThat (connector .isRunning ()).isTrue ();
80
+ connector .stop ();
81
+ assertThat (connector .isRunning ()).isFalse ();
72
82
}
73
83
74
84
@ Test
@@ -84,6 +94,27 @@ void lateStartWithExternalResourceFactory() {
84
94
assertThat (connector .isRunning ()).isFalse ();
85
95
connector .start ();
86
96
assertThat (connector .isRunning ()).isTrue ();
97
+ connector .stop ();
98
+ assertThat (connector .isRunning ()).isFalse ();
99
+ }
100
+
101
+ @ Test
102
+ void lazyStartWithExternalResourceFactory () throws Exception {
103
+ ReactorResourceFactory resourceFactory = new ReactorResourceFactory ();
104
+ Function <HttpClient , HttpClient > mapper = Function .identity ();
105
+ ReactorClientHttpConnector connector = new ReactorClientHttpConnector (resourceFactory , mapper );
106
+ assertThat (connector .isRunning ()).isFalse ();
107
+ resourceFactory .start ();
108
+ connector .connect (HttpMethod .GET , new URI ("" ), request -> Mono .empty ());
109
+ assertThat (connector .isRunning ()).isTrue ();
110
+ connector .stop ();
111
+ assertThat (connector .isRunning ()).isFalse ();
112
+ connector .connect (HttpMethod .GET , new URI ("" ), request -> Mono .empty ());
113
+ assertThat (connector .isRunning ()).isFalse ();
114
+ connector .start ();
115
+ assertThat (connector .isRunning ()).isTrue ();
116
+ connector .stop ();
117
+ assertThat (connector .isRunning ()).isFalse ();
87
118
}
88
119
89
120
}
0 commit comments