From bcc115c919f69ca1627916e891021bd7559e0666 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Mon, 13 Jun 2016 22:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4Mysql=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/mysql/TestMySQLDriver.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/skywalking-sdk-plugin/mysql-plugin/src/test/java/test/ai/cloud/skywalking/plugin/mysql/TestMySQLDriver.java b/skywalking-sdk-plugin/mysql-plugin/src/test/java/test/ai/cloud/skywalking/plugin/mysql/TestMySQLDriver.java index a74a1b8b1..56c8734db 100644 --- a/skywalking-sdk-plugin/mysql-plugin/src/test/java/test/ai/cloud/skywalking/plugin/mysql/TestMySQLDriver.java +++ b/skywalking-sdk-plugin/mysql-plugin/src/test/java/test/ai/cloud/skywalking/plugin/mysql/TestMySQLDriver.java @@ -1,40 +1,40 @@ package test.ai.cloud.skywalking.plugin.mysql; +import com.ai.cloud.skywalking.plugin.TracingBootstrap; +import com.ai.skywalking.testframework.api.TraceTreeAssert; +import org.junit.Test; + import java.lang.reflect.InvocationTargetException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; -import java.sql.Statement; - -import org.junit.Test; - -import com.ai.cloud.skywalking.plugin.TracingBootstrap; public class TestMySQLDriver { - //@Test - public void testsql() throws IllegalAccessException, - IllegalArgumentException, InvocationTargetException, - NoSuchMethodException, SecurityException, ClassNotFoundException { - TracingBootstrap - .main(new String[] { "test.ai.cloud.skywalking.plugin.mysql.TestMySQLDriver" }); - } + @Test + public void testsql() throws IllegalAccessException, + IllegalArgumentException, InvocationTargetException, + NoSuchMethodException, SecurityException, ClassNotFoundException { + TracingBootstrap + .main(new String[]{"test.ai.cloud.skywalking.plugin.mysql.TestMySQLDriver"}); + } - public static void main(String[] args) throws ClassNotFoundException, SQLException, InterruptedException { - Class.forName("com.mysql.jdbc.Driver"); - String url="jdbc:mysql://10.1.228.202:31316/test?user=devrdbusr21&password=devrdbusr21"; + public static void main(String[] args) throws ClassNotFoundException, SQLException, InterruptedException { + Class.forName("com.mysql.jdbc.Driver"); + String url = "jdbc:mysql://127.0.0.1:3306/test?user=root&password=root"; + Connection con = DriverManager.getConnection(url); + con.setAutoCommit(false); - Connection con = DriverManager.getConnection(url); - Statement state = con.createStatement(); - con.setAutoCommit(false); - state.execute("select 1 from dual"); - - PreparedStatement p0 = con.prepareStatement("select 1 from dual where 1=?"); - p0.setInt(1, 1); - p0.execute(); - con.commit(); - con.close(); - - Thread.sleep(5* 1000); - } + PreparedStatement p0 = con.prepareStatement("select 1 from dual where 1=?"); + p0.setInt(1, 1); + p0.execute(); + con.commit(); + con.close(); + TraceTreeAssert.assertEquals(new String[][]{ + {"0", "jdbc:mysql://127.0.0.1:3306/test?user=root&password=root(root)", "preaparedStatement.executeUpdate:select 1 from dual where 1=?"}, + {"0", "jdbc:mysql://127.0.0.1:3306/test?user=root&password=root(root)", "connection.commit"}, + {"0.0", "jdbc:mysql://127.0.0.1:3306/test?user=root&password=root(root)", "connection.rollback"}, + {"0", "jdbc:mysql://127.0.0.1:3306/test?user=root&password=root(root)", "connection.close"}, + }, true); + } }