OkHttpDebug.java
2.18 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
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.taover.util.UtilHttpByOkHttp;
public class OkHttpDebug {
public static void main(String args[]) {
//loadRequestPerMinute(10);
//testWarePushOrder(100);
multiRequest(10);
}
private static void multiRequest(int count) {
for(int sequence=0; sequence<count; ++sequence) {
new RequestThread(sequence).start();
}
}
private static void testWarePushOrder(int pushCount) {
Map<String, Object> params = new HashMap<String, Object>();
for(int i=0; i<pushCount; ++i) {
try {
if(i%2 == 0) {
params.put("wareId", 20);
}else {
params.put("wareId", 34);
}
Thread.sleep(3000);
long starTime = System.currentTimeMillis();
String response = UtilHttpByOkHttp.sendPostForm("http://localhost/api/schedule/ware/order", null, params);
long endTime = System.currentTimeMillis();
System.out.println("success["+i+"]["+(endTime-starTime)+"]:"+response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private static void loadRequestPerMinute(int i) {
double gapSecond = 60.0/i;
int sequence = 0;
while(true) {
++sequence;
new RequestThread(sequence).start();
try {
Thread.sleep((long)(gapSecond*1000));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class RequestThread extends Thread{
int sequence = 0;
public RequestThread(int sequence) {
this.sequence = sequence;
}
@Override
public void run() {
try {
long starTime = System.currentTimeMillis();
UtilHttpByOkHttp.sendGet("http://api.wxorder.taover.com/v1/wxorderorder?page=1&size=100&controlStatus=", Collections.singletonMap("Authorization", "bearer;eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0ZW5hbnQiOiIxNiIsInVzZXJuYW1lIjoiMTM2MjEwNTEyMzAiLCJ1c2VyaWQiOiIxNyIsImlzcyI6ImFkbWluIiwiYXVkIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJleHAiOjE2MDI4NDM5MzIsIm5iZiI6MTYwMjY3MTEzMn0.PbXwPqpFYQB7dwAeB9ELr6dho29k_YZCtcVoECeo-wM"), 60);
Thread.sleep(2000);
long endTime = System.currentTimeMillis();
System.out.println("success["+this.sequence+"]:"+(endTime-starTime));
} catch (Exception e) {
System.out.println("fail");
}
}
}