ameterizedOutputVisitorTest_6.java

This commit is contained in:
Yako
2014-10-27 14:34:02 +08:00
148 changed files with 1565 additions and 206 deletions
@@ -0,0 +1,15 @@
package com.alibaba.druid.bvt.bug;
import junit.framework.TestCase;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
public class Issue_685 extends TestCase {
public void test_for_issue() throws Exception {
OracleStatementParser parser = new OracleStatementParser("select upper(*) from aa order by now()");
SQLStatement st = parser.parseStatement();
st.toString();
}
}
@@ -1,9 +1,11 @@
package com.alibaba.druid.bvt.pool;
import java.sql.Connection;
import java.sql.SQLException;
import junit.framework.TestCase;
import org.junit.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.pool.DruidDataSource;
@@ -22,17 +24,34 @@ public class DruidDataSourceTest extends TestCase {
protected void tearDown() throws Exception {
dataSource.close();
}
public void test_getInitStackTrace() {
String stackTrace = dataSource.getInitStackTrace();
Assert.assertTrue(stackTrace.indexOf("com.alibaba.druid.bvt.pool.DruidDataSourceTest.setUp") != -1);
}
public void test_restart() throws Exception {
Assert.assertEquals(true, dataSource.isInited());
dataSource.restart();
{
Connection conn = dataSource.getConnection();
Assert.assertEquals(1, dataSource.getActiveCount());
Exception error = null;
try {
dataSource.restart();
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
Assert.assertEquals(true, dataSource.isInited());
conn.close();
dataSource.restart();
}
Assert.assertEquals(0, dataSource.getActiveCount());
Assert.assertEquals(false, dataSource.isInited());
Connection conn = dataSource.getConnection();
conn.close();
}
@@ -85,7 +85,7 @@ public class DruidDataSourceTest_notEmptyWait extends TestCase {
endLatch.await(100, TimeUnit.MILLISECONDS);
Thread.sleep(10);
Assert.assertEquals(0, dataSource.getNotEmptyWaitThreadCount());
// Assert.assertEquals(0, dataSource.getNotEmptyWaitThreadCount());
Assert.assertEquals(10, dataSource.getNotEmptyWaitThreadPeak());
}
}
@@ -0,0 +1,24 @@
package com.alibaba.druid.bvt.sql.mysql;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
import com.alibaba.druid.sql.parser.Token;
import junit.framework.TestCase;
public class MySql57Test extends TestCase {
public void test_0() throws Exception {
String sql = "ALTER TABLE t1 ALGORITHM=INPLACE, CHANGE COLUMN c1 c1 VARCHAR(255);";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("ALTER TABLE t1" //
+ "\n\tALGORITHM = INPLACE," //
+ "\n\tCHANGE COLUMN c1 c1 VARCHAR(255)", output);
}
}
@@ -0,0 +1,54 @@
/*
* 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.bvt.sql.mysql;
import org.junit.Assert;
import org.junit.Test;
import com.alibaba.druid.sql.MysqlTest;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
public class MySqlCreateTableTest55 extends MysqlTest {
@Test
public void test_union() throws Exception {
String sql = "CREATE TABLE tableA (datasn varchar(100) NOT NULL,PRIMARY KEY(datasn)) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 UNION=(tableB)";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseCreateTable();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(2, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE tableA (" //
+ "\n\tdatasn varchar(100) NOT NULL, " //
+ "\n\tPRIMARY KEY (datasn)" //
+ "\n) ENGINE = MRG_MyISAM CHARSET = utf8 UNION = (tableB)", output);
}
}
@@ -0,0 +1,54 @@
/*
* 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.bvt.sql.mysql;
import org.junit.Assert;
import org.junit.Test;
import com.alibaba.druid.sql.MysqlTest;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
public class MySqlCreateTableTest56 extends MysqlTest {
@Test
public void test_union() throws Exception {
String sql = "CREATE TABLE tableA (datasn varchar(100) NOT NULL,PRIMARY KEY(datasn)) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8 UNION=(tableB,tableC)";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseCreateTable();
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(3, visitor.getTables().size());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(0, visitor.getConditions().size());
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE tableA (" //
+ "\n\tdatasn varchar(100) NOT NULL, " //
+ "\n\tPRIMARY KEY (datasn)" //
+ "\n) ENGINE = MRG_MyISAM CHARSET = utf8 UNION = (tableB, tableC)", output);
}
}
@@ -0,0 +1,37 @@
package com.alibaba.druid.bvt.sql.odps;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser;
import com.alibaba.druid.sql.parser.Token;
public class OdpsCreateTableTest extends TestCase {
public void test_0() throws Exception {
String sql = "CREATE TABLE IF NOT EXISTS sale_detail(" //
+ " shop_name STRING," //
+ " customer_id STRING," //
+ " total_price DOUBLE" //
+ ")" //
+ "comment 'xxxx'" //
+ "PARTITIONED BY (sale_date STRING,region STRING)" //
+ "LIFECYCLE 5" //
+ ";";
OdpsStatementParser parser = new OdpsStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toOdpsString(stmt);
Assert.assertEquals("CREATE TABLE IF NOT EXISTS sale_detailsale_detail ("//
+ "\n\tshop_name STRING, "//
+ "\n\tcustomer_id STRING, "//
+ "\n\ttotal_price DOUBLE"//
+ "\n)"//
+ "\nCOMMENT 'xxxx'"//
+ "\nPARTITIONED (sale_date STRING, region STRING)"//
+ "\nLIFECYCLE 5", output);
}
}
@@ -0,0 +1,22 @@
package com.alibaba.druid.bvt.sql.odps;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser;
import com.alibaba.druid.sql.parser.Token;
public class OdpsCreateTableTest_1 extends TestCase {
public void test_0() throws Exception {
String sql = "CREATE TABLE sale_detail_like LIKE sale_detail;";
OdpsStatementParser parser = new OdpsStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toOdpsString(stmt);
Assert.assertEquals("CREATE TABLE sale_detail_likesale_detail_like LIKE sale_detail", output);
}
}
@@ -0,0 +1,22 @@
package com.alibaba.druid.bvt.sql.odps;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser;
import com.alibaba.druid.sql.parser.Token;
public class OdpsShowPartitionsTest extends TestCase {
public void test_0() throws Exception {
String sql = "show partitions secods.xxx";
OdpsStatementParser parser = new OdpsStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toOdpsString(stmt);
Assert.assertEquals("SHOW PARTITIONS secods.xxx", output);
}
}
@@ -0,0 +1,22 @@
package com.alibaba.druid.bvt.sql.odps;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser;
import com.alibaba.druid.sql.parser.Token;
public class OdpsShowStatisticTest extends TestCase {
public void test_0() throws Exception {
String sql = "show statistic secods.xxx";
OdpsStatementParser parser = new OdpsStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toOdpsString(stmt);
Assert.assertEquals("SHOW STATISTIC secods.xxx", output);
}
}
@@ -27,7 +27,16 @@ import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor;
public class PGSelectTest5 extends PGTest {
public void test_0() throws Exception {
String sql = " SELECT rs.* FROM ( WITH RECURSIVE r AS( SELECT * FROM t_e_shopcatalog WHERE parentcatalogid= (SELECT catalogid FROM t_e_shopcatalog where catalogname='学习分类' and parentcatalogid='0') UNION ALL SELECT t_e_shopcatalog.* FROM t_e_shopcatalog, r WHERE t_e_shopcatalog.parentcatalogid = r.catalogid )SELECT * FROM r )rs WHERE 1=1";
String sql = " SELECT rs.* FROM ( " //
+ "WITH RECURSIVE r AS( "//
+ "SELECT * " //
+ "FROM t_e_shopcatalog " //
+ "WHERE parentcatalogid= (SELECT catalogid FROM t_e_shopcatalog where catalogname='学习分类' and parentcatalogid='0') " //
+ "UNION ALL " //
+ "SELECT t_e_shopcatalog.* " //
+ "FROM t_e_shopcatalog, r " //
+ "WHERE t_e_shopcatalog.parentcatalogid = r.catalogid )"
+ "SELECT * FROM r )rs WHERE 1=1";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
@@ -43,7 +52,7 @@ public class PGSelectTest5 extends PGTest {
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
Assert.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(4, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getTables().size());
}