mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
change benchmarktest
This commit is contained in:
@@ -15,13 +15,15 @@
|
||||
*/
|
||||
package com.alibaba.druid.benckmark.wall;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.wall.WallProvider;
|
||||
import com.alibaba.druid.wall.spi.MySqlWallProvider;
|
||||
|
||||
public class WallBenchmarkTest1 extends TestCase {
|
||||
|
||||
static Random r = new Random();
|
||||
WallProvider provider = new MySqlWallProvider();
|
||||
|
||||
public final static int COUNT = 1000 * 1000;
|
||||
@@ -41,8 +43,26 @@ public class WallBenchmarkTest1 extends TestCase {
|
||||
|
||||
public void perf(String sql) {
|
||||
for (int i = 0; i < COUNT; ++i) {
|
||||
String text = sql + " AND FID = " + i;
|
||||
String text = genRandomSql();
|
||||
provider.check(text);
|
||||
}
|
||||
}
|
||||
|
||||
private String genRandomSql(){
|
||||
int result1=r.nextInt(65535);
|
||||
int result2=r.nextInt(65535);
|
||||
String result = Integer.toBinaryString(result1)+""+Integer.toBinaryString(result2);
|
||||
StringBuilder sb = new StringBuilder("select ");
|
||||
for(int i=0;i<result.length();i++){
|
||||
if(result.charAt(i) == '1'){
|
||||
String tempString = "col"+(i+1)+",";
|
||||
sb.append(tempString);
|
||||
}
|
||||
}
|
||||
sb.delete(sb.length()-1, sb.length());
|
||||
sb.append(" from sqlinject");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user