Merge remote-tracking branch 'upstream/master'

This commit is contained in:
DigitalSonic
2019-04-09 00:36:35 +08:00
410 changed files with 4338 additions and 1467 deletions
@@ -1,5 +1,6 @@
package com.alibaba.druid.bvt.console;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import junit.framework.TestCase;
@@ -44,7 +45,12 @@ public class DruidStatNullDataTest extends TestCase {
String pid = getSelfPid();
String[] cmdArray = {"-sql", pid};
Option opt = Option.parseOptions(cmdArray);
DruidStat.printDruidStat(opt);
try {
DruidStat.printDruidStat(opt);
} catch (IOException ex) {
// skip
return;
}
cmdArray = new String[] {"-act", pid};
opt = Option.parseOptions(cmdArray);
@@ -52,12 +58,12 @@ public class DruidStatNullDataTest extends TestCase {
dispose();
}
public static void main(String[] args) {
Result result = JUnitCore.runClasses(DruidStatNullDataTest.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
}
// public static void main(String[] args) {
// Result result = JUnitCore.runClasses(DruidStatNullDataTest.class);
// for (Failure failure : result.getFailures()) {
// System.out.println(failure.toString());
// }
// }
@@ -1,6 +1,7 @@
package com.alibaba.druid.bvt.console;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.sql.Connection;
import java.sql.Statement;
@@ -64,7 +65,12 @@ public class DruidStatTest extends TestCase {
String pid = getSelfPid();
String[] cmdArray = {"-sql", pid};
Option opt = Option.parseOptions(cmdArray);
DruidStat.printDruidStat(opt);
try {
DruidStat.printDruidStat(opt);
} catch (IOException ex) {
// skip
return;
}
cmdArray = new String[] {"-sql","-id","1", pid};
opt = Option.parseOptions(cmdArray);
@@ -79,8 +85,13 @@ public class DruidStatTest extends TestCase {
List<Integer> ids = DruidStat.getDataSourceIds(opt);
opt.setDetailPrint(true);
opt.setId( ids.get(0).intValue());
DruidStat.printDruidStat(opt);
try {
DruidStat.printDruidStat(opt);
} catch (IOException ex) {
// skip
return;
}
}
@@ -97,17 +108,20 @@ public class DruidStatTest extends TestCase {
stmt = conn.createStatement();
stmt.execute("insert into user values(30,'name2')");
DruidStat.printDruidStat(opt);
} catch (IOException ex) {
// skip
return;
} finally {
if (stmt != null ) try { stmt.close(); } catch (Exception e) {}
if (conn != null ) try { conn.close(); } catch (Exception e) {}
}
}
public static void main(String[] args) {
Result result = JUnitCore.runClasses(DruidStatTest.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
}
// public static void main(String[] args) {
// Result result = JUnitCore.runClasses(DruidStatTest.class);
// for (Failure failure : result.getFailures()) {
// System.out.println(failure.toString());
// }
// }
}
@@ -4,6 +4,7 @@ import java.sql.SQLException;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import com.alibaba.druid.PoolTestCase;
@@ -17,7 +18,8 @@ import junit.framework.TestCase;
public class FailFastTest extends PoolTestCase {
private DruidDataSource dataSource;
private AtomicInteger index = new AtomicInteger();
private CountDownLatch latch = new CountDownLatch(1);
@SuppressWarnings("serial")
@@ -26,6 +28,11 @@ public class FailFastTest extends PoolTestCase {
dataSource = new DruidDataSource() {
public PhysicalConnectionInfo createPhysicalConnection() throws SQLException {
if (index.get() > 2) {
return super.createPhysicalConnection();
}
index.incrementAndGet();
try {
latch.await();
} catch (InterruptedException e) {
@@ -79,6 +86,13 @@ public class FailFastTest extends PoolTestCase {
connectEndLatch.await(3, TimeUnit.SECONDS);
SQLException ex = errorHolder.get();
Assert.assertTrue(ex instanceof DataSourceNotAvailableException);
for (int i = 0; i < 300; ++i) {
if (!dataSource.isFailContinuous()) {
break;
}
Thread.sleep(100 * 1);
}
}
}
@@ -14,7 +14,7 @@ public class PagerUtilsTest_Limit_SQLServer_4 extends TestCase {
String result = PagerUtils.limit(sql, JdbcConstants.SQL_SERVER, 100, 10);
Assert.assertEquals("SELECT *\n" +
"FROM (\n" +
"\tSELECT *, ROW_NUMBER() OVER () AS ROWNUM\n" +
"\tSELECT *, ROW_NUMBER() AS ROWNUM\n" +
"\tFROM t1\n" +
"\tWHERE id > 1\n" +
") XX\n" +
@@ -0,0 +1,21 @@
package com.alibaba.druid.bvt.sql;
import com.alibaba.druid.sql.PagerUtils;
import com.alibaba.druid.util.JdbcConstants;
import junit.framework.TestCase;
import org.junit.Assert;
public class PagerUtilsTest_Limit_SQLServer_6 extends TestCase {
public void test_db2_union() throws Exception {
String sql = "SELECT t.name USER_NAME, t.xxx FROM t_sd_users t ORDER BY t.name ASC";
String result = PagerUtils.limit(sql, JdbcConstants.SQL_SERVER, 10, 10);
Assert.assertEquals("SELECT *\n" +
"FROM (\n" +
"\tSELECT t.name AS USER_NAME, t.xxx, ROW_NUMBER() OVER (ORDER BY t.name ASC) AS ROWNUM\n" +
"\tFROM t_sd_users t\n" +
") XX\n" +
"WHERE ROWNUM > 10\n" +
"\tAND ROWNUM <= 20", result);
}
}
@@ -74,4 +74,25 @@ public class PagerUtilsTest_Limit_oracle_0 extends TestCase {
") XXX\n" +
"WHERE RN > 20", result);
}
public void test_oracle_4() throws Exception {
String sql = "SELECT TO_CHAR(ADD_MONTHS(TO_DATE('2014', 'yyyy'), (ROWNUM) * 12), 'yyyy') as YEAR\n" +
"FROM DUAL\n" +
"CONNECT BY ROWNUM <=\n" +
"months_between(to_date(to_char(sysdate,'yyyy'),'yyyy') ,\n" +
"to_date('2014', 'yyyy')) / 12";
String result = PagerUtils.limit(sql, JdbcConstants.ORACLE, 20, 10);
Assert.assertEquals("SELECT *\n" +
"FROM (\n" +
"\tSELECT XX.*, ROWNUM AS RN\n" +
"\tFROM (\n" +
"\t\tSELECT TO_CHAR(ADD_MONTHS(TO_DATE('2014', 'yyyy'), ROWNUM * 12), 'yyyy') AS YEAR\n" +
"\t\tFROM DUAL\n" +
"\t\tCONNECT BY ROWNUM <= months_between(to_date(to_char(SYSDATE, 'yyyy'), 'yyyy'), to_date('2014', 'yyyy')) / 12\n" +
"\t) XX\n" +
"\tWHERE ROWNUM <= 30\n" +
") XXX\n" +
"WHERE RN > 20", result);
}
}
@@ -0,0 +1,39 @@
/*
* Copyright 1999-2017 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.hive;
import com.alibaba.druid.sql.OracleTest;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.util.JdbcConstants;
import java.util.List;
public class HiveCreateTableTest_41 extends OracleTest {
public void test_0() throws Exception {
String sql = "CREATE TABLE IF NOT EXISTS default.create_test (id int COMMENT '学号', name string COMMENT '姓名');";
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.HIVE);
assertEquals("CREATE TABLE IF NOT EXISTS default.create_test (\n" +
"\tid int COMMENT '学号',\n" +
"\tname string COMMENT '姓名'\n" +
");", SQLUtils.toSQLString(statementList, JdbcConstants.HIVE));
}
}
@@ -46,7 +46,7 @@ public class MySqlCreateTableTest69 extends MysqlTest {
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("CREATE TABLE t1 (\n" +
"\ts1 INT,\n" +
"\ts2 INT AS (EXP(s1)) SORTED\n" +
"\ts2 INT AS (EXP(s1)) STORED\n" +
")\n" +
"PARTITION BY LIST (s2) (\n" +
"\tPARTITION p1 VALUES IN (1)\n" +
@@ -57,7 +57,7 @@ public class MySqlCreateTableTest69 extends MysqlTest {
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("create table t1 (\n" +
"\ts1 INT,\n" +
"\ts2 INT as (EXP(s1)) sorted\n" +
"\ts2 INT as (EXP(s1)) stored\n" +
")\n" +
"partition by list (s2) (\n" +
"\tpartition p1 values in (1)\n" +
@@ -0,0 +1,53 @@
/*
* Copyright 1999-2017 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.select;
import com.alibaba.druid.sql.MysqlTest;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
public class MySqlSelectTest_241 extends MysqlTest {
public void test_0() throws Exception {
String sql = "select job_names.job_name from cover_rage_job_org as org RIGHT JOIN (\n" +
" select job_names.job_name as job_name\n" +
" from (\n" +
" SELECT '1' as job_name\n" +
") job_name_all) as job_names on job_names.job_name = org.job_name";
SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseSingleMysqlStatement(sql);
assertEquals("SELECT job_names.job_name\n" +
"FROM cover_rage_job_org org\n" +
"\tRIGHT JOIN (\n" +
"\t\tSELECT job_names.job_name AS job_name\n" +
"\t\tFROM (\n" +
"\t\t\tSELECT '1' AS job_name\n" +
"\t\t) job_name_all\n" +
"\t) job_names\n" +
"\tON job_names.job_name = org.job_name", stmt.toString());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
}
}
@@ -0,0 +1,42 @@
/*
* Copyright 1999-2017 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.select;
import com.alibaba.druid.sql.MysqlTest;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class MySqlSelectTest_246 extends MysqlTest {
public void test_0() throws Exception {
String sql = "SELECT -CAST(10 AS decimal(10, 2)), +CAST(10 AS decimal(10, 2))";
SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseSingleStatement(sql, JdbcConstants.MYSQL);
assertEquals("SELECT -CAST(10 AS decimal(10, 2)), +CAST(10 AS decimal(10, 2))", stmt.toString());
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
stmt.accept(visitor);
}
}
@@ -0,0 +1,28 @@
/*
* Copyright 1999-2017 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.postgresql;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.util.JdbcConstants;
import junit.framework.TestCase;
public class PGSetTest4 extends TestCase {
public void testSet() throws Exception {
SQLStatement stmt = SQLUtils.parseSingleStatement("SET ROLE 'postgres'", JdbcConstants.POSTGRESQL);
assertEquals("SET ROLE TO 'postgres'", stmt.toString());
}
}