17
17
18
18
package org .apache .uniffle .common .web ;
19
19
20
- import java .io .FileNotFoundException ;
21
-
22
20
import org .eclipse .jetty .server .Handler ;
23
21
import org .eclipse .jetty .server .Server ;
24
22
import org .eclipse .jetty .server .ServerConnector ;
25
23
import org .eclipse .jetty .servlet .ServletContextHandler ;
26
24
import org .eclipse .jetty .util .thread .ExecutorThreadPool ;
27
- import org .junit .jupiter .api .AfterEach ;
28
- import org .junit .jupiter .api .BeforeEach ;
29
25
import org .junit .jupiter .api .Test ;
30
26
31
27
import org .apache .uniffle .common .config .RssBaseConf ;
32
- import org .apache .uniffle .common .port .PortRegistry ;
33
28
import org .apache .uniffle .common .util .ExitUtils ;
34
29
import org .apache .uniffle .common .util .ExitUtils .ExitException ;
35
30
36
31
import static org .junit .jupiter .api .Assertions .assertEquals ;
32
+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
37
33
import static org .junit .jupiter .api .Assertions .assertTrue ;
38
34
39
35
public class JettyServerTest {
40
-
41
- int port ;
42
-
43
- @ BeforeEach
44
- public void beforeEach () {
45
- port = PortRegistry .reservePort ();
46
- }
47
-
48
- @ AfterEach
49
- public void afterEach () {
50
- PortRegistry .release (port );
51
- }
52
-
53
36
@ Test
54
- public void jettyServerTest () throws FileNotFoundException {
37
+ public void jettyServerTest () throws Exception {
55
38
RssBaseConf conf = new RssBaseConf ();
56
- conf .setInteger ("rss.jetty.http.port" , port );
39
+ conf .setInteger ("rss.jetty.http.port" , 0 );
57
40
JettyServer jettyServer = new JettyServer (conf );
58
41
Server server = jettyServer .getServer ();
59
42
@@ -65,21 +48,26 @@ public void jettyServerTest() throws FileNotFoundException {
65
48
assertEquals (server , server .getHandler ().getServer ());
66
49
assertTrue (server .getConnectors ()[0 ] instanceof ServerConnector );
67
50
ServerConnector connector = (ServerConnector ) server .getConnectors ()[0 ];
68
- assertEquals (port , connector .getPort ());
51
+ assertEquals (0 , connector .getPort ());
52
+ jettyServer .start ();
53
+ assertEquals (jettyServer .getHttpPort (), connector .getLocalPort ());
54
+ assertNotEquals (jettyServer .getHttpPort (), 0 );
69
55
70
56
assertEquals (1 , server .getHandlers ().length );
71
57
Handler handler = server .getHandler ();
72
58
assertTrue (handler instanceof ServletContextHandler );
59
+ jettyServer .stop ();
73
60
}
74
61
75
62
@ Test
76
63
public void jettyServerStartTest () throws Exception {
77
64
RssBaseConf conf = new RssBaseConf ();
78
- conf .setInteger ("rss.jetty.http.port" , port );
65
+ conf .setInteger ("rss.jetty.http.port" , 0 );
79
66
JettyServer jettyServer1 = new JettyServer (conf );
80
- JettyServer jettyServer2 = new JettyServer (conf );
81
- jettyServer1 .start ();
82
67
68
+ int portExist = jettyServer1 .start ();
69
+ conf .setInteger ("rss.jetty.http.port" , portExist );
70
+ JettyServer jettyServer2 = new JettyServer (conf );
83
71
ExitUtils .disableSystemExit ();
84
72
final String expectMessage = "Fail to start jetty http server" ;
85
73
final int expectStatus = 1 ;
0 commit comments