Commit 8e909349 by 朱瑞泽

test

parent a818dd1b
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;
}
}
......@@ -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 test1(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.test1(demoStoreService::test1);
// System.out.println("开启事务");
// bean.test(demoStoreService::test2);
// bean.test1(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);
}
}
}
......@@ -69,11 +69,11 @@
<!-- &lt;!&ndash; 改 &ndash;&gt;-->
<!-- <tx:method name="update*" rollback-for="java.lang.Exception"/>-->
<!-- &lt;!&ndash; 查 &ndash;&gt;-->
<!-- <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>-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment