diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/cubrid/CubridConnectionTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/cubrid/CubridConnectionTest.java index 64d6377a2..29b88d1b6 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/cubrid/CubridConnectionTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/cubrid/CubridConnectionTest.java @@ -6,6 +6,7 @@ import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.DatabaseInfoTraceValue; import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; import com.nhn.pinpoint.common.ServiceType; import com.nhn.pinpoint.profiler.DefaultAgent; +import com.nhn.pinpoint.profiler.junit4.BasePinpointTest; import com.nhn.pinpoint.profiler.logging.Slf4jLoggerBinder; import com.nhn.pinpoint.profiler.util.MockAgent; import com.nhn.pinpoint.profiler.util.TestClassLoader; @@ -22,55 +23,38 @@ import java.util.Properties; /** * @author emeroad */ -public class CubridConnectionTest { +public class CubridConnectionTest extends BasePinpointTest { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private TestClassLoader loader; @Test - public void executeQueryAndexecuteUpdate() throws SQLException { - CUBRIDDriver driver = new CUBRIDDriver(); - Properties properties = new Properties(); - properties.setProperty("user", "dba"); - properties.setProperty("password", "nhn!@#123"); - Connection connect = driver.connect("jdbc:cubrid:10.101.57.233:30102:pinpoint:::", properties); + public void executeQueryAndExecuteUpdate() throws SQLException { + Connection connection = connectDB(); - PreparedStatement preparedStatement = connect.prepareStatement("select 1 from db_root where 1=?"); + PreparedStatement preparedStatement = connection.prepareStatement("select 1 from db_root where 1=?"); preparedStatement.setInt(1, 1); ResultSet resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { - System.out.println("---" + resultSet.getObject(1)); + logger.debug("---{}", resultSet.getObject(1)); } + connection.close(); } - @Before - public void setUp() throws Exception { - PLoggerFactory.initialize(new Slf4jLoggerBinder()); - - ProfilerConfig profilerConfig = new ProfilerConfig(); - // profiler config를 setter를 열어두는것도 괜찮을듯 하다. - String path = MockAgent.class.getClassLoader().getResource("pinpoint.config").getPath(); - profilerConfig.readConfigFile(path); - - profilerConfig.setApplicationServerType(ServiceType.TEST_STAND_ALONE); - DefaultAgent agent = new MockAgent("", profilerConfig); - loader = new TestClassLoader(agent); - // agent가 로드한 모든 Modifier를 자동으로 찾도록 변경함. - - - loader.initialize(); + private Connection connectDB() throws SQLException { + Driver driver = new CUBRIDDriver(); + Properties properties = new Properties(); + properties.setProperty("user", "dba"); + properties.setProperty("password", "nhn!@#123"); + return driver.connect("jdbc:cubrid:10.101.57.233:30102:pinpoint:::", properties); } + + @Test public void testModify() throws Exception { - Driver driver = loadClass(); - - Properties properties = new Properties(); - properties.setProperty("user", "dba"); - properties.setProperty("password", "nhn!@#123"); - Connection connection = driver.connect("jdbc:cubrid:10.101.57.233:30102:pinpoint:::", properties); + Connection connection = connectDB(); logger.info("Connection class name:{}", connection.getClass().getName()); logger.info("Connection class cl:{}", connection.getClass().getClassLoader()); @@ -103,20 +87,6 @@ public class CubridConnectionTest { } - private Driver loadClass() throws ClassNotFoundException, InstantiationException, IllegalAccessException { - Class driverClazz = (Class) loader.loadClass("cubrid.jdbc.driver.CUBRIDDriver"); - - Driver driver = driverClazz.newInstance(); - logger.info("Driver class name:{}", driverClazz.getName()); - logger.info("Driver class cl:{}", driverClazz.getClassLoader()); - - - Class version = loader.loadClass("com.nhn.pinpoint.common.Version"); - Assert.assertSame("check classLoader", this.getClass().getClassLoader(), version.getClassLoader()); - logger.debug("common cl:{}", version.getClassLoader()); - return driver; - } - private void statement(Connection connection) throws SQLException { Statement statement = connection.createStatement(); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/jtds/JtdsConnectionTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/jtds/JtdsConnectionTest.java index ea97cbcc9..44cda6f72 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/jtds/JtdsConnectionTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/jtds/JtdsConnectionTest.java @@ -24,15 +24,16 @@ public class JtdsConnectionTest extends BasePinpointTest { @Test - public void executeQueryAndexecuteUpdate() throws SQLException { - Connection connect = connectDB(); + public void executeQueryAndExecuteUpdate() throws SQLException { + Connection connection = connectDB(); - PreparedStatement preparedStatement = connect.prepareStatement("select 1 "); + PreparedStatement preparedStatement = connection.prepareStatement("select 1 "); // preparedStatement.setInt(1, 1); ResultSet resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { - logger.debug("---" + resultSet.getObject(1)); + logger.debug("---{}", resultSet.getObject(1)); } + connection.close(); } private Connection connectDB() throws SQLException { diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/mysql/MySQLConnectionImplModifierTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/mysql/MySQLConnectionImplModifierTest.java index a471ce047..0cb890d47 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/mysql/MySQLConnectionImplModifierTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/modifier/db/mysql/MySQLConnectionImplModifierTest.java @@ -1,6 +1,7 @@ package com.nhn.pinpoint.profiler.modifier.db.mysql; import com.mysql.jdbc.JDBC4PreparedStatement; +import com.mysql.jdbc.NonRegisteringDriver; import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.DatabaseInfoTraceValue; import com.nhn.pinpoint.common.ServiceType; import com.nhn.pinpoint.profiler.DefaultAgent; @@ -8,6 +9,7 @@ import com.nhn.pinpoint.bootstrap.config.ProfilerConfig; import com.nhn.pinpoint.bootstrap.context.DatabaseInfo; import com.nhn.pinpoint.bootstrap.logging.PLoggerFactory; +import com.nhn.pinpoint.profiler.junit4.BasePinpointTest; import com.nhn.pinpoint.profiler.logging.Slf4jLoggerBinder; @@ -28,40 +30,14 @@ import java.util.Properties; /** * @author emeroad */ -public class MySQLConnectionImplModifierTest { +public class MySQLConnectionImplModifierTest extends BasePinpointTest { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private TestClassLoader loader; - - - @Before - public void setUp() throws Exception { - PLoggerFactory.initialize(new Slf4jLoggerBinder()); - - ProfilerConfig profilerConfig = new ProfilerConfig(); - // profiler config를 setter를 열어두는것도 괜찮을듯 하다. - String path = MockAgent.class.getClassLoader().getResource("pinpoint.config").getPath(); - profilerConfig.readConfigFile(path); - - profilerConfig.setApplicationServerType(ServiceType.TEST_STAND_ALONE); - DefaultAgent agent = new MockAgent("", profilerConfig); - loader = new TestClassLoader(agent); - // agent가 로드한 모든 Modifier를 자동으로 찾도록 변경함. - - - loader.initialize(); - } - @Test public void testModify() throws Exception { - Driver driver = loadClass(); - - Properties properties = new Properties(); - properties.setProperty("user", "lucytest"); - properties.setProperty("password", "testlucy"); - Connection connection = driver.connect("jdbc:mysql://10.98.133.22:3306/hippo", properties); + Connection connection = connectDB("jdbc:mysql://10.98.133.22:3306/hippo"); logger.info("Connection class name:{}", connection.getClass().getName()); logger.info("Connection class cl:{}", connection.getClass().getClassLoader()); @@ -78,41 +54,24 @@ public class MySQLConnectionImplModifierTest { preparedStatement3(connection); connection.close(); + DatabaseInfo clearUrl = ((DatabaseInfoTraceValue)connection).__getTraceDatabaseInfo(); Assert.assertNull(clearUrl); } - private Driver loadClass() throws ClassNotFoundException, InstantiationException, IllegalAccessException { - Class driverClazz = (Class) loader.loadClass("com.mysql.jdbc.NonRegisteringDriver"); -// Driver nonRegisteringDriver = new NonRegisteringDriver(); -// Class driverClazz = (Class) nonRegisteringDriver.getClass(); - - Driver driver = driverClazz.newInstance(); - logger.info("Driver class name:{}", driverClazz.getName()); - logger.info("Driver class cl:{}", driverClazz.getClassLoader()); - - - Class aClass = loader.loadClass("com.mysql.jdbc.StringUtils"); -// 이게 loader와 동일하게 로드 되는게 정확한건지 애매함. 하위에 로드되는게 좋을것 같은데. -// Assert.assertNotSame("check classLoader", aClass.getClassLoader(), loader); - logger.debug("mysql cl:{}", aClass.getClassLoader()); - - Class version = loader.loadClass("com.nhn.pinpoint.common.Version"); - Assert.assertSame("check classLoader", this.getClass().getClassLoader(), version.getClassLoader()); - logger.debug("common cl:{}", version.getClassLoader()); - return driver; + private Connection connectDB(String url) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException { + Driver driver = new NonRegisteringDriver(); + Properties properties = new Properties(); + properties.setProperty("user", "lucytest"); + properties.setProperty("password", "testlucy"); + return driver.connect(url, properties); } @Test public void loadBalancedUrlModify() throws Exception { - Driver driver = loadClass(); - - Properties properties = new Properties(); - properties.setProperty("user", "lucytest"); - properties.setProperty("password", "testlucy"); - Connection connection = driver.connect("jdbc:mysql:loadbalance://10.98.133.23:3306,10.98.133.22:3306/hippo", properties); + Connection connection = connectDB("jdbc:mysql:loadbalance://10.98.133.23:3306,10.98.133.22:3306/hippo"); logger.info("Connection class name:{}", connection.getClass().getName()); logger.info("Connection class cl:{}", connection.getClass().getClassLoader()); @@ -188,7 +147,6 @@ public class MySQLConnectionImplModifierTest { connection.commit(); - connection.setAutoCommit(true); }