修改测试程序支持maat回调类配置下发到redis中

This commit is contained in:
renkaige
2018-10-11 15:29:04 +08:00
parent 7208e1d830
commit bbf10f2438
2 changed files with 91 additions and 77 deletions

View File

@@ -84,27 +84,30 @@ public class MaatTestController {
FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "开始删除业务类型" + serviceType + "下的maat配置" + configId + "\n", FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "开始删除业务类型" + serviceType + "下的maat配置" + configId + "\n",
Configurations.getStringProperty("maatTestLogPath", ""), true); Configurations.getStringProperty("maatTestLogPath", ""), true);
// Map<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer, Map<Integer, List<Long>>>(); // Map<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer,
// Iterator<Integer> serviceIterator = compileMap.keySet().iterator(); // Map<Integer, List<Long>>>();
// while (serviceIterator.hasNext()) { // Iterator<Integer> serviceIterator = compileMap.keySet().iterator();
// Integer service = Integer.valueOf(serviceIterator.next().toString()); // while (serviceIterator.hasNext()) {
// List<Integer> dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service); // Integer service = Integer.valueOf(serviceIterator.next().toString());
// if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) { // List<Integer> dbIndexList =
// for (Integer dbIndex : dbIndexList) { // ServiceAndRDBIndexReal.getRedisDBByService(service);
// if (restMap.containsKey(dbIndex)) { // if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) {
// restMap.get(dbIndex).put(service, compileMap.get(service)); // for (Integer dbIndex : dbIndexList) {
// } else { // if (restMap.containsKey(dbIndex)) {
// Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>(); // restMap.get(dbIndex).put(service, compileMap.get(service));
// map.put(service, compileMap.get(service)); // } else {
// restMap.put(dbIndex, map); // Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>();
// } // map.put(service, compileMap.get(service));
// } // restMap.put(dbIndex, map);
// } else { // }
// FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "error:获取业务类型" + service + "对应的redisDb失败\n", // }
// Configurations.getStringProperty("maatTestLogPath", ""), true); // } else {
// return "error"; // FileUtils.addStrToFile(sdf.format(new Date()) + "\t" + "error:获取业务类型" +
// } // service + "对应的redisDb失败\n",
// } // Configurations.getStringProperty("maatTestLogPath", ""), true);
// return "error";
// }
// }
try { try {
if (!configRedisService.delMaatConfig(compileMap)) { if (!configRedisService.delMaatConfig(compileMap)) {
FileUtils.addStrToFile( FileUtils.addStrToFile(
@@ -153,7 +156,7 @@ public class MaatTestController {
configCompileList.add(getConfigCompile(ser)); configCompileList.add(getConfigCompile(ser));
} }
String jsonString = JsonMapper.toJsonString(configCompileList); String jsonString = JsonMapper.toJsonString(configCompileList);
FileUtils.addStrToFile("下发的json串是"+jsonString+"\n", FileUtils.addStrToFile("下发的json串是" + jsonString + "\n",
Configurations.getStringProperty("maatTestLogPath", ""), true); Configurations.getStringProperty("maatTestLogPath", ""), true);
// 保存测试配置 // 保存测试配置
configSourcesService.saveMaatConfig(thread, start, configCompileList, sb); configSourcesService.saveMaatConfig(thread, start, configCompileList, sb);
@@ -180,7 +183,7 @@ public class MaatTestController {
configCompileList.add(getConfigCompile(service)); configCompileList.add(getConfigCompile(service));
} }
String jsonString = JsonMapper.toJsonString(configCompileList); String jsonString = JsonMapper.toJsonString(configCompileList);
FileUtils.addStrToFile("下发的json串是"+jsonString+"\n", FileUtils.addStrToFile("下发的json串是" + jsonString + "\n",
Configurations.getStringProperty("maatTestLogPath", ""), true); Configurations.getStringProperty("maatTestLogPath", ""), true);
// 保存测试配置 // 保存测试配置
configSourcesService.saveMaatConfig(thread, start, configCompileList, sb); configSourcesService.saveMaatConfig(thread, start, configCompileList, sb);
@@ -260,11 +263,11 @@ public class MaatTestController {
List<NumRegion> numList = new ArrayList<NumRegion>(); List<NumRegion> numList = new ArrayList<NumRegion>();
List<StrRegion> strList = new ArrayList<StrRegion>(); List<StrRegion> strList = new ArrayList<StrRegion>();
List<DigestRegion> digestList = new ArrayList<DigestRegion>(); List<DigestRegion> digestList = new ArrayList<DigestRegion>();
// configCompile.setIpRegionList(ipList); // configCompile.setIpRegionList(ipList);
// configCompile.setNumRegionList(numList); // configCompile.setNumRegionList(numList);
// configCompile.setStrRegionList(strList); // configCompile.setStrRegionList(strList);
// configCompile.setDigestRegionList(digestList); // configCompile.setDigestRegionList(digestList);
// configCompile.setIpClientRangeList(ipList); // configCompile.setIpClientRangeList(ipList);
if (tableType == 12 || tableType == 18) { if (tableType == 12 || tableType == 18) {
ipList = new ArrayList<IpRegion>(); ipList = new ArrayList<IpRegion>();
if (tableNameArr.length == 1) { if (tableNameArr.length == 1) {
@@ -381,9 +384,9 @@ public class MaatTestController {
strRegion.setGroupId(groupId); strRegion.setGroupId(groupId);
strRegion.setRegionId(configRedisService.getIncrId("SEQ_REGIONID")); strRegion.setRegionId(configRedisService.getIncrId("SEQ_REGIONID"));
strRegion.setTableName(ServiceAndRDBIndexReal.getMaatTableName(service, type, tableName)); strRegion.setTableName(ServiceAndRDBIndexReal.getMaatTableName(service, type, tableName));
if(type==15) { if (type == 15) {
strRegion.setDistrict("增强字符串测试groupid"+groupId); strRegion.setDistrict("增强字符串测试groupid" + groupId);
}else { } else {
strRegion.setDistrict(""); strRegion.setDistrict("");
} }
strRegion.setKeywords("keywords,UUID:" + UUID.randomUUID()); strRegion.setKeywords("keywords,UUID:" + UUID.randomUUID());
@@ -522,6 +525,7 @@ public class MaatTestController {
/** /**
* 组装json串,然后下发配置,在验证配置是否正确,然后删除配置 * 组装json串,然后下发配置,在验证配置是否正确,然后删除配置
*
* @param service * @param service
* @param saveCount * @param saveCount
* @param map * @param map
@@ -536,62 +540,72 @@ public class MaatTestController {
jsonString.append("["); jsonString.append("[");
for (int i = 0; i < saveCount; i++) { for (int i = 0; i < saveCount; i++) {
jsonString.append("{"); jsonString.append("{");
List<String> srcList = new ArrayList<String>();
for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) { for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) {
String fieldType = commonSourceFieldCfg.getFieldType(); String fieldType = commonSourceFieldCfg.getFieldType();
String srcName = commonSourceFieldCfg.getSrcName(); String srcName = commonSourceFieldCfg.getSrcName();
jsonString.append("\""); String dstName = commonSourceFieldCfg.getDstName();
jsonString.append(srcName); if (!srcList.contains(srcName)) {
jsonString.append("\":"); jsonString.append("\"");
if (fieldType.equals("String")) { jsonString.append(srcName);
if (srcName.toLowerCase().equals("service")) { jsonString.append("\":");
jsonString.append("\"" + service + "\""); if (fieldType.equals("String")) {
} else if (srcName.toLowerCase().equals("dstfile")) { if (srcName.toLowerCase().equals("service")) {
jsonString.append( jsonString.append("\"" + service + "\"");
"\"http://10.0.6.249/group1/M00/00/02/CgAG-VtziqWAIzafAAITEbfJ8Zw992.jpg\""); // } else if (dstName.toLowerCase().contains("redisfile")) {
} else { // jsonString.append(
jsonString.append("\"" + UUID.randomUUID() + "\""); // "\"http://192.168.10.205:9000/maat-redis/201810284141049-212b64ca-5b5d-4b13-873e-c57868b4b46b.jpg\"");
}
} else if (fieldType.equals("Number")) {
if (srcName.toLowerCase().equals("addrtype")) {
jsonString.append("4");
} else if (srcName.toLowerCase().equals("action")) {
jsonString.append(ServiceAndRDBIndexReal.getActionByService(service));
} else if (srcName.toLowerCase().equals("protocol")) {
jsonString.append("0");
} else if (srcName.toLowerCase().equals("direction")) {
jsonString.append("0");
} else if (srcName.toLowerCase().equals("location")) {
jsonString.append("1");
} else if (srcName.toLowerCase().equals("isvalid")) {
jsonString.append("1");
} else if (srcName.toLowerCase().equals("cfgid")||srcName.toLowerCase().equals("keyringid")||srcName.toLowerCase().equals("fileid")) {
Long incrId = configRedisService.getIncrId("seq_compileid");
compileIdList.add(incrId);
jsonString.append(incrId);
} else {
if (commonSourceFieldCfg.getDefaultVal() != null) {
jsonString.append(commonSourceFieldCfg.getDefaultVal());
} else { } else {
jsonString.append(System.currentTimeMillis()); // jsonString.append("\"" + UUID.randomUUID() + "\"");
jsonString.append(
"\"http://192.168.10.205:9000/maat-redis/201810284141049-212b64ca-5b5d-4b13-873e-c57868b4b46b.jpg\"");
} }
} else if (fieldType.equals("Number")) {
if (srcName.toLowerCase().equals("addrtype")) {
jsonString.append("4");
} else if (srcName.toLowerCase().equals("action")) {
jsonString.append(ServiceAndRDBIndexReal.getActionByService(service));
} else if (srcName.toLowerCase().equals("protocol")) {
jsonString.append("0");
} else if (srcName.toLowerCase().equals("direction")) {
jsonString.append("0");
} else if (srcName.toLowerCase().equals("location")) {
jsonString.append("1");
} else if (srcName.toLowerCase().equals("isvalid")) {
jsonString.append("1");
} else if (srcName.toLowerCase().equals("cfgid")
|| srcName.toLowerCase().equals("keyringid")
|| srcName.toLowerCase().equals("fileid")) {
Long incrId = configRedisService.getIncrId("seq_compileid");
compileIdList.add(incrId);
jsonString.append(incrId);
} else {
if (commonSourceFieldCfg.getDefaultVal() != null) {
jsonString.append(commonSourceFieldCfg.getDefaultVal());
} else {
jsonString.append(System.currentTimeMillis());
}
}
} else if (fieldType.equals("IP")) {
if (srcName.toLowerCase().equals("srcip")) {
jsonString.append("\"1.1.1.1\"");
} else {
jsonString.append("\"2.2.2.2\"");
}
} else if (fieldType.equals("Port")) {
jsonString.append("\"80\"");
} else if (fieldType.equals("Date")) {
jsonString.append("\"" + sdf.format(new Date()) + "\"");
} }
} else if (fieldType.equals("IP")) { jsonString.append(",");
if (srcName.toLowerCase().equals("srcip")) {
jsonString.append("\"1.1.1.1\"");
} else {
jsonString.append("\"2.2.2.2\"");
}
} else if (fieldType.equals("Port")) {
jsonString.append("\"80\"");
} else if (fieldType.equals("Date")) {
jsonString.append("\"" + sdf.format(new Date()) + "\"");
} }
jsonString.append(","); srcList.add(srcName);
} }
String str = jsonString.substring(0, jsonString.lastIndexOf(",")); String str = jsonString.substring(0, jsonString.lastIndexOf(","));
jsonString.setLength(0); jsonString.setLength(0);
jsonString.append(str); jsonString.append(str);
jsonString.append("},"); jsonString.append("},");
} }
String jsonStr = jsonString.substring(0, jsonString.lastIndexOf(",")); String jsonStr = jsonString.substring(0, jsonString.lastIndexOf(","));
jsonStr += "]"; jsonStr += "]";

View File

@@ -386,7 +386,7 @@ public class MaatTestServiceimpl {
maatTableName.substring(maatTableName.lastIndexOf("_") + 1)); maatTableName.substring(maatTableName.lastIndexOf("_") + 1));
dstStr = dstPath.replace("{fileName}", dstStr.substring(dstStr.lastIndexOf("/") + 1)); dstStr = dstPath.replace("{fileName}", dstStr.substring(dstStr.lastIndexOf("/") + 1));
} else if ("file_id".equals(commonSourceFieldCfg.getDstName())) { } else if ("file_id".equals(commonSourceFieldCfg.getDstName())) {
dstStr = dstStr.substring(dstStr.indexOf("group")); // dstStr = dstStr.substring(dstStr.indexOf("group"));
} }
} }
switch (commonSourceFieldCfg.getFieldType()) { switch (commonSourceFieldCfg.getFieldType()) {
@@ -562,7 +562,7 @@ public class MaatTestServiceimpl {
if (!isNum(attrName)) { if (!isNum(attrName)) {
String beanVal = map.get(attrName); String beanVal = map.get(attrName);
String redisVal = valArr[i]; String redisVal = valArr[i];
if (beanVal == null || redisVal == null || !beanVal.trim().equals(redisVal.trim())) { if (!attrName.contains("redisFile")&&(beanVal == null || redisVal == null || !beanVal.trim().equals(redisVal.trim()))) {
FileUtils.addStrToFile( FileUtils.addStrToFile(
"\t" + sdf.format(new Date()) + " error:" + redisDb + "号redis库中key=" + key + "的值第" + i "\t" + sdf.format(new Date()) + " error:" + redisDb + "号redis库中key=" + key + "的值第" + i
+ "" + attrName + "的值:" + redisVal + "与实际传的值不一样,实际值是:{}\n", + "" + attrName + "的值:" + redisVal + "与实际传的值不一样,实际值是:{}\n",