添加测试

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@285 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-06-27 09:34:12 +00:00
parent f75016268d
commit b4997cccf1
3 changed files with 132 additions and 0 deletions
@@ -0,0 +1,41 @@
package com.alibaba.druid.bvt.proxy.filter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.management.openmbean.TabularData;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.alibaba.druid.stat.JdbcStatManager;
public class StatFilterTest extends TestCase {
public void setUp() throws Exception {
JdbcStatManager.getInstance().reset();
}
public void tearDown() throws Exception {
JdbcStatManager.getInstance().reset();
}
public void test_stat() throws Exception {
Connection conn = DriverManager.getConnection("jdbc:wrap-jdbc:filters=default:jdbc:mock:xx");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1");
while (rs.next()) {
rs.getInt(1);
}
rs.close();
stmt.close();
conn.close();
TabularData sqlList = JdbcStatManager.getInstance().getSqlList();
Assert.assertEquals(1, sqlList.size());
}
}
@@ -0,0 +1,51 @@
package com.alibaba.druid.sql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import junit.framework.TestCase;
public class TestOnlineSQLTest3 extends TestCase {
private String url = "jdbc:mysql://10.249.192.221/test";
private String user = "dragoon";
private String password = "dragoon";
protected Connection conn;
public void setUp() throws Exception {
conn = DriverManager.getConnection(url, user, password);
}
public void tearDown() throws Exception {
if (conn != null) {
conn.close();
conn = null;
}
}
public void test_0 () throws Exception {
String sql = "SELECT * FROM m_sql_const";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
long id = rs.getLong(1);
String value = rs.getString(2);
handle(id, value);
}
rs.close();
stmt.close();
}
void handle(long id, String value) {
String sql = value.toString();
System.out.println(sql);
}
}
@@ -0,0 +1,40 @@
/*
* 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.stat;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import junit.framework.TestCase;
public class TestBeidou extends TestCase {
public void test_0() throws Exception {
String url = "jdbc:mysql://172.22.32.5/beidou?useUnicode=true&characterEncoding=UTF-8";
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, "beidou", "mzbSXikh48dTrVX8kuLYtuok1");
PreparedStatement stmt = conn.prepareStatement("select sysdate");
stmt.executeBatch();
String catalog = conn.getCatalog();
System.out.println(catalog);
stmt.close();
conn.close();
}
}