You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/10/28 07:27:26 UTC
[skywalking] branch master updated: Refactor:extract common module
postgresql-common (#3725)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new d9fcda1 Refactor:extract common module postgresql-common (#3725)
d9fcda1 is described below
commit d9fcda13257808f5e40e4565d7240ba669c0ac3c
Author: aderm <zh...@163.com>
AuthorDate: Mon Oct 28 15:27:15 2019 +0800
Refactor:extract common module postgresql-common (#3725)
* refactor:extract common module postgresql-common
* remove sql param tag.
* delete the deploy plugin
---
apm-sniffer/apm-sdk-plugin/pom.xml | 1 +
.../apm-sdk-plugin/postgresql-8.x-plugin/pom.xml | 14 ++-
.../AbstractJdbc2StatementInstrumentation.java | 7 +-
.../define/ConnectionInstrumentation.java | 3 +-
.../plugin/jdbc/postgresql/define/Constants.java | 31 -------
.../define/Jdbc3ConnectionInstrumentation.java | 1 +
.../define/Jdbc4ConnectionInstrumentation.java | 1 +
.../define/PgCallableStatementInstrumentation.java | 4 +-
.../define/PgPreparedStatementInstrumentation.java | 4 +-
.../define/PgStatementInstrumentation.java | 4 +-
.../pom.xml | 15 +--
.../apm/plugin/jdbc/postgresql/Constants.java} | 14 ++-
.../CreateCallableStatementInterceptor.java | 2 +-
.../CreatePreparedStatementInterceptor.java | 2 +-
.../interceptor}/CreateStatementInterceptor.java | 2 +-
...PrepareStatementWithStringArrayInterceptor.java | 4 +-
...PreparedStatementExecuteMethodsInterceptor.java | 2 +-
.../StatementExecuteMethodsInterceptor.java | 2 +-
.../CreateCallableStatementInterceptorTest.java | 64 +++++++++++++
.../CreatePreparedStatementInterceptorTest.java | 60 ++++++++++++
.../test/java/CreateStatementInterceptorTest.java | 61 ++++++++++++
...aredStatementExecuteMethodsInterceptorTest.java | 102 +++++++++++++++++++++
.../StatementExecuteMethodsInterceptorTest.java | 99 ++++++++++++++++++++
23 files changed, 426 insertions(+), 73 deletions(-)
diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml
index 2c7feb7..4748f66 100644
--- a/apm-sniffer/apm-sdk-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/pom.xml
@@ -54,6 +54,7 @@
<module>mysql-common</module>
<module>h2-1.x-plugin</module>
<module>postgresql-8.x-plugin</module>
+ <module>postgresql-common</module>
<module>rocketMQ-3.x-plugin</module>
<module>rocketMQ-4.x-plugin</module>
<module>elastic-job-2.x-plugin</module>
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/pom.xml
index 11c781b..675cd11 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/pom.xml
@@ -48,13 +48,11 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.skywalking</groupId>
+ <artifactId>apm-postgresql-commons</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-deploy-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
</project>
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java
index 507f025..b4557e3 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java
@@ -24,12 +24,11 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.Constants;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
-import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
-import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
@@ -49,7 +48,7 @@ public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsE
}
@Override public String getMethodsInterceptor() {
- return PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
+ return Constants.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
@@ -64,7 +63,7 @@ public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsE
}
@Override public String getMethodsInterceptor() {
- return PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
+ return Constants.PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java
index 6c942bb..f546e77 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java
@@ -25,6 +25,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.Constants;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
@@ -48,7 +49,7 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMa
*/
public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
- private static final String PREPARE_STATEMENT_METHOD_WITH_STRING_ARRAY_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.JDBCPrepareStatementWithStringArrayInterceptor";
+ private static final String PREPARE_STATEMENT_METHOD_WITH_STRING_ARRAY_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.JDBCPrepareStatementWithStringArrayInterceptor";
public static final String PG_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc.PgConnection";
public static final String STRING_ARRAY_ARGUMENT_TYPE = "java.lang.String[]";
public static final String PG_JDBC42_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc42.Jdbc42Connection";
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java
deleted file mode 100755
index cda27df..0000000
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Constants.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.jdbc.postgresql.define;
-
-/**
- * Interceptor class name constant variable
- *
- * @author zhangxin
- */
-public class Constants {
- public static final String CREATE_STATEMENT_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.CreateStatementInterceptor";
- public static final String CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.CreatePreparedStatementInterceptor";
- public static final String CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.CreateCallableStatementInterceptor";
-}
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java
index 6e67fe0..09c4ae4 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc3ConnectionInstrumentation.java
@@ -26,6 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsIn
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.Constants;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java
index df4cf51..cbeca3b 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/Jdbc4ConnectionInstrumentation.java
@@ -25,6 +25,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.Constants;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgCallableStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgCallableStatementInstrumentation.java
index 5851166..a47c27e 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgCallableStatementInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgCallableStatementInstrumentation.java
@@ -24,11 +24,11 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.Constants;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
-import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
public class PgCallableStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
@Override public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
@@ -44,7 +44,7 @@ public class PgCallableStatementInstrumentation extends ClassInstanceMethodsEnha
}
@Override public String getMethodsInterceptor() {
- return PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
+ return Constants.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgPreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgPreparedStatementInstrumentation.java
index a88878c..e64e5ad 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgPreparedStatementInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgPreparedStatementInstrumentation.java
@@ -24,11 +24,11 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.Constants;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
-import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
/**
* @author zhang xin
@@ -49,7 +49,7 @@ public class PgPreparedStatementInstrumentation extends ClassInstanceMethodsEnha
}
@Override public String getMethodsInterceptor() {
- return PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
+ return Constants.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgStatementInstrumentation.java
index 66f8c90..a82378d 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgStatementInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgStatementInstrumentation.java
@@ -24,11 +24,11 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.Constants;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
-import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
/**
* @author zhang xin
@@ -52,7 +52,7 @@ public class PgStatementInstrumentation extends ClassInstanceMethodsEnhancePlugi
}
@Override public String getMethodsInterceptor() {
- return PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
+ return Constants.PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/postgresql-common/pom.xml
similarity index 86%
copy from apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/pom.xml
copy to apm-sniffer/apm-sdk-plugin/postgresql-common/pom.xml
index 11c781b..3f5ebbe 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/pom.xml
@@ -24,15 +24,16 @@
</parent>
<modelVersion>4.0.0</modelVersion>
- <artifactId>apm-postgresql-8.x-plugin</artifactId>
+ <artifactId>apm-postgresql-commons</artifactId>
<packaging>jar</packaging>
- <name>postgresql-8.x-plugin</name>
+ <name>apm-postgresql-commons</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<postgresql.version>42.0.0</postgresql.version>
+ <guava.version>20.0</guava.version>
</properties>
<dependencies>
@@ -40,7 +41,7 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
- <scope>provided</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
@@ -49,12 +50,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-deploy-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
</project>
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/Variables.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/Constants.java
old mode 100755
new mode 100644
similarity index 59%
rename from apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/Variables.java
rename to apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/Constants.java
index d92d965..5142d3f
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/Variables.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/Constants.java
@@ -15,11 +15,15 @@
* limitations under the License.
*
*/
-
package org.apache.skywalking.apm.plugin.jdbc.postgresql;
-public final class Variables {
- public static final String PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.postgresql.PreparedStatementExecuteMethodsInterceptor";
-
- public static final String PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.postgresql.StatementExecuteMethodsInterceptor";
+/**
+ * @author aderm
+ */
+public class Constants {
+ public static final String CREATE_STATEMENT_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.CreateStatementInterceptor";
+ public static final String CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.CreatePreparedStatementInterceptor";
+ public static final String CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.CreateCallableStatementInterceptor";
+ public static final String PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.PreparedStatementExecuteMethodsInterceptor";
+ public static final String PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.StatementExecuteMethodsInterceptor";
}
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/CreateCallableStatementInterceptor.java
similarity index 96%
rename from apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java
rename to apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/CreateCallableStatementInterceptor.java
index 8c93ce9..4540df8 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateCallableStatementInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/CreateCallableStatementInterceptor.java
@@ -17,7 +17,7 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.postgresql;
+package org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/CreatePreparedStatementInterceptor.java
similarity index 96%
rename from apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java
rename to apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/CreatePreparedStatementInterceptor.java
index ef084ba..b08afb3 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreatePreparedStatementInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/CreatePreparedStatementInterceptor.java
@@ -17,7 +17,7 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.postgresql;
+package org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/CreateStatementInterceptor.java
similarity index 96%
rename from apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java
rename to apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/CreateStatementInterceptor.java
index 678e2b0..e12c79a 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/CreateStatementInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/CreateStatementInterceptor.java
@@ -17,7 +17,7 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.postgresql;
+package org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/JDBCPrepareStatementWithStringArrayInterceptor.java
similarity index 97%
rename from apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java
rename to apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/JDBCPrepareStatementWithStringArrayInterceptor.java
index 8bca900..7be1cd6 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/JDBCPrepareStatementWithStringArrayInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/JDBCPrepareStatementWithStringArrayInterceptor.java
@@ -17,16 +17,16 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.postgresql;
+package org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
-import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement;
/**
* {@link JDBCPrepareStatementWithStringArrayInterceptor} return {@link SWPreparedStatement} instance that wrapper the
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/PreparedStatementExecuteMethodsInterceptor.java
similarity index 98%
rename from apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java
rename to apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/PreparedStatementExecuteMethodsInterceptor.java
index 6686e6b..4629370 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/PreparedStatementExecuteMethodsInterceptor.java
@@ -17,7 +17,7 @@
*/
-package org.apache.skywalking.apm.plugin.jdbc.postgresql;
+package org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.conf.Config;
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/StatementExecuteMethodsInterceptor.java
similarity index 98%
rename from apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java
rename to apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/StatementExecuteMethodsInterceptor.java
index fd75626..af98395 100755
--- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/interceptor/StatementExecuteMethodsInterceptor.java
@@ -16,7 +16,7 @@
*
*/
-package org.apache.skywalking.apm.plugin.jdbc.postgresql;
+package org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/CreateCallableStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/CreateCallableStatementInterceptorTest.java
new file mode 100644
index 0000000..2270883
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/CreateCallableStatementInterceptorTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.CreateCallableStatementInterceptor;
+import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * @author aderm
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class CreateCallableStatementInterceptorTest {
+
+ private CreateCallableStatementInterceptor interceptor;
+
+ @Mock
+ private EnhancedInstance objectInstance;
+
+ @Mock
+ private EnhancedInstance ret;
+
+ @Mock
+ private ConnectionInfo connectionInfo;
+
+ @Before
+ public void setUp() {
+ interceptor = new CreateCallableStatementInterceptor();
+ when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo);
+ }
+
+ @Test
+ public void testResultIsEnhanceInstance() throws Throwable {
+ interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FORM test"}, null, ret);
+ verify(ret).setSkyWalkingDynamicField(Matchers.any());
+ }
+
+
+
+
+}
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/CreatePreparedStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/CreatePreparedStatementInterceptorTest.java
new file mode 100644
index 0000000..d82f3a0
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/CreatePreparedStatementInterceptorTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.CreatePreparedStatementInterceptor;
+import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * @author aderm
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class CreatePreparedStatementInterceptorTest {
+
+ private CreatePreparedStatementInterceptor interceptor;
+
+ @Mock
+ private EnhancedInstance ret;
+
+ @Mock
+ private EnhancedInstance objectInstance;
+
+ @Mock
+ private ConnectionInfo connectionInfo;
+
+ @Before
+ public void setUp() {
+ interceptor = new CreatePreparedStatementInterceptor();
+ when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo);
+ }
+
+ @Test
+ public void testResultEnhanceInstance() throws Throwable {
+ interceptor.afterMethod(objectInstance, null, new Object[]{"SELECT * FROM test"}, null, ret);
+ verify(ret).setSkyWalkingDynamicField(Matchers.any());
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/CreateStatementInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/CreateStatementInterceptorTest.java
new file mode 100644
index 0000000..5623c24
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/CreateStatementInterceptorTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
+import static org.mockito.Mockito.verify;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.CreateStatementInterceptor;
+import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+/**
+ * @author aderm
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class CreateStatementInterceptorTest {
+
+ private CreateStatementInterceptor interceptor;
+
+ @Mock
+ private EnhancedInstance ret;
+
+ @Mock
+ private EnhancedInstance objectInstance;
+
+ @Mock
+ private ConnectionInfo connectionInfo;
+
+ @Before
+ public void setUp() {
+ interceptor = new CreateStatementInterceptor();
+
+ when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo);
+ }
+
+ @Test
+ public void testResultIsEnhanceInstance() throws Throwable {
+ interceptor.afterMethod(objectInstance, null, new Object[] {"SELECT * FROM test"}, null, ret);
+ verify(ret).setSkyWalkingDynamicField(Matchers.any());
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/PreparedStatementExecuteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/PreparedStatementExecuteMethodsInterceptorTest.java
new file mode 100644
index 0000000..0941e85
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/PreparedStatementExecuteMethodsInterceptorTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.when;
+
+import java.lang.reflect.Method;
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
+import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
+import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
+import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
+import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
+import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
+import org.apache.skywalking.apm.agent.test.tools.SpanAssert;
+import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
+import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.PreparedStatementExecuteMethodsInterceptor;
+import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+
+/**
+ * @author aderm
+ */
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+public class PreparedStatementExecuteMethodsInterceptorTest {
+
+ @SegmentStoragePoint
+ private SegmentStorage segmentStorage;
+
+ @Rule
+ public AgentServiceRule serviceRule = new AgentServiceRule();
+
+ private PreparedStatementExecuteMethodsInterceptor interceptor;
+
+ @Mock
+ private ConnectionInfo connectionInfo;
+
+ @Mock
+ private EnhancedInstance objectInstance;
+
+ @Mock
+ private Method method;
+
+ private StatementEnhanceInfos statementEnhanceInfos;
+
+ @Before
+ public void setUp() {
+ interceptor = new PreparedStatementExecuteMethodsInterceptor();
+ statementEnhanceInfos = new StatementEnhanceInfos(connectionInfo, "SELECT * FROM test WHERE item1=? and item2=?", "CallableStatement");
+ statementEnhanceInfos.setParameter(1, "abc");
+ statementEnhanceInfos.setParameter(2, "def");
+ when(objectInstance.getSkyWalkingDynamicField()).thenReturn(statementEnhanceInfos);
+ when(method.getName()).thenReturn("executeQuery");
+ when(connectionInfo.getComponent()).thenReturn(ComponentsDefine.POSTGRESQL_DRIVER);
+ when(connectionInfo.getDBType()).thenReturn("POSTGRESQL");
+ when(connectionInfo.getDatabaseName()).thenReturn("test");
+ when(connectionInfo.getDatabasePeer()).thenReturn("localhost:5432");
+ }
+
+ @Test
+ public void testCreateDatabaseSpan() throws Throwable {
+ interceptor.beforeMethod(objectInstance, method, new Object[]{"WHERE item1=? and item2=?"}, null, null);
+ interceptor.afterMethod(objectInstance, method, new Object[]{"WHERE item1=? and item2=?"}, null, null);
+
+ assertThat(segmentStorage.getTraceSegments().size(), is(1));
+ TraceSegment segment = segmentStorage.getTraceSegments().get(0);
+ assertThat(SegmentHelper.getSpans(segment).size(), is(1));
+ AbstractTracingSpan span = SegmentHelper.getSpans(segment).get(0);
+ SpanAssert.assertLayer(span, SpanLayer.DB);
+ assertThat(span.getOperationName(), is("POSTGRESQL/JDBI/CallableStatement/"));
+ SpanAssert.assertTag(span, 0, "sql");
+ SpanAssert.assertTag(span, 1, "test");
+ SpanAssert.assertTag(span, 2, "SELECT * FROM test WHERE item1=? and item2=?");
+ }
+
+}
diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/StatementExecuteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/StatementExecuteMethodsInterceptorTest.java
new file mode 100644
index 0000000..2a6775d
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/postgresql-common/src/test/java/StatementExecuteMethodsInterceptorTest.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ *
+ */
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.when;
+
+import java.lang.reflect.Method;
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
+import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
+import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
+import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
+import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
+import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
+import org.apache.skywalking.apm.agent.test.tools.SpanAssert;
+import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
+import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos;
+import org.apache.skywalking.apm.plugin.jdbc.postgresql.interceptor.StatementExecuteMethodsInterceptor;
+import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+
+/**
+ * @author aderm
+ */
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+public class StatementExecuteMethodsInterceptorTest {
+
+ @SegmentStoragePoint
+ private SegmentStorage segmentStorage;
+
+ @Rule
+ public AgentServiceRule serviceRule = new AgentServiceRule();
+
+ private StatementExecuteMethodsInterceptor interceptor;
+
+ @Mock
+ private ConnectionInfo connectionInfo;
+
+ @Mock
+ private EnhancedInstance objectInstance;
+
+ @Mock
+ private Method method;
+
+ private StatementEnhanceInfos statementEnhanceInfos;
+
+ @Before
+ public void setUp() {
+ interceptor = new StatementExecuteMethodsInterceptor();
+ statementEnhanceInfos = new StatementEnhanceInfos(connectionInfo, "SELECT * FROM test", "CallableStatement");
+ when(objectInstance.getSkyWalkingDynamicField()).thenReturn(statementEnhanceInfos);
+ when(method.getName()).thenReturn("executeQuery");
+ when(connectionInfo.getComponent()).thenReturn(ComponentsDefine.POSTGRESQL_DRIVER);
+ when(connectionInfo.getDBType()).thenReturn("POSTGRESQL");
+ when(connectionInfo.getDatabaseName()).thenReturn("test");
+ when(connectionInfo.getDatabasePeer()).thenReturn("localhost:5432");
+ }
+
+ @Test
+ public void testCreateDatabaseSpan() throws Throwable {
+ interceptor.beforeMethod(objectInstance, method, new Object[]{"SELECT * FROM test"}, null, null);
+ interceptor.afterMethod(objectInstance, method, new Object[]{"SELECT * FROM test"}, null, null);
+
+ assertThat(segmentStorage.getTraceSegments().size(), is(1));
+ TraceSegment segment = segmentStorage.getTraceSegments().get(0);
+ assertThat(SegmentHelper.getSpans(segment).size(), is(1));
+ AbstractTracingSpan span = SegmentHelper.getSpans(segment).get(0);
+ SpanAssert.assertLayer(span, SpanLayer.DB);
+ assertThat(span.getOperationName(), is("POSTGRESQL/JDBI/CallableStatement/"));
+ SpanAssert.assertTag(span, 0, "sql");
+ SpanAssert.assertTag(span, 1, "test");
+ SpanAssert.assertTag(span, 2, "SELECT * FROM test");
+ }
+}