Commit d5a4c22f authored by yanzg's avatar yanzg

表结构修改

parent 731fbd04
......@@ -4,6 +4,7 @@ import com.yanzuoguang.util.helper.BaiduHelper;
import com.yanzuoguang.util.helper.HttpHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.thread.ThreadHelper;
import helper.vo.BaiduDate;
import org.junit.Test;
......@@ -88,4 +89,97 @@ public class HttpHelperTest {
String result = HttpHelper.post("http://127.0.0.1:6903/test/wait/20000", StringHelper.EMPTY);
System.out.println(result);
}
@Test
public void testHelper() throws Exception {
String result = HttpHelper.post("http://127.0.0.1:6903/test/wait/20000", StringHelper.EMPTY);
System.out.println(result);
}
@Test
public void testThread() throws Exception {
int maxThread = 100;
int maxCount = 100000;
Request req = new Request("http://10.150.2.3:6888/tbd_system/login/heart", maxThread, maxCount);
// Request req = new Request("http://127.0.0.1:6907/login/heart", maxThread, maxCount);
long totalStart = System.currentTimeMillis();
for (int i = 0; i < req.thread; i++) {
ThreadHelper.runThread(() -> {
while (true) {
synchronized (req) {
if (req.start < req.max) {
req.start++;
} else {
return;
}
}
long start = System.currentTimeMillis();
boolean isError = false;
try {
String s = HttpHelper.get(req.url);
} catch (Exception ex) {
isError = true;
} finally {
long end = System.currentTimeMillis();
long time = end - start;
synchronized (req) {
req.maxTime = Math.max(time, req.maxTime);
req.minTime = Math.max(time, req.maxTime);
if (isError) {
req.error++;
} else {
req.ok++;
}
}
}
}
});
}
while (req.max > req.ok + req.error) {
ThreadHelper.sleep(100);
System.out.println(req);
}
long totalEnd = System.currentTimeMillis();
System.out.println("总用时:" + (totalEnd - totalStart));
}
class Request {
String url;
int thread;
int max;
volatile int start;
volatile int ok;
volatile int error;
volatile long maxTime;
volatile long minTime;
public Request(String url, int thread, int max) {
this.url = url;
this.thread = thread;
this.max = max;
}
@Override
public String toString() {
return "Request{" +
"url='" + url + '\'' +
", thread=" + thread +
", max=" + max +
", start=" + start +
", ok=" + ok +
", error=" + error +
", maxTime=" + maxTime +
", minTime=" + minTime +
'}';
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment