1 Star 0 Fork 0

迷途的指针/JavaWebTester

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TestClientRunnable.java 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
迷途的指针 提交于 2018-11-26 10:21 +08:00 . 添加get支持
import com.google.gson.JsonObject;
import java.util.Date;
public class TestClientRunnable implements Runnable {
private TestClient testClient;
private RequestMethod method;
private long waitTime;
private JsonObject data;
private boolean running;
private int count;
private long totalTime;
private int failCount;
private long longestTime = 0;
private long shortestTime = 0x7fffffffffffffffL;
public TestClientRunnable(String url, RequestMethod method, long waitTime){
this(url, method, waitTime, new JsonObject());
}
public TestClientRunnable(String url, RequestMethod method, long waitTime, JsonObject data){
testClient = new TestClient(url);
this.method = method;
this.waitTime = waitTime;
this.data = data;
running = true;
}
public int getCount(){
return count;
}
public int getFailCount(){
return failCount;
}
public long getTotalTime(){
return totalTime;
}
public long getLongestTime() {
return longestTime;
}
public long getShortestTime() {
return shortestTime;
}
@Override
public void run() {
int counter;
//System.out.println(Thread.currentThread().getName() + " is running");
while (running){
counter = 1;
switch (method){
case GET:
if (testClient.get() == null)
counter = 0;
break;
case POST:
if (testClient.post(data) == null)
counter = 0;
break;
case PUT:
//TODO: PUT method
break;
case DELETE:
//TODO: GET method
break;
}
count += counter;
long dt = testClient.lastTime;
//System.out.println(dt);
longestTime = longestTime > dt ? longestTime : dt;
shortestTime = shortestTime < dt ? shortestTime : dt;
if (counter > 0){
totalTime += dt;
}
else {
failCount += 1;
}
try {
Thread.sleep(waitTime - dt > 0 ? waitTime - dt : 0);
}
catch (InterruptedException e){
running = false;
//System.out.println(Thread.currentThread().getName() + " is exiting, sent " + count + " requests");
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/PointerY/JavaWebTester.git
git@gitee.com:PointerY/JavaWebTester.git
PointerY
JavaWebTester
JavaWebTester
master

搜索帮助