File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
libraries-5/src/test/java/com/baeldung/activej Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 12
12
import org .junit .jupiter .api .BeforeAll ;
13
13
import org .junit .jupiter .api .Test ;
14
14
15
+ import java .io .IOException ;
15
16
import java .net .InetAddress ;
17
+ import java .net .InetSocketAddress ;
18
+ import java .net .ServerSocket ;
16
19
17
20
import static org .junit .jupiter .api .Assertions .assertEquals ;
18
21
@@ -36,8 +39,8 @@ static void setUp() throws Exception {
36
39
.build ();
37
40
38
41
server = HttpServer .builder (eventloop , servlet )
39
- .withListenPort (8080 )
40
- .build ();
42
+ .withListenPort (randomPort () )
43
+ .build ();
41
44
42
45
server .listen ();
43
46
@@ -48,6 +51,14 @@ static void setUp() throws Exception {
48
51
client = HttpClient .builder (eventloop , dnsClient ).build ();
49
52
}
50
53
54
+ private static int randomPort () {
55
+ try (ServerSocket socket = new ServerSocket (0 )) {
56
+ return socket .getLocalPort ();
57
+ } catch (IOException e ) {
58
+ throw new RuntimeException ("Failed to find a free port" , e );
59
+ }
60
+ }
61
+
51
62
@ AfterAll
52
63
static void tearDown () {
53
64
if (server != null ) {
You can’t perform that action at this time.
0 commit comments