improve sql parser & improve GetConnecitonTimeout error message

This commit is contained in:
wenshao
2013-08-07 19:25:55 +08:00
parent 29e84f2be2
commit 65a963f88f
10 changed files with 268 additions and 64 deletions
@@ -52,7 +52,7 @@ public class WallProviderTest extends TestCase {
Assert.assertSame(whiteStat_1, provider.getSqlStat(sql_x));
}
Assert.assertEquals(500, provider.getWhiteList().size());
Assert.assertEquals(0, provider.getWhiteList().size());
Assert.assertEquals(2, provider.getSqlList().size());
Assert.assertFalse(provider.checkValid("slelc"));
@@ -66,10 +66,10 @@ public class WallProviderTest extends TestCase {
Assert.assertEquals(1009, statValue.getCheckCount());
Assert.assertEquals(2, statValue.getBlackListHitCount());
Assert.assertEquals(1005, statValue.getHardCheckCount());
Assert.assertEquals(4, statValue.getHardCheckCount());
Assert.assertEquals(1, statValue.getSyntaxErrorCount());
Assert.assertEquals(5, statValue.getViolationCount());
Assert.assertEquals(2, statValue.getWhiteListHitCount());
Assert.assertEquals(1003, statValue.getWhiteListHitCount());
Assert.assertEquals(1, statValue.getWhiteList().size());
Assert.assertEquals(2, statValue.getBlackList().size());
@@ -30,8 +30,8 @@ public class WallStatTest_WhiteList extends TestCase {
WallTableStat tableStat = provider.getTableStat("t");
Assert.assertEquals(3001, tableStat.getSelectCount());
Assert.assertEquals(0, provider.getBlackListHitCount());
Assert.assertEquals(0, provider.getWhiteListHitCount());
Assert.assertEquals(500, provider.getWhiteList().size());
Assert.assertEquals(3000, provider.getWhiteListHitCount());
Assert.assertEquals(0, provider.getWhiteList().size());
Assert.assertEquals(3001, provider.getCheckCount());
}
@@ -30,7 +30,7 @@ public class WallStatTest_whiteList_syntaxError extends TestCase {
Assert.assertEquals(0, tableStat.getSelectCount());
Assert.assertEquals(0, provider.getBlackListHitCount());
Assert.assertEquals(0, provider.getWhiteListHitCount());
Assert.assertEquals(1, provider.getWhiteList().size());
Assert.assertEquals(0, provider.getWhiteList().size());
Assert.assertEquals(0, provider.getBlackList().size());
Assert.assertEquals(1, provider.getCheckCount());
Assert.assertEquals(1, provider.getSyntaxErrorCount());
@@ -42,12 +42,12 @@ public class WallStatTest_whiteList_syntaxError extends TestCase {
WallTableStat tableStat = provider.getTableStat("t");
Assert.assertEquals(0, tableStat.getSelectCount());
Assert.assertEquals(0, provider.getBlackListHitCount());
Assert.assertEquals(1, provider.getWhiteListHitCount());
Assert.assertEquals(1, provider.getWhiteList().size());
Assert.assertEquals(0, provider.getWhiteListHitCount());
Assert.assertEquals(0, provider.getWhiteList().size());
Assert.assertEquals(0, provider.getBlackList().size());
Assert.assertEquals(2, provider.getCheckCount());
Assert.assertEquals(2, provider.getSyntaxErrorCount());
Assert.assertEquals(1, provider.getHardCheckCount());
Assert.assertEquals(2, provider.getHardCheckCount());
}
}
@@ -29,7 +29,7 @@ import com.alibaba.druid.stat.TableStat;
public class MySqlCreateTableTest29 extends MysqlTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE lookup" + //
String sql = "CREATE TABLE user" + //
" (id INT, INDEX USING BTREE (id))" + //
" MIN_ROWS 1024;"; //
@@ -52,10 +52,10 @@ public class MySqlCreateTableTest29 extends MysqlTest {
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("lookup")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("user")));
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE lookup (" + //
Assert.assertEquals("CREATE TABLE user (" + //
"\n\tid INT, " + //
"\n\tINDEX USING BTREE(id)" + //
"\n) MIN_ROWS = 1024", output);
@@ -0,0 +1,69 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.pool;
import java.sql.Connection;
import java.sql.Statement;
import java.util.concurrent.CountDownLatch;
import EDU.oswego.cs.dl.util.concurrent.CountDown;
import junit.framework.TestCase;
public class MaxWaitTest extends TestCase {
private DruidDataSource dataSource;
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mysql://localhost:3306/sonar");
dataSource.setUsername("sonar");
dataSource.setPassword("sonar");
dataSource.setFilters("stat");
dataSource.setMaxWait(1000);
dataSource.setInitialSize(3);
dataSource.setMinIdle(3);
dataSource.setMaxActive(3);
}
public void test_maxWait() throws Exception {
final CountDownLatch latch = new CountDownLatch(10);
for (int i = 0; i < 20; ++i) {
Thread thread = new Thread() {
public void run() {
try {
for (int i = 0; i < 10; ++i) {
try {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("select sleep(" + (i % 5 + 1) + ")");
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} finally {
latch.countDown();
}
}
};
thread.start();
}
latch.await();
}
}
@@ -0,0 +1,16 @@
package com.alibaba.druid.sql;
import java.io.StringReader;
import junit.framework.TestCase;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
public class JSqlParserTest extends TestCase {
CCJSqlParserManager parserManager = new CCJSqlParserManager();
public void test_0() throws Exception {
String statement = "ALTER TABLE `test`.`tb1` ADD INDEX `ix` (`f2` ASC) ;";
parserManager.parse(new StringReader(statement));
}
}