Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
d5a4c22f
Commit
d5a4c22f
authored
May 05, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
表结构修改
parent
731fbd04
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
0 deletions
+94
-0
HttpHelperTest.java
yzg-util-base/src/test/java/helper/HttpHelperTest.java
+94
-0
No files found.
yzg-util-base/src/test/java/helper/HttpHelperTest.java
View file @
d5a4c22f
...
@@ -4,6 +4,7 @@ import com.yanzuoguang.util.helper.BaiduHelper;
...
@@ -4,6 +4,7 @@ import com.yanzuoguang.util.helper.BaiduHelper;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.helper.HttpHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
helper.vo.BaiduDate
;
import
helper.vo.BaiduDate
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -88,4 +89,97 @@ public class HttpHelperTest {
...
@@ -88,4 +89,97 @@ public class HttpHelperTest {
String
result
=
HttpHelper
.
post
(
"http://127.0.0.1:6903/test/wait/20000"
,
StringHelper
.
EMPTY
);
String
result
=
HttpHelper
.
post
(
"http://127.0.0.1:6903/test/wait/20000"
,
StringHelper
.
EMPTY
);
System
.
out
.
println
(
result
);
System
.
out
.
println
(
result
);
}
}
@Test
public
void
testHelper
()
throws
Exception
{
String
result
=
HttpHelper
.
post
(
"http://127.0.0.1:6903/test/wait/20000"
,
StringHelper
.
EMPTY
);
System
.
out
.
println
(
result
);
}
@Test
public
void
testThread
()
throws
Exception
{
int
maxThread
=
100
;
int
maxCount
=
100000
;
Request
req
=
new
Request
(
"http://10.150.2.3:6888/tbd_system/login/heart"
,
maxThread
,
maxCount
);
// Request req = new Request("http://127.0.0.1:6907/login/heart", maxThread, maxCount);
long
totalStart
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
req
.
thread
;
i
++)
{
ThreadHelper
.
runThread
(()
->
{
while
(
true
)
{
synchronized
(
req
)
{
if
(
req
.
start
<
req
.
max
)
{
req
.
start
++;
}
else
{
return
;
}
}
long
start
=
System
.
currentTimeMillis
();
boolean
isError
=
false
;
try
{
String
s
=
HttpHelper
.
get
(
req
.
url
);
}
catch
(
Exception
ex
)
{
isError
=
true
;
}
finally
{
long
end
=
System
.
currentTimeMillis
();
long
time
=
end
-
start
;
synchronized
(
req
)
{
req
.
maxTime
=
Math
.
max
(
time
,
req
.
maxTime
);
req
.
minTime
=
Math
.
max
(
time
,
req
.
maxTime
);
if
(
isError
)
{
req
.
error
++;
}
else
{
req
.
ok
++;
}
}
}
}
});
}
while
(
req
.
max
>
req
.
ok
+
req
.
error
)
{
ThreadHelper
.
sleep
(
100
);
System
.
out
.
println
(
req
);
}
long
totalEnd
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"总用时:"
+
(
totalEnd
-
totalStart
));
}
class
Request
{
String
url
;
int
thread
;
int
max
;
volatile
int
start
;
volatile
int
ok
;
volatile
int
error
;
volatile
long
maxTime
;
volatile
long
minTime
;
public
Request
(
String
url
,
int
thread
,
int
max
)
{
this
.
url
=
url
;
this
.
thread
=
thread
;
this
.
max
=
max
;
}
@Override
public
String
toString
()
{
return
"Request{"
+
"url='"
+
url
+
'\''
+
", thread="
+
thread
+
", max="
+
max
+
", start="
+
start
+
", ok="
+
ok
+
", error="
+
error
+
", maxTime="
+
maxTime
+
", minTime="
+
minTime
+
'}'
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment