-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestingClient.java
More file actions
89 lines (80 loc) · 2.92 KB
/
TestingClient.java
File metadata and controls
89 lines (80 loc) · 2.92 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
*
* client for TCPClient from Kurose and Ross
*
* * Usage: java TCPClient [server addr] [server port]
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
public class TestingClient{
public static void main(String[] args) throws Exception {
String ServerIP = "localhost";
String ServerName = "test-server";
int ServerPort = 10000;
int threadsNum = 1;
String requestPatternFileName = util.REQ_PATH+"/requests.txt";
long threshholdTime = 100;
for (int i = 0; i < args.length - 1; i++) {
if (args[i].equals("-server")) {
ServerIP = args[i+1];
}
else if (args[i].equals("-servname")) {
ServerName = args[i+1];
}
else if (args[i].equals("-port" )) {
ServerPort = Integer.parseInt(args[i+1]);
}
else if (args[i].equals("-parallel" )) {
threadsNum = Integer.parseInt(args[i+1]);
}
else if (args[i].equals("-files")) {
requestPatternFileName = util.REQ_PATH+"/"+ args[i+1];
}
else if (args[i].equals("-T")) {
threshholdTime = Integer.parseInt(args[i+1]);
}
}
File requestFile = new File(requestPatternFileName);
BufferedReader br = new BufferedReader(new FileReader(requestFile));
List<String> filelist = new ArrayList<String>();
String line = br.readLine();
while (line!= null) {
filelist.add("/"+line);
line = br.readLine();
}
br.close();
int tasksNum = filelist.size();
int maxTasksPerThread = (int) Math.ceil((double)tasksNum / (double)threadsNum);
// String[] filelist = {"/file1", "/file2", "/file3", "test.cgi","hello","/load"};
// // System.out.println("hello");
// rh.run();
// connectSocket.close();
// System.out.println("task 1 finished");
// Socket connectSocket2 = new Socket("localhost", 10000);
// // System.out.println("hello");
// RequestHandler rh2 = new RequestHandler(filelist, "Servername", connectSocket2);
// rh2.run();
// System.out.println("task 2 finished");
// connectSocket2.close();
int tasksIndex = 0;
int remainingTasksNum = tasksNum;
for (int i = 0; i < threadsNum; i++) {
int tasksThisThread;
if (maxTasksPerThread < remainingTasksNum) {
tasksThisThread = maxTasksPerThread;
remainingTasksNum -= maxTasksPerThread;
}
else {
tasksThisThread = remainingTasksNum;
remainingTasksNum = 0;
}
RequestGen req = new TestingRequestGen(filelist.toArray(new String[filelist.size()]),
ServerName, ServerPort, ServerIP, 100);
Thread t = new Thread(req);
t.start();
}
} // end of main
} // end of class TCPClient