Skip to content

Commit a02c8ad

Browse files
committed
Java: MultiDataSource 解决改 APIJSON 相关类泛型误改了 UnitAuto, SQLAuto, UIGO 源码的
1 parent 6c01da6 commit a02c8ad

File tree

15 files changed

+277
-94
lines changed

15 files changed

+277
-94
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/sql/js/jquery.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ jQuery.extend({
521521
parseJSON: function( data ) {
522522
// Attempt to parse using the native JSON parser first
523523
if ( window.JSON && window.JSON.parse ) {
524-
return window.parseJSON( data );
524+
return window.JSON.parse( data );
525525
}
526526

527527
if ( data === null ) {
@@ -555,7 +555,7 @@ jQuery.extend({
555555
return null;
556556
}
557557
try {
558-
if ( window.DOMParser<T, M, L> ) { // Standard
558+
if ( window.DOMParser ) { // Standard
559559
tmp = new DOMParser();
560560
xml = tmp.parseFromString( data , "text/xml" );
561561
} else { // IE

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/sql/js/localforage.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/sql/js/server.js

+37-41
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const Koa = require('koa');
22
//const cors = require('koa2-cors');
3-
//const bodyParser<T, M, L> = require('koa-bodyparser');
4-
3+
const bodyParser = require('koa-bodyparser');
54
// const Vue = require('vue');
65
const {getRequestFromURL, App} = require('./main');
76
// const { createBundleRenderer } = require('vue-server-renderer')
@@ -66,25 +65,11 @@ function update() {
6665
+ '\nRandom & Order: ' + App.randomDoneCount + ' / ' + App.randomAllCount + ' = ' + (100*randomProgress) + '%';
6766
};
6867

69-
const PORT = 3002;
70-
71-
const app = new Koa();
72-
73-
//app.use(cors({
74-
// origin: function(ctx) {
75-
// return '*';
76-
// },
77-
// maxAge: 5,
78-
// credentials: true,
79-
// allowMethods: ['GET', 'HEAD ', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
80-
// allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
81-
// exposeHeaders: ['WWW-Authenticate', 'Server-Authorization']
82-
//}));
83-
84-
//app.use(bodyParser());
68+
const PORT = 3000;
8569

8670
var done = false;
87-
71+
const app = new Koa();
72+
// app.use(bodyParser());
8873
app.use(async ctx => {
8974
console.log(ctx);
9075
var origin = ctx.get('Origin') || ctx.get('origin');
@@ -147,7 +132,10 @@ app.use(async ctx => {
147132
isCrossEnabled = App.isCrossEnabled;
148133

149134
ctx.status = ctx.response.status = 200; // 302;
150-
ctx.body = ctx.response.body = 'Auto testing in node...';
135+
ctx.body = ctx.response.body = JSON.stringify({
136+
'code': 200,
137+
'msg': 'Auto testing in node...'
138+
});
151139

152140
// setTimeout(function () { // 延迟无效
153141
ctx.redirect('/test/status');
@@ -160,43 +148,51 @@ app.use(async ctx => {
160148
// ctx.redirect('/status');
161149
}
162150

151+
var server = App.server;
152+
var ind = server == null ? -1 : server.indexOf('?');
153+
163154
ctx.status = ctx.response.status = 200; // progress >= 1 ? 200 : 302;
164-
ctx.body = ctx.response.body = (message || (progress < 1 || isLoading ? 'Auto testing in node...' : 'Done auto testing in node.')) + timeMsg + progressMsg;
155+
ctx.body = ctx.response.body = JSON.stringify({
156+
'code': 200,
157+
'msg': (message || (progress < 1 || isLoading ? 'Auto testing in node...' : 'Done auto testing in node.')) + timeMsg + progressMsg,
158+
'progress': progress,
159+
'reportId': App.reportId,
160+
'link': server + (ind < 0 ? '?' : '&') + 'reportId=' + App.reportId
161+
});
165162
}
166163
else if (ctx.path == '/test/compare' || ctx.path == '/test/ml') {
167164
done = false;
168-
var json = '';
169-
ctx.req.addListener('data', (data) => {
170-
json += data;
171-
})
172-
ctx.req.addListener('end', function() {
173-
console.log(json);
165+
// var json = '';
166+
// ctx.req.addListener('data', (data) => {
167+
// json += data;
174168
// })
175-
176-
var body = parseJSON(json) || ctx.body || ctx.req.body || ctx.request.body || {};
169+
// ctx.req.addListener('end', function() {
170+
// console.log(json);
171+
var body = ctx.body || ctx.req.body || ctx.request.body || {} // || JSON.parse(json) || {};
177172
console.log(body);
178173
var isML = ctx.path == '/test/ml' || body.isML;
179174
var res = body.response;
180175
var stdd = body.standard;
181-
182-
var response = typeof res != 'string' ? res : (StringUtil.isEmpty(res, true) ? null : parseJSON(res));
183-
var standard = typeof stdd != 'string' ? stdd : (StringUtil.isEmpty(stdd, true) ? null : parseJSON(stdd));
184-
176+
var response = typeof res != 'string' ? res : (StringUtil.isEmpty(res, true) ? null : JSON.parse(res));
177+
var standard = typeof stdd != 'string' ? stdd : (StringUtil.isEmpty(stdd, true) ? null : JSON.parse(stdd));
185178
console.log('\n\nresponse = ' + JSON.stringify(response));
186179
console.log('\n\nstdd = ' + JSON.stringify(stdd));
187-
var compare = JSONResponse.compareResponse(standard, response || {}, '', isML, null, null, false) || {}
180+
var compare = JSONResponse.compareResponse(null, standard, response || {}, '', isML, null, null, false) || {}
181+
182+
if (body.newStandard) {
183+
compare.newStandard = JSONResponse.updateFullStandard(standard, response, isML)
184+
}
188185
console.log('\n\ncompare = ' + JSON.stringify(compare));
189186

190187
ctx.status = ctx.response.status = 200;
191188
ctx.body = ctx.response.body = compare == null ? '' : JSON.stringify(compare);
192189
done = true;
193-
})
194-
195-
while (true) {
196-
if (done) {
197-
break;
198-
}
199-
}
190+
// })
191+
// while (true) {
192+
// if (done) {
193+
// break;
194+
// }
195+
// }
200196
}
201197
});
202198

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/sql/md/lib/codemirror/mode/rust/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h2>Rust mode</h2>
2929
<div><textarea id="code" name="code">
3030
// Demo code.
3131

32-
type foo<T, M, L> = int;
32+
type foo<T> = int;
3333
enum bar {
3434
some(int, foo<float>),
3535
none

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/sql/md/lib/jquery.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/ui/js/jquery.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ jQuery.extend({
521521
parseJSON: function( data ) {
522522
// Attempt to parse using the native JSON parser first
523523
if ( window.JSON && window.JSON.parse ) {
524-
return window.parseJSON( data );
524+
return window.JSON.parse( data );
525525
}
526526

527527
if ( data === null ) {
@@ -555,7 +555,7 @@ jQuery.extend({
555555
return null;
556556
}
557557
try {
558-
if ( window.DOMParser<T, M, L> ) { // Standard
558+
if ( window.DOMParser ) { // Standard
559559
tmp = new DOMParser();
560560
xml = tmp.parseFromString( data , "text/xml" );
561561
} else { // IE

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/ui/js/localforage.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
const Koa = require('koa');
2+
//const cors = require('koa2-cors');
3+
const bodyParser = require('koa-bodyparser');
4+
// const Vue = require('vue');
5+
const {getRequestFromURL, App} = require('./main');
6+
// const { createBundleRenderer } = require('vue-server-renderer')
7+
8+
const JSONResponse = require('../apijson/JSONResponse');
9+
const StringUtil = require('../apijson/StringUtil');
10+
11+
var isCrossEnabled = true; // false;
12+
var isLoading = false;
13+
var startTime = 0;
14+
var endTime = 0;
15+
var message = '';
16+
var error = null;
17+
var timeMsg = '';
18+
var progressMsg = '';
19+
20+
var progress = 0;
21+
var accountProgress = 0;
22+
var testCaseProgress = 0;
23+
var deepProgress = 0;
24+
var randomProgress = 0;
25+
26+
function update() {
27+
if (isLoading != true) {
28+
return;
29+
}
30+
31+
if (error != null) {
32+
isLoading = false;
33+
}
34+
35+
var curTime = isLoading ? (new Date()).getTime() : null;
36+
if (endTime <= 0 || isLoading) {
37+
endTime = curTime;
38+
}
39+
var duration = endTime - startTime;
40+
var dd = new Date(duration + 60000*(new Date().getTimezoneOffset()));
41+
42+
timeMsg = '\n\nStart Time: ' + startTime + ' = ' + new Date(startTime).toLocaleString()
43+
+ (isLoading ? '; \nCurrent' : '\nEnd') + ' Time: ' + endTime + ' = ' + new Date(endTime).toLocaleString()
44+
+ '; \nTime Spent: ' + duration + ' = ' + dd.getHours() + ":" + dd.getMinutes() + ":" + dd.getSeconds() + "." + dd.getMilliseconds();
45+
46+
var accountDoneCount = App.currentAccountIndex + 1;
47+
var accountAllCount = App.accounts.length;
48+
49+
accountProgress = isCrossEnabled != true || accountAllCount <= 0 || accountDoneCount >= accountAllCount ? 1 : (accountDoneCount/accountAllCount).toFixed(2);
50+
testCaseProgress = App.doneCount >= App.allCount ? 1 : (App.doneCount/App.allCount).toFixed(2);
51+
deepProgress = App.deepDoneCount >= App.deepAllCount ? 1 : (App.deepDoneCount/App.deepAllCount).toFixed(2);
52+
randomProgress = App.randomDoneCount >= App.randomAllCount ? 1 : (App.randomDoneCount/App.randomAllCount).toFixed(2);
53+
// progress = accountProgress*testCaseProgress*deepProgress*randomProgress;
54+
progress = accountProgress >= 1 ? 1 : (accountProgress + (accountAllCount <= 0 ? 1 : 1/accountAllCount*(testCaseProgress
55+
+ (App.allCount <= 0 ? 1 : 1/App.allCount*(deepProgress + (App.deepAllCount <= 0 ? 1 : 1/App.deepAllCount*randomProgress))))));
56+
57+
if (progress >= 1) {
58+
isLoading = false;
59+
}
60+
61+
progressMsg = '\n\nProgress: ' + (100*progress) + '%'
62+
+ '\nTest Account: ' + accountDoneCount + ' / ' + accountAllCount + ' = ' + (100*accountProgress) + '%'
63+
+ '\nTest Case: ' + App.doneCount + ' / ' + App.allCount + ' = ' + (100*testCaseProgress) + '%'
64+
+ '\nDeep Test Case: ' + App.deepDoneCount + ' / ' + App.deepAllCount + ' = ' + (100*deepProgress) + '%'
65+
+ '\nRandom & Order: ' + App.randomDoneCount + ' / ' + App.randomAllCount + ' = ' + (100*randomProgress) + '%';
66+
};
67+
68+
const PORT = 3000;
69+
70+
var done = false;
71+
const app = new Koa();
72+
// app.use(bodyParser());
73+
app.use(async ctx => {
74+
console.log(ctx);
75+
var origin = ctx.get('Origin') || ctx.get('origin');
76+
console.log('origin = ' + origin);
77+
ctx.set('Access-Control-Max-Age', "1000000"); // "-1");
78+
ctx.set('Access-Control-Allow-Origin', origin);
79+
ctx.set('Access-Control-Allow-Headers', "*");
80+
ctx.set('Access-Control-Allow-Credentials', 'true');
81+
ctx.set('Access-Control-Allow-Methods', 'GET,HEAD,POST,PUT,DELETE,OPTIONS,TRACE');
82+
// ctx.set('Access-Control-Expose-Headers', "*");
83+
84+
if (ctx.method == null || ctx.method.toUpperCase() == 'OPTIONS') {
85+
ctx.status = 200;
86+
return;
87+
}
88+
89+
if (ctx.path == '/test/start' || (isLoading != true && ctx.path == '/test')) {
90+
if (isLoading && ctx.path == '/test/start') {
91+
ctx.status = 200;
92+
ctx.body = ctx.response.body = 'Already started auto testing in node, please wait for minutes...';
93+
return;
94+
}
95+
96+
App.isCrossEnabled = isCrossEnabled; // isCrossEnabled = App.isCrossEnabled;
97+
if (isCrossEnabled) {
98+
App.currentAccountIndex = -1;
99+
}
100+
101+
isLoading = true;
102+
startTime = (new Date()).getTime();
103+
endTime = startTime;
104+
message = '';
105+
error = null;
106+
timeMsg = '';
107+
progressMsg = '';
108+
109+
progress = 0;
110+
accountProgress = 0;
111+
testCaseProgress = 0;
112+
deepProgress = 0;
113+
randomProgress = 0;
114+
115+
update();
116+
117+
App.key = ctx.query.key;
118+
if (StringUtil.isNotEmpty(App.key, true)) {
119+
App.testCaseCount = App.data.testCaseCount = 1000;
120+
App.randomCount = App.data.randomCount = 200;
121+
App.randomSubCount = App.data.randomSubCount = 500;
122+
}
123+
124+
App.autoTest(function (msg, err) {
125+
message = msg;
126+
error = err;
127+
update();
128+
console.log('autoTest callback(' + msg + ')' + timeMsg + progressMsg);
129+
return Number.isNaN(progress) != true && progress >= 1;
130+
});
131+
isLoading = true;
132+
isCrossEnabled = App.isCrossEnabled;
133+
134+
ctx.status = ctx.response.status = 200; // 302;
135+
ctx.body = ctx.response.body = JSON.stringify({
136+
'code': 200,
137+
'msg': 'Auto testing in node...'
138+
});
139+
140+
// setTimeout(function () { // 延迟无效
141+
ctx.redirect('/test/status');
142+
// }, 1000)
143+
}
144+
else if (ctx.path == '/test/status' || (isLoading && ctx.path == '/test')) {
145+
update();
146+
if (isLoading) {
147+
// ctx.response.header['refresh'] = "1";
148+
// ctx.redirect('/status');
149+
}
150+
151+
var server = App.server;
152+
var ind = server == null ? -1 : server.indexOf('?');
153+
154+
ctx.status = ctx.response.status = 200; // progress >= 1 ? 200 : 302;
155+
ctx.body = ctx.response.body = JSON.stringify({
156+
'code': 200,
157+
'msg': (message || (progress < 1 || isLoading ? 'Auto testing in node...' : 'Done auto testing in node.')) + timeMsg + progressMsg,
158+
'progress': progress,
159+
'reportId': App.reportId,
160+
'link': server + (ind < 0 ? '?' : '&') + 'reportId=' + App.reportId
161+
});
162+
}
163+
else if (ctx.path == '/test/compare' || ctx.path == '/test/ml') {
164+
done = false;
165+
// var json = '';
166+
// ctx.req.addListener('data', (data) => {
167+
// json += data;
168+
// })
169+
// ctx.req.addListener('end', function() {
170+
// console.log(json);
171+
var body = ctx.body || ctx.req.body || ctx.request.body || {} // || JSON.parse(json) || {};
172+
console.log(body);
173+
var isML = ctx.path == '/test/ml' || body.isML;
174+
var res = body.response;
175+
var stdd = body.standard;
176+
var response = typeof res != 'string' ? res : (StringUtil.isEmpty(res, true) ? null : JSON.parse(res));
177+
var standard = typeof stdd != 'string' ? stdd : (StringUtil.isEmpty(stdd, true) ? null : JSON.parse(stdd));
178+
console.log('\n\nresponse = ' + JSON.stringify(response));
179+
console.log('\n\nstdd = ' + JSON.stringify(stdd));
180+
var compare = JSONResponse.compareResponse(null, standard, response || {}, '', isML, null, null, false) || {}
181+
182+
if (body.newStandard) {
183+
compare.newStandard = JSONResponse.updateFullStandard(standard, response, isML)
184+
}
185+
console.log('\n\ncompare = ' + JSON.stringify(compare));
186+
187+
ctx.status = ctx.response.status = 200;
188+
ctx.body = ctx.response.body = compare == null ? '' : JSON.stringify(compare);
189+
done = true;
190+
// })
191+
// while (true) {
192+
// if (done) {
193+
// break;
194+
// }
195+
// }
196+
}
197+
});
198+
199+
app.listen(PORT);
200+
201+
console.log(`已启动 Node HTTP 服务,可以
202+
GET http://localhost:${PORT}/test/start
203+
来启动后台回归测试,或者
204+
GET http://localhost:${PORT}/test/status
205+
来查询测试进度。`);

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/ui/md/lib/codemirror/mode/rust/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h2>Rust mode</h2>
2929
<div><textarea id="code" name="code">
3030
// Demo code.
3131

32-
type foo<T, M, L> = int;
32+
type foo<T> = int;
3333
enum bar {
3434
some(int, foo<float>),
3535
none

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/ui/md/lib/jquery.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)