Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-demo-single
Overview
Overview
Details
Activity
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
gic_demo
gic-demo-single
Commits
8e909349
Commit
8e909349
authored
Jul 19, 2019
by
朱瑞泽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
a818dd1b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
15 deletions
+120
-15
MySQLTestIntercepter.java
...c/main/java/com/gic/demo/single/MySQLTestIntercepter.java
+53
-0
TestRun.java
...le-service/src/main/java/com/gic/demo/single/TestRun.java
+62
-10
jdbc-gic-demo-service.xml
...ngle-service/src/main/resources/jdbc-gic-demo-service.xml
+5
-5
No files found.
gic-demo-single-service/src/main/java/com/gic/demo/single/MySQLTestIntercepter.java
0 → 100644
View file @
8e909349
package
com
.
gic
.
demo
.
single
;
import
com.mysql.jdbc.Connection
;
import
com.mysql.jdbc.ResultSetInternalMethods
;
import
com.mysql.jdbc.Statement
;
import
com.mysql.jdbc.StatementInterceptorV2
;
import
java.sql.SQLException
;
import
java.util.Properties
;
/**
* @author zhurz
*/
public
class
MySQLTestIntercepter
implements
StatementInterceptorV2
{
private
void
println
(
String
method
,
String
argName
,
Object
argVal
)
{
System
.
out
.
println
(
String
.
format
(
"%s -> %s %s:%s"
,
Thread
.
currentThread
(),
method
,
argName
,
argVal
));
}
@Override
public
void
init
(
Connection
conn
,
Properties
props
)
throws
SQLException
{
// println("init", "conn", conn);
// println("init", "props", props);
}
@Override
public
ResultSetInternalMethods
preProcess
(
String
sql
,
Statement
interceptedStatement
,
Connection
connection
)
throws
SQLException
{
// println("preProcess", "sql", sql);
// println("preProcess", "interceptedStatement", interceptedStatement);
// println("preProcess", "isReadOnly", connection.isReadOnly());
return
null
;
}
@Override
public
boolean
executeTopLevelOnly
()
{
return
false
;
}
@Override
public
void
destroy
()
{
}
@Override
public
ResultSetInternalMethods
postProcess
(
String
sql
,
Statement
interceptedStatement
,
ResultSetInternalMethods
originalResultSet
,
Connection
connection
,
int
warningCount
,
boolean
noIndexUsed
,
boolean
noGoodIndexUsed
,
SQLException
statementException
)
throws
SQLException
{
// println("postProcess", "sql", sql);
// println("postProcess", "interceptedStatement", interceptedStatement);
// println("postProcess", "isReadOnly", connection.isReadOnly());
return
null
;
}
}
gic-demo-single-service/src/main/java/com/gic/demo/single/TestRun.java
View file @
8e909349
...
...
@@ -23,9 +23,9 @@ public class TestRun {
@Value
(
"${jdbc.maxsize}"
)
private
Integer
jdbcMaxsize
;
public
void
test
(
Consumer
<
String
>
consumer
)
throws
InterruptedException
{
int
maxThreadSize
=
100
;
int
size
=
100000
;
public
void
test
1
(
Consumer
<
String
>
consumer
,
int
maxThreadSize
,
int
size
)
throws
InterruptedException
{
//
int maxThreadSize = 100;
//
int size = 100000;
ExecutorService
exec
=
Executors
.
newFixedThreadPool
(
maxThreadSize
);
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
size
);
long
begin
=
System
.
currentTimeMillis
();
...
...
@@ -50,6 +50,7 @@ public class TestRun {
cost
,
size
/
cost
);
exec
.
shutdown
();
}
public
void
test2
(
DemoStoreService
demoStoreService
)
{
...
...
@@ -61,6 +62,31 @@ public class TestRun {
demoStoreService
.
test3
(
"789"
);
}
public
void
test3
(
DemoStoreService
demoStoreService
,
int
maxThreadSize
,
int
size
,
int
choose
)
throws
InterruptedException
{
boolean
all
=
choose
==
0
;
int
batchSizeMax
=
100
;
int
step
=
size
/
batchSizeMax
+
(
size
%
batchSizeMax
>
0
?
1
:
0
);
for
(
int
i
=
1
;
i
<=
step
;
i
++)
{
int
batchSize
=
i
==
step
?
(
size
%
batchSizeMax
)
:
batchSizeMax
;
switch
(
choose
)
{
case
0
:
case
1
:
System
.
out
.
println
(
"无事务"
);
test1
(
demoStoreService:
:
test1
,
maxThreadSize
,
batchSize
);
if
(!
all
)
break
;
case
2
:
System
.
out
.
println
(
"开启事务"
);
test1
(
demoStoreService:
:
test2
,
maxThreadSize
,
batchSize
);
if
(!
all
)
break
;
case
3
:
System
.
out
.
println
(
"只读事务"
);
test1
(
demoStoreService:
:
test3
,
maxThreadSize
,
batchSize
);
break
;
}
Thread
.
sleep
(
25
);
}
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
,
IOException
{
ApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
"applicationContext-conf.xml"
);
TestRun
bean
=
applicationContext
.
getBean
(
TestRun
.
class
);
...
...
@@ -69,19 +95,45 @@ public class TestRun {
// String s = reader.readLine();
// System.out.println(s);
// System.out.println("无事务");
// bean.test(demoStoreService::test1);
// bean.test
1
(demoStoreService::test1);
// System.out.println("开启事务");
// bean.test(demoStoreService::test2);
// bean.test
1
(demoStoreService::test2);
// System.out.println("只读事务");
// bean.test(demoStoreService::test3);
// bean.test1(demoStoreService::test3);
int
maxThreadSize
=
100
;
int
size
=
10000
;
int
choose
=
0
;
String
input
;
while
(
true
)
{
String
s2
=
reader
.
readLine
();
System
.
out
.
println
(
s2
);
if
(
s2
.
equals
(
"exit"
))
{
System
.
out
.
printf
(
"请输入并发线程数,当前 %d\n"
,
maxThreadSize
);
input
=
reader
.
readLine
();
if
(
input
.
length
()
>
0
)
{
maxThreadSize
=
Integer
.
valueOf
(
input
);
}
System
.
out
.
printf
(
"请输入查询次数,当前 %d\n"
,
size
);
input
=
reader
.
readLine
();
if
(
input
.
length
()
>
0
)
{
size
=
Integer
.
valueOf
(
input
);
}
System
.
out
.
printf
(
"请输入测试项(当前 %d)\n"
+
"0. 全部\n"
+
"1. 无事务\n"
+
"2. 开启事务\n"
+
"3. 只读事务\n"
,
choose
);
input
=
reader
.
readLine
();
if
(
input
.
length
()
>
0
)
{
choose
=
Integer
.
valueOf
(
input
);
}
System
.
out
.
println
(
"-- test begin --"
);
bean
.
test3
(
demoStoreService
,
maxThreadSize
,
size
,
choose
);
System
.
out
.
println
(
"-- test end --"
);
System
.
out
.
println
(
"输入任意字符继续,exit退出..."
);
input
=
reader
.
readLine
();
if
(
"exit"
.
equals
(
input
))
{
System
.
exit
(
0
);
break
;
}
bean
.
test2
(
demoStoreService
);
}
}
}
gic-demo-single-service/src/main/resources/jdbc-gic-demo-service.xml
View file @
8e909349
...
...
@@ -69,11 +69,11 @@
<!-- <!– 改 –>-->
<!-- <tx:method name="update*" rollback-for="java.lang.Exception"/>-->
<!-- <!– 查 –>-->
<!-- <tx:method name="get*" read-only="true"/>-->
<!-- <tx:method name="find*" read-only="true"/>-->
<!-- <tx:method name="count*" read-only="true"/>-->
<!-- <tx:method name="list*" read-only="true"/>-->
<!-- <tx:method name="query*" read-only="true"/>-->
<!-- <tx:method name="get*"
propagation="SUPPORTS"
read-only="true"/>-->
<!-- <tx:method name="find*"
propagation="SUPPORTS"
read-only="true"/>-->
<!-- <tx:method name="count*"
propagation="SUPPORTS"
read-only="true"/>-->
<!-- <tx:method name="list*"
propagation="SUPPORTS"
read-only="true"/>-->
<!-- <tx:method name="query*"
propagation="SUPPORTS"
read-only="true"/>-->
<!-- </tx:attributes>-->
<!-- </tx:advice>-->
...
...
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