1515
1616import com .fasterxml .jackson .core .JsonProcessingException ;
1717import org .junit .AfterClass ;
18- import org .junit .BeforeClass ;
18+ import org .junit .Before ;
1919import org .junit .Test ;
2020import reactivefeign .testcase .IcecreamServiceApi ;
2121import reactivefeign .testcase .domain .OrderGenerator ;
2222import reactor .core .publisher .Mono ;
2323import reactor .netty .DisposableServer ;
24+ import reactor .netty .http .HttpProtocol ;
2425import reactor .netty .http .server .HttpServer ;
2526
2627import java .time .Duration ;
@@ -45,24 +46,31 @@ abstract public class ReactivityTest extends BaseReactorTest {
4546
4647 private static DisposableServer server ;
4748
48- @ BeforeClass
49- public static void startServer () throws JsonProcessingException {
50- byte [] data = TestUtils .MAPPER .writeValueAsString (new OrderGenerator ().generate (1 )).getBytes ();
51-
52- server = HttpServer .create ()
53- .protocol (HTTP11 , H2C )
54- .route (r -> r .get ("/icecream/orders/1" ,
55- (req , res ) -> {
56- res .header ("Content-Type" , "application/json" );
57- return Mono .delay (Duration .ofMillis (DELAY_IN_MILLIS ))
58- .thenEmpty (res .sendByteArray (Mono .just (data )));
59- }))
60- .bindNow ();
49+ @ Before
50+ public void startServer () throws JsonProcessingException {
51+ if (server == null ) {
52+ byte [] data = TestUtils .MAPPER .writeValueAsString (new OrderGenerator ().generate (1 )).getBytes ();
53+
54+ server = HttpServer .create ()
55+ .protocol (serverProtocols ())
56+ .route (r -> r .get ("/icecream/orders/1" ,
57+ (req , res ) -> {
58+ res .header ("Content-Type" , "application/json" );
59+ return Mono .delay (Duration .ofMillis (DELAY_IN_MILLIS ))
60+ .thenEmpty (res .sendByteArray (Mono .just (data )));
61+ }))
62+ .bindNow ();
63+ }
64+ }
65+
66+ protected HttpProtocol [] serverProtocols (){
67+ return new HttpProtocol []{HTTP11 , H2C };
6168 }
6269
6370 @ AfterClass
6471 public static void stopServer (){
6572 server .disposeNow ();
73+ server = null ;
6674 }
6775
6876 @ Test
0 commit comments