-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadTestingClient.java
39 lines (32 loc) · 1.09 KB
/
LoadTestingClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.evgeniy.ua.client;
import org.evgeniy.ua.util.ProgramArgumentsUtil;
import java.io.IOException;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class LoadTestingClient {
private static final int DEFAULT_PORT = 4567;
public static void start(String[] args) {
int port = ProgramArgumentsUtil.extract(args, 1, Integer::valueOf, DEFAULT_PORT);
List<Socket> sockets = new ArrayList<>();
System.out.println("Opening sockets for server on port " + port + "...");
for (int i = 0; i < 10_000; i++) {
try {
sockets.add(new Socket("localhost", port));
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Print any string to exit");
new Scanner(System.in).next();
System.out.println("Closing connections");
sockets.forEach(s -> {
try {
s.close();
} catch (IOException e) {
e.printStackTrace();
}
});
}
}