Skip to content

Commit f7cb4cd

Browse files
committed
Java:MultiDataSource 解决录制重复的 Random 参数注入配置
1 parent 124293f commit f7cb4cd

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/java/apijson/boot/DemoController.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,7 @@ else if (names != null) {
17891789

17901790
JSONRequest request = new JSONRequest();
17911791
JSONRequest testRecord = new JSONRequest();
1792+
long randomId = 0;
17921793

17931794
if (documentId <= 0) {
17941795
if (isUnit) {
@@ -1819,10 +1820,10 @@ else if (recordType > 0) {
18191820
document.put("from", 2); // 0-测试工具,1-CI/CD,2-流量录制
18201821
document.put("name", "[Record] " + new java.util.Date().toLocaleString());
18211822
document.put("type", reqType);
1822-
document.put("method", method);
1823+
document.put("method", method == null ? "GET" : method.name());
18231824
document.put("url", branch);
18241825
document.put("header", StringUtil.isEmpty(hs, true) ? null : hs.trim());
1825-
document.put("request", isSQL ? "{}" : reqBody);
1826+
document.put("request", isSQL ? "{}" : (reqBody != null && ! reqBody.isEmpty() ? JSON.toJSONString(reqBody) : (StringUtil.isEmail(body) ? "{}" : body)));
18261827
if (isSQL) {
18271828
// 没有名称,除非 args 传对象而不是数组
18281829
// JSONList args = req.getJSONArray("args");
@@ -1850,12 +1851,24 @@ else if (recordType > 0) {
18501851
String config = isSQL ? hs : parseRandomConfig("", m);
18511852

18521853
JSONObject random = JSON.newJSONObject();
1853-
random.put("count", 1);
1854+
random.put("toId", 0);
1855+
random.put("chainId", 0);
18541856
random.put("documentId", documentId);
1857+
random.put("count", 1);
18551858
random.put("config", config.trim());
18561859
// Random >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
18571860

18581861
if (recordType > 0) {
1862+
try {
1863+
JSONObject randomReq = JSON.newJSONObject();
1864+
randomReq.put("Random", random);
1865+
JSONObject rsp = newParser(session, GET).setNeedVerify(false).parseResponse(randomReq);
1866+
JSONObject rsp2 = rsp == null ? null : rsp.getJSONObject("Random");
1867+
randomId = rsp2 == null ? 0 : rsp2.getLongValue("id");
1868+
} catch (Throwable e) {
1869+
e.printStackTrace();
1870+
}
1871+
18591872
random.put("from", 2); // 0-测试工具,1-CI/CD,2-流量录制
18601873
random.put("name", "[Record] " + new java.util.Date().toLocaleString());
18611874

@@ -1885,7 +1898,6 @@ else if (recordType > 0) {
18851898
testRecord.put("randomId", 0);
18861899
}
18871900
else {
1888-
long randomId = 0;
18891901
try {
18901902
JSONObject randomReq = JSON.newJSONObject();
18911903
randomReq.put("Random", random);
@@ -1918,7 +1930,7 @@ else if (recordType > 0) {
19181930
} // TestRecord >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
19191931

19201932
request.put("TestRecord", testRecord);
1921-
JSONObject rsp = newParser(session, recordType < 0 ? GET : POST)
1933+
JSONObject rsp = recordType > 0 && randomId > 0 ? null : newParser(session, recordType < 0 ? GET : POST)
19221934
.setNeedVerify(false).setNeedVerifyContent(true).parseResponse(request);
19231935
if (recordType < 0) {
19241936
JSONObject rsp2 = rsp == null ? null : rsp.getJSONObject("TestRecord");

0 commit comments

Comments
 (0)