|
@@ -20,6 +20,8 @@ import cn.seecoder.web.service.user.UserService;
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
import net.sf.json.JSONArray;
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -40,7 +42,7 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
@Service
|
|
|
public class APITestServiceImpl implements APITestService {
|
|
public class APITestServiceImpl implements APITestService {
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(APITestServiceImpl.class);
|
|
|
private final APITestMapper apiTestMapper;
|
|
private final APITestMapper apiTestMapper;
|
|
|
|
|
|
|
|
private final PipelineMapper pipelineMapper;
|
|
private final PipelineMapper pipelineMapper;
|
|
@@ -225,7 +227,7 @@ public class APITestServiceImpl implements APITestService {
|
|
|
try {
|
|
try {
|
|
|
arr = doPost(url, params);
|
|
arr = doPost(url, params);
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ log.error("POST api test request failed, url={}, testId={}", url, testId, e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
timeList.add(arr[1]);
|
|
timeList.add(arr[1]);
|
|
@@ -234,7 +236,8 @@ public class APITestServiceImpl implements APITestService {
|
|
|
try{
|
|
try{
|
|
|
Thread.sleep(100);
|
|
Thread.sleep(100);
|
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ log.warn("API test thread interrupted, testId={}", testId, e);
|
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -352,13 +355,13 @@ public class APITestServiceImpl implements APITestService {
|
|
|
result.append(line);
|
|
result.append(line);
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ log.error("GET api test request failed, url={}, params={}", url, params, e);
|
|
|
} finally {
|
|
} finally {
|
|
|
try {
|
|
try {
|
|
|
if (br != null)
|
|
if (br != null)
|
|
|
br.close();
|
|
br.close();
|
|
|
} catch (IOException ex) {
|
|
} catch (IOException ex) {
|
|
|
- ex.printStackTrace();
|
|
|
|
|
|
|
+ log.warn("Failed to close GET api test reader, url={}", url, ex);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
long end = System.currentTimeMillis();
|
|
long end = System.currentTimeMillis();
|
|
@@ -411,8 +414,7 @@ public class APITestServiceImpl implements APITestService {
|
|
|
// 断开连接
|
|
// 断开连接
|
|
|
conn.disconnect();
|
|
conn.disconnect();
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- System.out.println("发送 POST 请求出现异常!"+e);
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ log.error("POST api test request failed, url={}, params={}", url, params, e);
|
|
|
} finally{
|
|
} finally{
|
|
|
try{
|
|
try{
|
|
|
if(out!=null){
|
|
if(out!=null){
|
|
@@ -423,7 +425,7 @@ public class APITestServiceImpl implements APITestService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
catch(IOException ex){
|
|
catch(IOException ex){
|
|
|
- ex.printStackTrace();
|
|
|
|
|
|
|
+ log.warn("Failed to close POST api test resources, url={}", url, ex);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
long end = System.currentTimeMillis();
|
|
long end = System.currentTimeMillis();
|
|
@@ -446,19 +448,20 @@ public class APITestServiceImpl implements APITestService {
|
|
|
endGate.countDown();
|
|
endGate.countDown();
|
|
|
}
|
|
}
|
|
|
} catch (InterruptedException ie) {
|
|
} catch (InterruptedException ie) {
|
|
|
- ie.printStackTrace();
|
|
|
|
|
|
|
+ log.warn("API test worker interrupted", ie);
|
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
t.start();
|
|
t.start();
|
|
|
}
|
|
}
|
|
|
long startTime = System.nanoTime();
|
|
long startTime = System.nanoTime();
|
|
|
- System.out.println(startTime + " [" + Thread.currentThread() + "] All thread is ready, concurrent going...");
|
|
|
|
|
|
|
+ log.info("{} [{}] All thread is ready, concurrent going...", startTime, Thread.currentThread());
|
|
|
// 因开启门只需一个开关,所以立马就开启开始门
|
|
// 因开启门只需一个开关,所以立马就开启开始门
|
|
|
startGate.countDown();
|
|
startGate.countDown();
|
|
|
// 等等结束门开启
|
|
// 等等结束门开启
|
|
|
endGate.await();
|
|
endGate.await();
|
|
|
long endTime = System.nanoTime();
|
|
long endTime = System.nanoTime();
|
|
|
- System.out.println(endTime + " [" + Thread.currentThread() + "] All thread is completed.");
|
|
|
|
|
|
|
+ log.info("{} [{}] All thread is completed.", endTime, Thread.currentThread());
|
|
|
return endTime - startTime;
|
|
return endTime - startTime;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|