|
|
|
@ -0,0 +1,617 @@
|
|
|
|
|
package cn.estsh.i3plus.core.apiservice.controller.busi;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysLogSystemService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysToolService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ISystemResourceService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.ITestService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.*;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.platbean.SysLogSystem;
|
|
|
|
|
import cn.estsh.impp.framework.boot.eureka.EurekaClientHealthCheck;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.lang.reflect.Parameter;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description :
|
|
|
|
|
* @Reference :
|
|
|
|
|
* @Author : yunhao
|
|
|
|
|
* @CreateDate : 2019-02-19 11:29
|
|
|
|
|
* @Modify:
|
|
|
|
|
**/
|
|
|
|
|
@RestController
|
|
|
|
|
@Api(description = "IMPP性能测试")
|
|
|
|
|
@RequestMapping("/impp/white/sys-test")
|
|
|
|
|
public class TestController {
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger(TestController.class);
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysLogSystemService syslogSystemService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysToolService sysToolService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EntityManager entityManager;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
public ISystemResourceService systemResourceService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ITestService testService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EurekaClientHealthCheck healthCheck;
|
|
|
|
|
|
|
|
|
|
@Resource(name = "redisRes")
|
|
|
|
|
private ImppRedis redisRes;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 压力测试
|
|
|
|
|
*
|
|
|
|
|
* @param num 对象生成数量/π计算线程数
|
|
|
|
|
* @param cpu 是否进行cpu测试
|
|
|
|
|
* @param piLength π精确位数
|
|
|
|
|
* @param ram 是否进行内存测试
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/test-pressure")
|
|
|
|
|
@ApiOperation(value = "压力测试", notes = "压力测试")
|
|
|
|
|
public ResultBean testPressure(int num, boolean cpu, int piLength, boolean ram) {
|
|
|
|
|
try {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
//测试内存
|
|
|
|
|
if (ram) {
|
|
|
|
|
SysUser user;
|
|
|
|
|
SysDepartment sysDepartment;
|
|
|
|
|
List userList = new ArrayList();
|
|
|
|
|
List deptList = new ArrayList();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
|
// 生成部门计划
|
|
|
|
|
for (int j = 0; j < 10; j++) {
|
|
|
|
|
sysDepartment = new SysDepartment();
|
|
|
|
|
sysDepartment.setName("部门名称");
|
|
|
|
|
sysDepartment.setDepartmentCode("code");
|
|
|
|
|
sysDepartment.setDepartmentSort(j);
|
|
|
|
|
deptList.add(sysDepartment);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user = new SysUser();
|
|
|
|
|
user.setDepartmentList(deptList);
|
|
|
|
|
userList.add(user);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 测试cpu性能
|
|
|
|
|
if (cpu) {
|
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
|
TestThread th1 = new TestThread(piLength);
|
|
|
|
|
th1.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("查询成功").setResultObject("耗时:" + (System.currentTimeMillis() - time))
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据库操作测试
|
|
|
|
|
*
|
|
|
|
|
* @param num 操作数量
|
|
|
|
|
* @param insert 是否进行新增测试
|
|
|
|
|
* @param update 是否进行修改测试
|
|
|
|
|
* @param batchUpdate 是否批量修改
|
|
|
|
|
* @param delete 是否进行删除测试
|
|
|
|
|
* @param batchDelete 是否批量删除
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/test-db")
|
|
|
|
|
@ApiOperation(value = "数据库操作测试", notes = "数据库操作测试")
|
|
|
|
|
public ResultBean testDBCRUD(int num, boolean mongo, boolean insert, boolean update, boolean batchUpdate, boolean delete, boolean batchDelete,int waitTime) {
|
|
|
|
|
try {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
Pager page = new Pager();
|
|
|
|
|
page.setCurrentPage(1);
|
|
|
|
|
page.setPageSize(num);
|
|
|
|
|
List list;
|
|
|
|
|
SysTool sysTool;
|
|
|
|
|
SysLogSystem sysLogSystem;
|
|
|
|
|
|
|
|
|
|
long t1 = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
// 新增数据
|
|
|
|
|
if (insert) {
|
|
|
|
|
for (int i = 0; i < num * 1000; i++) {
|
|
|
|
|
t1 = System.currentTimeMillis();
|
|
|
|
|
if (!mongo) {
|
|
|
|
|
sysTool = new SysTool();
|
|
|
|
|
sysTool.setName("新增测试");
|
|
|
|
|
sysTool.setToolTypeId(1073140662133723136L);
|
|
|
|
|
sysTool.setToolIp("192.168.1.35");
|
|
|
|
|
sysTool.setToolPort(8888);
|
|
|
|
|
sysTool.setToolDescription("描述新增测试");
|
|
|
|
|
|
|
|
|
|
sysToolService.insertSysTool(sysTool);
|
|
|
|
|
|
|
|
|
|
this.wait(waitTime);
|
|
|
|
|
} else {
|
|
|
|
|
sysLogSystem = new SysLogSystem();
|
|
|
|
|
sysLogSystem.setLogClass("新增测试class");
|
|
|
|
|
sysLogSystem.setLogMethod("新增测试method");
|
|
|
|
|
sysLogSystem.setLogArgs("新增测试参数");
|
|
|
|
|
sysLogSystem.setExecuteTime(0L);
|
|
|
|
|
sysLogSystem.setArgsCount(1);
|
|
|
|
|
sysLogSystem.setLogDetail("2333");
|
|
|
|
|
sysLogSystem.setLogLevel(ImppEnumUtil.LOG_LEVEL.DEBUG.getValue());
|
|
|
|
|
sysLogSystem.setLogModuleId(CommonEnumUtil.SOFT_TYPE.CORE.getValue());
|
|
|
|
|
sysLogSystem.setLogTitle("新增测试");
|
|
|
|
|
|
|
|
|
|
syslogSystemService.insertSysLogSystem(sysLogSystem);
|
|
|
|
|
|
|
|
|
|
this.wait(waitTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGGER.info("插入耗时:" + (System.currentTimeMillis() - t1) + ",idx:" + i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (update || delete) {
|
|
|
|
|
// 查询批量修改或删除的数据
|
|
|
|
|
if(mongo){
|
|
|
|
|
list = syslogSystemService.querySysLogSystemByPager(null,page).getObjectList();
|
|
|
|
|
}else {
|
|
|
|
|
list = sysToolService.findSysToolByTop(num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否进行修改测试,并判断进行批量或逐次修改
|
|
|
|
|
if (!mongo && update && batchUpdate) {
|
|
|
|
|
Long[] ids = new Long[num];
|
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
|
ids[i] = ((SysTool) list.get(i)).getId();
|
|
|
|
|
}
|
|
|
|
|
sysToolService.updateSysToolStatusByIds(ids, CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
} else if (!mongo && update) {
|
|
|
|
|
for (Object obj : list) {
|
|
|
|
|
sysTool = (SysTool) obj;
|
|
|
|
|
sysTool.setName("修改测试"+System.currentTimeMillis());
|
|
|
|
|
sysTool.setToolTypeId(1073140662133723136L);
|
|
|
|
|
sysTool.setToolIp("192.168.1.35");
|
|
|
|
|
sysTool.setToolPort(8888);
|
|
|
|
|
sysTool.setToolDescription("描述修改测试"+System.currentTimeMillis());
|
|
|
|
|
|
|
|
|
|
sysToolService.updateSysTool(sysTool);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否进行删除测试,并判断进行批量或逐次删除
|
|
|
|
|
if (delete && batchDelete) {
|
|
|
|
|
Long[] ids = new Long[num];
|
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
|
if (mongo) {
|
|
|
|
|
ids[i] = ((SysLogSystem) list.get(i)).getId();
|
|
|
|
|
} else {
|
|
|
|
|
ids[i] = ((SysTool) list.get(i)).getId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (mongo) {
|
|
|
|
|
syslogSystemService.deleteSysLogSystemByIds(ids);
|
|
|
|
|
} else {
|
|
|
|
|
sysToolService.deleteSysToolByIds(ids);
|
|
|
|
|
}
|
|
|
|
|
} else if (delete) {
|
|
|
|
|
for (Object obj : list) {
|
|
|
|
|
if (mongo) {
|
|
|
|
|
sysLogSystem = (SysLogSystem) obj;
|
|
|
|
|
syslogSystemService.deleteSysLogSystemById(sysLogSystem.getId());
|
|
|
|
|
} else {
|
|
|
|
|
sysTool = (SysTool) obj;
|
|
|
|
|
sysToolService.deleteSysToolById(sysTool.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("调用完成-耗时:" + (System.currentTimeMillis() - time) + ",数据量:" + num)
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据库操作测试
|
|
|
|
|
*
|
|
|
|
|
* @param num 操作数量
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/data-insert")
|
|
|
|
|
@ApiOperation(value = "数据库造数据", notes = "数据库造数据")
|
|
|
|
|
public ResultBean dateInsert(int num,
|
|
|
|
|
boolean mongo,
|
|
|
|
|
int waitTime) {
|
|
|
|
|
try {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
SysTool sysTool;
|
|
|
|
|
SysLogSystem sysLogSystem;
|
|
|
|
|
long t1 = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
// 新增数据
|
|
|
|
|
if (!mongo) {
|
|
|
|
|
sysToolService.insertBatch(num,waitTime);
|
|
|
|
|
} else {
|
|
|
|
|
syslogSystemService.insertSysLogBatch(num,waitTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("调用完成-耗时:" + (System.currentTimeMillis() - time) + ",数据量:" + num)
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 缓存操作效率
|
|
|
|
|
*
|
|
|
|
|
* @param redisKey 缓存key
|
|
|
|
|
* @param num 操作数量
|
|
|
|
|
* @param batchPutCache 是否批量操作缓存
|
|
|
|
|
* @param putCache 是否进行放入缓存操作
|
|
|
|
|
* @param db 是否从数据库查询数据
|
|
|
|
|
* @param mongo 是否从mongodb查询数据
|
|
|
|
|
* @param cacheTime 缓存时间
|
|
|
|
|
* @param deleteCache 是否进行缓存删除操作
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/test-db-redis")
|
|
|
|
|
@ApiOperation(value = "缓存操作测试", notes = "数据库操作测试")
|
|
|
|
|
public ResultBean testDBRedis(String redisKey, int num, boolean batchPutCache, boolean putCache, boolean db, boolean mongo, int cacheTime, boolean deleteCache) {
|
|
|
|
|
try {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
List list = null;
|
|
|
|
|
|
|
|
|
|
// 是否放入缓存
|
|
|
|
|
if (putCache) {
|
|
|
|
|
// 是否需要从数据库中查询
|
|
|
|
|
if (db) {
|
|
|
|
|
Pager page = new Pager();
|
|
|
|
|
page.setCurrentPage(1);
|
|
|
|
|
page.setPageSize(num);
|
|
|
|
|
|
|
|
|
|
//是否对mongodb操作
|
|
|
|
|
if (mongo) {
|
|
|
|
|
list = sysToolService.findSysToolByTop(num);
|
|
|
|
|
} else {
|
|
|
|
|
list = syslogSystemService.querySysLogSystemByPager(null, page).getObjectList();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 缓存测试
|
|
|
|
|
list = new ArrayList();
|
|
|
|
|
SysTool sysTool;
|
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
|
sysTool = new SysTool();
|
|
|
|
|
sysTool.setName("缓存对象");
|
|
|
|
|
sysTool.setToolTypeId(1073141149285355520L);
|
|
|
|
|
sysTool.setToolIp("192.168.1.1");
|
|
|
|
|
sysTool.setToolPort(8080);
|
|
|
|
|
sysTool.setToolStatus(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
sysTool.setToolConnType(ImppEnumUtil.TOOL_CONN_TYPE.USB.getValue());
|
|
|
|
|
sysTool.setToolDataType(ImppEnumUtil.TOOL_DATA_TYPE.STRING.getValue());
|
|
|
|
|
sysTool.setToolDescription("描述");
|
|
|
|
|
|
|
|
|
|
list.add(sysTool);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 批量或是逐次放入缓存
|
|
|
|
|
if (batchPutCache) {
|
|
|
|
|
redisRes.putList(redisKey, list, cacheTime);
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
redisRes.putObject(redisKey + i, list.get(i), cacheTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deleteCache && batchPutCache) {
|
|
|
|
|
redisRes.deleteKey(redisKey);
|
|
|
|
|
} else if (deleteCache) {
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
redisRes.putObject(redisKey + i, list.get(i), cacheTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("调用完成-耗时:" + (System.currentTimeMillis() - time) + ",数据量:" + list.size())
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据库查询测试
|
|
|
|
|
*
|
|
|
|
|
* @param num 操作数据量
|
|
|
|
|
* @param mongo 是否使用mongodb
|
|
|
|
|
* @param needCache 是否使用缓存
|
|
|
|
|
* @param cacheTime 缓存时间
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/test-db-query")
|
|
|
|
|
@ApiOperation(value = "数据库查询测试", notes = "数据库查询测试")
|
|
|
|
|
public ResultBean testDBQuery(int num, boolean mongo, boolean needCache, int cacheTime) {
|
|
|
|
|
try {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
Pager page = new Pager();
|
|
|
|
|
page.setCurrentPage(1);
|
|
|
|
|
page.setPageSize(num);
|
|
|
|
|
List list;
|
|
|
|
|
|
|
|
|
|
// 是否放入缓存
|
|
|
|
|
if (needCache) {
|
|
|
|
|
// 是否使用mongodb
|
|
|
|
|
if (mongo) {
|
|
|
|
|
list = redisRes.getList(SysLogSystem.class.getSimpleName() + num, 0, num);
|
|
|
|
|
if (list == null || list.size() == 0) {
|
|
|
|
|
list = syslogSystemService.querySysLogSystemByPager(null, page).getObjectList();
|
|
|
|
|
redisRes.putList(SysLogSystem.class.getSimpleName() + num, list, cacheTime);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
list = redisRes.getList(SysTool.class.getSimpleName() + num, 0, num);
|
|
|
|
|
if (list == null || list.size() == 0) {
|
|
|
|
|
list = sysToolService.findSysToolByTop(num);
|
|
|
|
|
redisRes.putList(SysTool.class.getSimpleName() + num, list, cacheTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 是否使用mongodb
|
|
|
|
|
if (mongo) {
|
|
|
|
|
list = syslogSystemService.querySysLogSystemByPager(null, page).getObjectList();
|
|
|
|
|
} else {
|
|
|
|
|
list = sysToolService.findSysToolByTop(num);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("调用完成 耗时:" + (System.currentTimeMillis() - time) + ",数据量:" + list.size())
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 吞吐量测试
|
|
|
|
|
*
|
|
|
|
|
* @param num 对象数量
|
|
|
|
|
* @param objectLevel 对象等级 1.单对象,2.大对象,3.复杂对象
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/test-throughput")
|
|
|
|
|
@ApiOperation(value = "吞吐量测试", notes = "吞吐量测试")
|
|
|
|
|
public ResultBean testThroughput(int num, int objectLevel) {
|
|
|
|
|
try {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
List list = new ArrayList();
|
|
|
|
|
|
|
|
|
|
SysTool sysTool;
|
|
|
|
|
SessionUser sessionUser;
|
|
|
|
|
SysUser sysUser;
|
|
|
|
|
SysUserInfo sysUserInfo;
|
|
|
|
|
SysDepartment sysDept;
|
|
|
|
|
List<SysDepartment> deptList;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
|
switch (objectLevel) {
|
|
|
|
|
// 单对象
|
|
|
|
|
case 1:
|
|
|
|
|
sysTool = new SysTool();
|
|
|
|
|
sysTool.setName("单对象测试");
|
|
|
|
|
sysTool.setToolTypeId(1073141149285355520L);
|
|
|
|
|
sysTool.setToolIp("192.168.1.1");
|
|
|
|
|
sysTool.setToolPort(8080);
|
|
|
|
|
sysTool.setToolStatus(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
sysTool.setToolConnType(ImppEnumUtil.TOOL_CONN_TYPE.USB.getValue());
|
|
|
|
|
sysTool.setToolDataType(ImppEnumUtil.TOOL_DATA_TYPE.STRING.getValue());
|
|
|
|
|
sysTool.setToolDescription("描述");
|
|
|
|
|
|
|
|
|
|
list.add(sysTool);
|
|
|
|
|
break;
|
|
|
|
|
// 大对象
|
|
|
|
|
case 2:
|
|
|
|
|
deptList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < 300; j++) {
|
|
|
|
|
sysDept = new SysDepartment();
|
|
|
|
|
sysDept.setName("部门名称");
|
|
|
|
|
sysDept.setDepartmentCode("部门code");
|
|
|
|
|
sysDept.setParentNameRdd("上级部门名称");
|
|
|
|
|
|
|
|
|
|
deptList.add(sysDept);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sysUser = new SysUser();
|
|
|
|
|
sysUser.setUserName("用户名");
|
|
|
|
|
sysUser.setUserStatus(CommonEnumUtil.USER_STATUS.ENABLE.getValue());
|
|
|
|
|
sysUser.setUserLoginPassword("123456");
|
|
|
|
|
sysUser.setDepartmentId(1L);
|
|
|
|
|
sysUser.setOrganizeId(1L);
|
|
|
|
|
sysUser.setDepartmentNameRdd("部门名称");
|
|
|
|
|
sysUser.setOrganizeNameRdd("组织名称");
|
|
|
|
|
sysUser.setUserLoginNum(1);
|
|
|
|
|
sysUser.setDepartmentList(deptList);
|
|
|
|
|
|
|
|
|
|
list.add(sysUser);
|
|
|
|
|
break;
|
|
|
|
|
// 复杂对象
|
|
|
|
|
case 3:
|
|
|
|
|
deptList = new ArrayList<>();
|
|
|
|
|
sysDept = new SysDepartment();
|
|
|
|
|
sysDept.setName("部门名称");
|
|
|
|
|
sysDept.setDepartmentCode("部门code");
|
|
|
|
|
sysDept.setParentNameRdd("上级部门名称");
|
|
|
|
|
deptList.add(sysDept);
|
|
|
|
|
|
|
|
|
|
sysDept.setChildList(deptList);
|
|
|
|
|
|
|
|
|
|
sysUser = new SysUser();
|
|
|
|
|
sysUser.setUserName("用户名");
|
|
|
|
|
sysUser.setUserStatus(CommonEnumUtil.USER_STATUS.ENABLE.getValue());
|
|
|
|
|
sysUser.setUserLoginPassword("123456");
|
|
|
|
|
sysUser.setDepartmentId(1L);
|
|
|
|
|
sysUser.setOrganizeId(1L);
|
|
|
|
|
sysUser.setDepartmentNameRdd("部门名称");
|
|
|
|
|
sysUser.setOrganizeNameRdd("组织名称");
|
|
|
|
|
sysUser.setUserLoginNum(1);
|
|
|
|
|
sysUser.setDepartment(sysDept);
|
|
|
|
|
sysUser.setDepartmentList(deptList);
|
|
|
|
|
|
|
|
|
|
sysUserInfo = new SysUserInfo();
|
|
|
|
|
sysUserInfo.setName("yonghuming");
|
|
|
|
|
sysUserInfo.setOrganizeId(1L);
|
|
|
|
|
sysUserInfo.setPositionId(1L);
|
|
|
|
|
sysUserInfo.setDepartmentNameRdd("部门名称");
|
|
|
|
|
sysUserInfo.setOrganizeNameRdd("组织名称");
|
|
|
|
|
|
|
|
|
|
sessionUser = new SessionUser();
|
|
|
|
|
sessionUser.setUserName("用户名");
|
|
|
|
|
sessionUser.setLanguageCode("zh/CN");
|
|
|
|
|
sessionUser.setUserCode("10086");
|
|
|
|
|
sessionUser.setUserType("测试用户");
|
|
|
|
|
sessionUser.setUserId(1L);
|
|
|
|
|
sessionUser.setUser(sysUser);
|
|
|
|
|
sessionUser.setUserInfo(sysUserInfo);
|
|
|
|
|
|
|
|
|
|
list.add(sessionUser);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("调用完成-耗时:" + (System.currentTimeMillis() - time) + ",数量:" + list.size())
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultList(list);
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 可靠性测试
|
|
|
|
|
* @param needChangeHealth 是否需要修改健康状态
|
|
|
|
|
* @param serverHealth 设置微服务健康状态
|
|
|
|
|
* @param needSleep 是否需要线程睡眠
|
|
|
|
|
* @param sleepTime 睡眠时间ms
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/test-network")
|
|
|
|
|
@ApiOperation(value = "网络测试", notes = "网络测试")
|
|
|
|
|
public ResultBean testNetwork(boolean needChangeHealth,boolean serverHealth,boolean needSleep, int sleepTime) {
|
|
|
|
|
try {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
if(needChangeHealth){
|
|
|
|
|
healthCheck.setHealth(serverHealth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (needSleep) {
|
|
|
|
|
Thread.sleep(sleepTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("调用完成-耗时:" + (System.currentTimeMillis() - time))
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 多表查询
|
|
|
|
|
* @param num 查询数量
|
|
|
|
|
* @param needCache 是否使用缓存
|
|
|
|
|
* @param cacheTime 缓存时间
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/test-complex-query")
|
|
|
|
|
@ApiOperation(value = "多表查询", notes = "多表查询")
|
|
|
|
|
public ResultBean testComplexQuery(int num, boolean needCache, int cacheTime) {
|
|
|
|
|
try {
|
|
|
|
|
long time = System.currentTimeMillis();
|
|
|
|
|
Pager page = new Pager();
|
|
|
|
|
page.setCurrentPage(1);
|
|
|
|
|
page.setPageSize(num);
|
|
|
|
|
List list;
|
|
|
|
|
|
|
|
|
|
if (needCache) {
|
|
|
|
|
list = redisRes.getList(Object.class.getSimpleName() + num, 0, num);
|
|
|
|
|
if (list == null || list.size() == 0) {
|
|
|
|
|
list = testService.queryToolAndToolType(page);
|
|
|
|
|
redisRes.putList(SysTool.class.getSimpleName() + num, list, cacheTime);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
list = testService.queryToolAndToolType(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultBean.success("调用完成-耗时:" + (System.currentTimeMillis() - time) + ",数量:" + list.size())
|
|
|
|
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/test-gc")
|
|
|
|
|
@ApiOperation(value = "垃圾回收", notes = "垃圾回收")
|
|
|
|
|
public ResultBean gc() {
|
|
|
|
|
try {
|
|
|
|
|
System.gc();
|
|
|
|
|
return ResultBean.success("调用完成").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
|
|
|
|
} catch (ImppBusiException busExcep) {
|
|
|
|
|
return ResultBean.fail(busExcep);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|