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 2020/06/15 09:03:31 UTC
[skywalking] branch master updated: provider shardingSphere 4.0.0
4.0.1 plugin. (#4927)
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 164124f provider shardingSphere 4.0.0 4.0.1 plugin. (#4927)
164124f is described below
commit 164124fc22721c7ea99b35aa1a2f237eedb795ac
Author: xiaoyu <54...@qq.com>
AuthorDate: Mon Jun 15 17:03:17 2020 +0800
provider shardingSphere 4.0.0 4.0.1 plugin. (#4927)
---
.github/workflows/plugins-test.2.yaml | 1 +
apm-sniffer/apm-sdk-plugin/pom.xml | 1 +
.../sharding-sphere-4.0.x-plugin/pom.xml | 67 ++++++++
.../apm/plugin/shardingsphere/v40/Constant.java | 30 ++++
.../shardingsphere/v40/ExecuteInterceptor.java | 64 ++++++++
.../v40/JDBCRootInvokeInterceptor.java | 56 +++++++
.../shardingsphere/v40/ParseInterceptor.java | 57 +++++++
.../v40/ProxyRootInvokeInterceptor.java | 56 +++++++
.../AbstractShardingSphere40Instrumentation.java} | 6 +-
.../v40/define/ExecuteInstrumentation.java} | 13 +-
.../v40/define/JDBCRootInvokeInstrumentation.java} | 15 +-
.../v40}/define/ParseInstrumentation.java | 9 +-
.../define/ProxyRootInvokeInstrumentation.java} | 15 +-
.../src/main/resources/skywalking-plugin.def | 19 +++
.../apm/plugin/shardingsphere/InterceptorTest.java | 130 +++++++++++++++
.../AbstractShardingSphereV4R3Instrumentation.java | 2 +-
.../v4rc3/define/ParseInstrumentation.java | 3 +-
.../service-agent/java-agent/Supported-list.md | 2 +-
.../shardingsphere-4.0.x-scenario/bin/startup.sh | 21 +++
.../config/expectedData.yaml | 174 +++++++++++++++++++++
.../configuration.yml | 20 +++
.../shardingsphere-4.0.x-scenario/pom.xml | 154 ++++++++++++++++++
.../src/main/assembly/assembly.xml | 41 +++++
.../apm/testcase/shardingsphere/Application.java | 51 ++++++
.../shardingsphere/controller/CaseController.java | 50 ++++++
.../shardingsphere/service/api/entity/Order.java | 61 ++++++++
.../service/api/entity/OrderItem.java | 71 +++++++++
.../service/api/repository/CommonRepository.java | 38 +++++
.../api/repository/OrderItemRepository.java | 24 +++
.../service/api/repository/OrderRepository.java | 24 +++
.../service/api/service/CommonService.java | 32 ++++
.../service/api/service/CommonServiceImpl.java | 109 +++++++++++++
...dingDatabasesAndTablesConfigurationPrecise.java | 76 +++++++++
.../jdbc/JDBCOrderItemRepositoryImpl.java | 120 ++++++++++++++
.../repository/jdbc/JDBCOrderRepositoryImpl.java | 118 ++++++++++++++
.../service/repository/service/RawPojoService.java | 60 +++++++
.../PreciseModuloShardingDatabaseAlgorithm.java | 38 +++++
.../PreciseModuloShardingTableAlgorithm.java | 37 +++++
.../RangeModuloShardingDatabaseAlgorithm.java | 54 +++++++
.../RangeModuloShardingTableAlgorithm.java | 46 ++++++
.../service/utility/config/DataSourceUtil.java | 56 +++++++
.../utility/config/ExampleConfiguration.java | 29 ++++
.../src/main/resources/application.properties | 17 ++
.../support-version.list | 18 +++
44 files changed, 2050 insertions(+), 35 deletions(-)
diff --git a/.github/workflows/plugins-test.2.yaml b/.github/workflows/plugins-test.2.yaml
index 75a0a30..fd1ef98 100644
--- a/.github/workflows/plugins-test.2.yaml
+++ b/.github/workflows/plugins-test.2.yaml
@@ -45,6 +45,7 @@ jobs:
- { name: 'shardingsphere-3.x-scenario', title: 'ShardingSphere 3.0.0 (1)' }
- { name: 'shardingsphere-4.x-RC1-RC2-scenario', title: 'ShardingSphere 4.0.0-RC1-4.0.0-RC2 (2)' }
- { name: 'shardingsphere-4.x-RC3-scenario', title: 'ShardingSphere 4.0.0-RC3 (1)' }
+ - { name: 'shardingsphere-4.0.x-scenario', title: 'ShardingSphere 4.0.0-4.0.1 (2)' }
- { name: 'shardingsphere-4.x-scenario', title: 'ShardingSphere 4.1.0-4.1.1 (2)' }
- { name: 'sofarpc-scenario', title: 'SofaRPC 5.4.0-5.6.2 (23)' }
- { name: 'solrj-7.x-scenario', title: 'SolrJ 7.x (12)' }
diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml
index 75c317b..4520b78 100644
--- a/apm-sniffer/apm-sdk-plugin/pom.xml
+++ b/apm-sniffer/apm-sdk-plugin/pom.xml
@@ -47,6 +47,7 @@
<module>sharding-sphere-3.x-plugin</module>
<module>sharding-sphere-4.x-plugin</module>
<module>sharding-sphere-4.x-RC3-plugin</module>
+ <module>sharding-sphere-4.0.x-plugin</module>
<module>sharding-sphere-4.1.0-plugin</module>
<module>xmemcached-2.x-plugin</module>
<module>grpc-1.x-plugin</module>
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/pom.xml
new file mode 100644
index 0000000..266e843
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/pom.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ ~
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>apm-sdk-plugin</artifactId>
+ <groupId>org.apache.skywalking</groupId>
+ <version>8.1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>apm-shardingsphere-4.0.x-plugin</artifactId>
+
+
+ <packaging>jar</packaging>
+ <name>sharding-sphere-4.0.x-plugin</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <shardingsphere.version>4.0.0</shardingsphere.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>[2.0.14,6.0.6]</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>sharding-core-execute</artifactId>
+ <version>${shardingsphere.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>sharding-jdbc-core</artifactId>
+ <version>${shardingsphere.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-sql-parser-engine</artifactId>
+ <version>${shardingsphere.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/Constant.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/Constant.java
new file mode 100644
index 0000000..755c3bb
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/Constant.java
@@ -0,0 +1,30 @@
+/*
+ * 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.shardingsphere.v40;
+
+/**
+ * The type Constant.
+ */
+public final class Constant {
+
+ /**
+ * The constant CONTEXT_SNAPSHOT.
+ */
+ public static final String CONTEXT_SNAPSHOT = "CONTEXT_SNAPSHOT";
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ExecuteInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ExecuteInterceptor.java
new file mode 100644
index 0000000..4528183
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ExecuteInterceptor.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.
+ *
+ */
+
+package org.apache.skywalking.apm.plugin.shardingsphere.v40;
+
+import org.apache.shardingsphere.core.execute.engine.ShardingExecuteDataMap;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+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.network.trace.component.ComponentsDefine;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * {@link ExecuteInterceptor} enhances. {@link org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback}
+ * creating a local span that records the execution of sql.
+ */
+public class ExecuteInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+ MethodInterceptResult result) {
+ ContextManager.createLocalSpan("/ShardingSphere/executeSQL/").setComponent(ComponentsDefine.SHARDING_SPHERE);
+ ContextSnapshot contextSnapshot = (ContextSnapshot) ShardingExecuteDataMap.getDataMap()
+ .get(Constant.CONTEXT_SNAPSHOT);
+ if (null == contextSnapshot) {
+ contextSnapshot = (ContextSnapshot) ((Map) allArguments[2]).get(Constant.CONTEXT_SNAPSHOT);
+ }
+ if (null != contextSnapshot) {
+ ContextManager.continued(contextSnapshot);
+ }
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+ Object ret) {
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class<?>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().errorOccurred().log(t);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/JDBCRootInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/JDBCRootInvokeInterceptor.java
new file mode 100644
index 0000000..fad49e3
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/JDBCRootInvokeInterceptor.java
@@ -0,0 +1,56 @@
+/*
+ * 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.shardingsphere.v40;
+
+import org.apache.shardingsphere.core.execute.engine.ShardingExecuteDataMap;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+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.network.trace.component.ComponentsDefine;
+
+import java.lang.reflect.Method;
+
+/**
+ * {@link JDBCRootInvokeInterceptor} enhances {@link org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor},
+ * creating a local span that records the overall execution of sql.
+ */
+public class JDBCRootInvokeInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+ MethodInterceptResult result) {
+ ContextManager.createLocalSpan("/ShardingSphere/JDBCRootInvoke/")
+ .setComponent(ComponentsDefine.SHARDING_SPHERE);
+ ShardingExecuteDataMap.getDataMap().put(Constant.CONTEXT_SNAPSHOT, ContextManager.capture());
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+ Object ret) {
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class<?>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().errorOccurred().log(t);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ParseInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ParseInterceptor.java
new file mode 100644
index 0000000..9859f50
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ParseInterceptor.java
@@ -0,0 +1,57 @@
+/*
+ * 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.shardingsphere.v40;
+
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.context.tag.Tags;
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+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.network.trace.component.ComponentsDefine;
+
+import java.lang.reflect.Method;
+
+/**
+ * {@link ParseInterceptor} enhances {@link org.apache.shardingsphere.core.route.router.sharding.ShardingRouter}.
+ * creating a local span that records the parse of sql.
+ */
+public class ParseInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+ MethodInterceptResult result) {
+ AbstractSpan span = ContextManager.createLocalSpan("/ShardingSphere/parseSQL/")
+ .setComponent(ComponentsDefine.SHARDING_SPHERE);
+ Tags.DB_STATEMENT.set(span, (String) allArguments[0]);
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+ Object ret) {
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class<?>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().errorOccurred().log(t);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ProxyRootInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ProxyRootInvokeInterceptor.java
new file mode 100644
index 0000000..4f416f6
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/ProxyRootInvokeInterceptor.java
@@ -0,0 +1,56 @@
+/*
+ * 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.shardingsphere.v40;
+
+import org.apache.shardingsphere.core.execute.engine.ShardingExecuteDataMap;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+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.network.trace.component.ComponentsDefine;
+
+import java.lang.reflect.Method;
+
+/**
+ * ProxyRootInvokeInterceptor enhances. skywalking intercepts org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask
+ * creating a local span that records the overall execution of sql.
+ */
+public class ProxyRootInvokeInterceptor implements InstanceMethodsAroundInterceptor {
+
+ @Override
+ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+ MethodInterceptResult result) {
+ ContextManager.createLocalSpan("/ShardingSphere/ProxyRootInvoke/")
+ .setComponent(ComponentsDefine.SHARDING_SPHERE);
+ ShardingExecuteDataMap.getDataMap().put(Constant.CONTEXT_SNAPSHOT, ContextManager.capture());
+ }
+
+ @Override
+ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+ Object ret) {
+ ContextManager.stopSpan();
+ return ret;
+ }
+
+ @Override
+ public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
+ Class<?>[] argumentsTypes, Throwable t) {
+ ContextManager.activeSpan().errorOccurred().log(t);
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/AbstractShardingSphereV4R3Instrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/AbstractShardingSphere40Instrumentation.java
similarity index 82%
copy from apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/AbstractShardingSphereV4R3Instrumentation.java
copy to apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/AbstractShardingSphere40Instrumentation.java
index c44965a..9afe2be 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/AbstractShardingSphereV4R3Instrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/AbstractShardingSphere40Instrumentation.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.define;
+package org.apache.skywalking.apm.plugin.shardingsphere.v40.define;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
-public abstract class AbstractShardingSphereV4R3Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
- public static final String WITHNESS_CLASSES = "org.apache.shardingsphere.core.route.router.sharding.ShardingRouter";
+public abstract class AbstractShardingSphere40Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+ public static final String WITHNESS_CLASSES = "org.apache.shardingsphere.sql.parser.SQLParseEngine";
@Override
protected final String[] witnessClasses() {
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ExecuteInstrumentation.java
similarity index 80%
copy from apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
copy to apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ExecuteInstrumentation.java
index 4e1c4b7..7a2f70f 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ExecuteInstrumentation.java
@@ -16,26 +16,25 @@
*
*/
-package org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.define;
+package org.apache.skywalking.apm.plugin.shardingsphere.v40.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
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.agent.core.plugin.match.NameMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
- * {@link ParseInstrumentation} presents that skywalking intercepts {@link org.apache.shardingsphere.core.route.router.sharding.ShardingRouter}.
+ * {@link ExecuteInstrumentation} presents that skywalking intercepts. {@link org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback}.
*/
-public class ParseInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+public class ExecuteInstrumentation extends AbstractShardingSphere40Instrumentation {
- private static final String ENHANCE_CLASS = "org.apache.shardingsphere.core.route.router.sharding.ShardingRouter";
+ private static final String ENHANCE_CLASS = "org.apache.shardingsphere.core.execute.sql.execute.SQLExecuteCallback";
- private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.ParseInterceptor";
+ private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v40.ExecuteInterceptor";
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
@@ -43,7 +42,7 @@ public class ParseInstrumentation extends ClassInstanceMethodsEnhancePluginDefin
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
- return named("parse");
+ return named("execute0");
}
@Override
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/JDBCRootInvokeInstrumentation.java
similarity index 75%
copy from apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
copy to apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/JDBCRootInvokeInstrumentation.java
index 4e1c4b7..e01fd8e 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/JDBCRootInvokeInstrumentation.java
@@ -16,26 +16,25 @@
*
*/
-package org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.define;
+package org.apache.skywalking.apm.plugin.shardingsphere.v40.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
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.agent.core.plugin.match.NameMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
- * {@link ParseInstrumentation} presents that skywalking intercepts {@link org.apache.shardingsphere.core.route.router.sharding.ShardingRouter}.
+ * {@link JDBCRootInvokeInstrumentation} presents that skywalking intercepts. {@link org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor}.
*/
-public class ParseInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+public class JDBCRootInvokeInstrumentation extends AbstractShardingSphere40Instrumentation {
- private static final String ENHANCE_CLASS = "org.apache.shardingsphere.core.route.router.sharding.ShardingRouter";
+ private static final String ENHANCE_CLASS = "org.apache.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor";
- private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.ParseInterceptor";
+ private static final String JDBC_ROOT_INVOKE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v40.JDBCRootInvokeInterceptor";
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
@@ -43,12 +42,12 @@ public class ParseInstrumentation extends ClassInstanceMethodsEnhancePluginDefin
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
- return named("parse");
+ return named("executeCallback");
}
@Override
public String getMethodsInterceptor() {
- return EXECUTE_INTERCEPTOR_CLASS;
+ return JDBC_ROOT_INVOKE_INTERCEPTOR_CLASS;
}
@Override
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ParseInstrumentation.java
similarity index 88%
copy from apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
copy to apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ParseInstrumentation.java
index 4e1c4b7..0c5c386 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ParseInstrumentation.java
@@ -16,13 +16,12 @@
*
*/
-package org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.define;
+package org.apache.skywalking.apm.plugin.shardingsphere.v40.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
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.agent.core.plugin.match.NameMatch;
@@ -31,11 +30,11 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link ParseInstrumentation} presents that skywalking intercepts {@link org.apache.shardingsphere.core.route.router.sharding.ShardingRouter}.
*/
-public class ParseInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
-
+public class ParseInstrumentation extends AbstractShardingSphere40Instrumentation {
+
private static final String ENHANCE_CLASS = "org.apache.shardingsphere.core.route.router.sharding.ShardingRouter";
- private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.ParseInterceptor";
+ private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v40.ParseInterceptor";
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ProxyRootInvokeInstrumentation.java
similarity index 75%
copy from apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
copy to apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ProxyRootInvokeInstrumentation.java
index 4e1c4b7..7b78756 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v40/define/ProxyRootInvokeInstrumentation.java
@@ -16,26 +16,25 @@
*
*/
-package org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.define;
+package org.apache.skywalking.apm.plugin.shardingsphere.v40.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
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.agent.core.plugin.match.NameMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
- * {@link ParseInstrumentation} presents that skywalking intercepts {@link org.apache.shardingsphere.core.route.router.sharding.ShardingRouter}.
+ * ProxyRootInvokeInstrumentation presents that skywalking intercepts. skywalking intercepts org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask.
*/
-public class ParseInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+public class ProxyRootInvokeInstrumentation extends AbstractShardingSphere40Instrumentation {
- private static final String ENHANCE_CLASS = "org.apache.shardingsphere.core.route.router.sharding.ShardingRouter";
+ private static final String ENHANCE_CLASS = "org.apache.shardingsphere.shardingproxy.frontend.command.CommandExecutorTask";
- private static final String EXECUTE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.ParseInterceptor";
+ private static final String PROXY_ROOT_INVOKE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.shardingsphere.v40.ProxyRootInvokeInterceptor";
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
@@ -43,12 +42,12 @@ public class ParseInstrumentation extends ClassInstanceMethodsEnhancePluginDefin
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
- return named("parse");
+ return named("run");
}
@Override
public String getMethodsInterceptor() {
- return EXECUTE_INTERCEPTOR_CLASS;
+ return PROXY_ROOT_INVOKE_INTERCEPTOR_CLASS;
}
@Override
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/resources/skywalking-plugin.def
new file mode 100644
index 0000000..636580a
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/main/resources/skywalking-plugin.def
@@ -0,0 +1,19 @@
+# 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.
+sharding-sphere-4.0.0=org.apache.skywalking.apm.plugin.shardingsphere.v40.define.ProxyRootInvokeInstrumentation
+sharding-sphere-4.0.0=org.apache.skywalking.apm.plugin.shardingsphere.v40.define.JDBCRootInvokeInstrumentation
+sharding-sphere-4.0.0=org.apache.skywalking.apm.plugin.shardingsphere.v40.define.ParseInstrumentation
+sharding-sphere-4.0.0=org.apache.skywalking.apm.plugin.shardingsphere.v40.define.ExecuteInstrumentation
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/shardingsphere/InterceptorTest.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/shardingsphere/InterceptorTest.java
new file mode 100644
index 0000000..cb315e5
--- /dev/null
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.0.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/shardingsphere/InterceptorTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.shardingsphere;
+
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
+import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
+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.plugin.shardingsphere.v40.ExecuteInterceptor;
+import org.apache.skywalking.apm.plugin.shardingsphere.v40.JDBCRootInvokeInterceptor;
+import org.apache.skywalking.apm.plugin.shardingsphere.v40.ParseInterceptor;
+import org.apache.skywalking.apm.plugin.shardingsphere.v40.ProxyRootInvokeInterceptor;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+
+import java.util.HashMap;
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(TracingSegmentRunner.class)
+public class InterceptorTest {
+
+ @SegmentStoragePoint
+ private SegmentStorage segmentStorage;
+
+ @Rule
+ public AgentServiceRule serviceRule = new AgentServiceRule();
+
+ private ProxyRootInvokeInterceptor proxyRootInvokeInterceptor;
+
+ private JDBCRootInvokeInterceptor jdbcRootInvokeInterceptor;
+
+ private ParseInterceptor parseInterceptor;
+
+ private ExecuteInterceptor executeInterceptor;
+
+ @Before
+ public void setUp() {
+ proxyRootInvokeInterceptor = new ProxyRootInvokeInterceptor();
+ jdbcRootInvokeInterceptor = new JDBCRootInvokeInterceptor();
+ parseInterceptor = new ParseInterceptor();
+ executeInterceptor = new ExecuteInterceptor();
+ }
+
+ @Test
+ public void assertProxyRootInvoke() {
+ proxyRootInvokeInterceptor.beforeMethod(null, null, null, null, null);
+ proxyRootInvokeInterceptor.afterMethod(null, null, null, null, null);
+ assertThat(segmentStorage.getTraceSegments().size(), is(1));
+ TraceSegment segment = segmentStorage.getTraceSegments().get(0);
+ List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
+ assertNotNull(spans);
+ assertThat(spans.size(), is(1));
+ assertThat(spans.get(0).getOperationName(), is("/ShardingSphere/ProxyRootInvoke/"));
+ }
+
+ @Test
+ public void assertJDBCRootInvoke() {
+ jdbcRootInvokeInterceptor.beforeMethod(null, null, null, null, null);
+ jdbcRootInvokeInterceptor.afterMethod(null, null, null, null, null);
+ assertThat(segmentStorage.getTraceSegments().size(), is(1));
+ TraceSegment segment = segmentStorage.getTraceSegments().get(0);
+ List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
+ assertNotNull(spans);
+ assertThat(spans.size(), is(1));
+ assertThat(spans.get(0).getOperationName(), is("/ShardingSphere/JDBCRootInvoke/"));
+ }
+
+ @Test
+ public void assertParse() {
+ Object[] allArguments = new Object[] {
+ "SELECT * FROM t_order",
+ false
+ };
+ parseInterceptor.beforeMethod(null, null, allArguments, null, null);
+ parseInterceptor.afterMethod(null, null, allArguments, null, null);
+ assertThat(segmentStorage.getTraceSegments().size(), is(1));
+ TraceSegment segment = segmentStorage.getTraceSegments().get(0);
+ List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
+ assertNotNull(spans);
+ assertThat(spans.size(), is(1));
+ assertThat(spans.get(0).getOperationName(), is("/ShardingSphere/parseSQL/"));
+ SpanAssert.assertTag(spans.get(0), 0, "SELECT * FROM t_order");
+ }
+
+ @Test
+ public void assertExecute() {
+ Object[] allArguments = new Object[] {
+ null,
+ null,
+ new HashMap<Object, Object>()
+ };
+ executeInterceptor.beforeMethod(null, null, allArguments, null, null);
+ executeInterceptor.afterMethod(null, null, allArguments, null, null);
+ assertThat(segmentStorage.getTraceSegments().size(), is(1));
+ TraceSegment segment = segmentStorage.getTraceSegments().get(0);
+ List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
+ assertNotNull(spans);
+ assertThat(spans.size(), is(1));
+ assertThat(spans.get(0).getOperationName(), is("/ShardingSphere/executeSQL/"));
+ }
+}
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/AbstractShardingSphereV4R3Instrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/AbstractShardingSphereV4R3Instrumentation.java
index c44965a..aab7140 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/AbstractShardingSphereV4R3Instrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/AbstractShardingSphereV4R3Instrumentation.java
@@ -20,7 +20,7 @@ package org.apache.skywalking.apm.plugin.shardingsphere.v4rc3.define;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
public abstract class AbstractShardingSphereV4R3Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
- public static final String WITHNESS_CLASSES = "org.apache.shardingsphere.core.route.router.sharding.ShardingRouter";
+ public static final String WITHNESS_CLASSES = "org.apache.shardingsphere.core.parse.SQLParseEngine";
@Override
protected final String[] witnessClasses() {
diff --git a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
index 4e1c4b7..c842de4 100644
--- a/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
+++ b/apm-sniffer/apm-sdk-plugin/sharding-sphere-4.x-RC3-plugin/src/main/java/org/apache/skywalking/apm/plugin/shardingsphere/v4rc3/define/ParseInstrumentation.java
@@ -22,7 +22,6 @@ import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
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.agent.core.plugin.match.NameMatch;
@@ -31,7 +30,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link ParseInstrumentation} presents that skywalking intercepts {@link org.apache.shardingsphere.core.route.router.sharding.ShardingRouter}.
*/
-public class ParseInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
+public class ParseInstrumentation extends AbstractShardingSphereV4R3Instrumentation {
private static final String ENHANCE_CLASS = "org.apache.shardingsphere.core.route.router.sharding.ShardingRouter";
diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md
index 1047985..28d9ca2 100644
--- a/docs/en/setup/service-agent/java-agent/Supported-list.md
+++ b/docs/en/setup/service-agent/java-agent/Supported-list.md
@@ -30,7 +30,7 @@
* Oracle Driver (Optional¹)
* H2 Driver 1.3.x -> 1.4.x
* [Sharding-JDBC](https://github.com/shardingjdbc/sharding-jdbc) 1.5.x
- * [ShardingSphere](https://github.com/apache/shardingsphere) 3.0.0, 4.0.0-RC1, 4.1.0, 4.1.1
+ * [ShardingSphere](https://github.com/apache/shardingsphere) 3.0.0, 4.0.0-RC1, 4.0.0, 4.0.1, 4.1.0, 4.1.1
* PostgreSQL Driver 8.x, 9.x, 42.x
* Mariadb Driver 2.x, 1.8
* RPC Frameworks
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/bin/startup.sh b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/bin/startup.sh
new file mode 100644
index 0000000..979ddf9
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/bin/startup.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# 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.
+
+home="$(cd "$(dirname $0)"; pwd)"
+
+java -jar ${agent_opts} ${home}/../libs/shardingsphere-4.0.x-scenario.jar &
\ No newline at end of file
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/config/expectedData.yaml
new file mode 100644
index 0000000..655dc10
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/config/expectedData.yaml
@@ -0,0 +1,174 @@
+# 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.
+segmentItems:
+- serviceName: shardingsphere-4.0.x-scenario
+ segmentSize: not null
+ segments:
+ - segmentId: not null
+ spans:
+ - operationName: H2/JDBI/PreparedStatement/executeQuery
+ operationId: 0
+ parentSpanId: 0
+ spanId: 1
+ spanLayer: Database
+ startTime: not null
+ endTime: not null
+ componentId: 32
+ isError: false
+ spanType: Exit
+ peer: localhost:-1
+ tags:
+ - {key: db.type, value: sql}
+ - {key: db.instance, value: demo_ds_1}
+ - {key: db.statement, value: SELECT * FROM t_order_1}
+ skipAnalysis: 'false'
+ - operationName: /ShardingSphere/executeSQL/
+ operationId: 0
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Unknown
+ startTime: not null
+ endTime: not null
+ componentId: 60
+ isError: false
+ spanType: Local
+ peer: ''
+ refs:
+ - {parentEndpoint: /shardingsphere-4.0.x-scenario/case/execute, networkAddress: '',
+ refType: CrossThread, parentSpanId: 2, parentTraceSegmentId: not null, parentServiceInstance: not
+ null, parentService: not null, traceId: not null}
+ skipAnalysis: 'false'
+ - segmentId: not null
+ spans:
+ - operationName: H2/JDBI/PreparedStatement/executeQuery
+ operationId: 0
+ parentSpanId: 0
+ spanId: 1
+ spanLayer: Database
+ startTime: not null
+ endTime: not null
+ componentId: 32
+ isError: false
+ spanType: Exit
+ peer: localhost:-1
+ tags:
+ - {key: db.type, value: sql}
+ - {key: db.instance, value: demo_ds_0}
+ - {key: db.statement, value: SELECT * FROM t_order_1}
+ skipAnalysis: 'false'
+ - operationName: /ShardingSphere/executeSQL/
+ operationId: 0
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Unknown
+ startTime: not null
+ endTime: not null
+ componentId: 60
+ isError: false
+ spanType: Local
+ peer: ''
+ refs:
+ - {parentEndpoint: /shardingsphere-4.0.x-scenario/case/execute, networkAddress: '',
+ refType: CrossThread, parentSpanId: 2, parentTraceSegmentId: not null, parentServiceInstance: not
+ null, parentService: not null, traceId: not null}
+ skipAnalysis: 'false'
+ - segmentId: not null
+ spans:
+ - operationName: H2/JDBI/PreparedStatement/executeQuery
+ operationId: 0
+ parentSpanId: 0
+ spanId: 1
+ spanLayer: Database
+ startTime: not null
+ endTime: not null
+ componentId: 32
+ isError: false
+ spanType: Exit
+ peer: localhost:-1
+ tags:
+ - {key: db.type, value: sql}
+ - {key: db.instance, value: demo_ds_1}
+ - {key: db.statement, value: SELECT * FROM t_order_0}
+ skipAnalysis: 'false'
+ - operationName: /ShardingSphere/executeSQL/
+ operationId: 0
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Unknown
+ startTime: not null
+ endTime: not null
+ componentId: 60
+ isError: false
+ spanType: Local
+ peer: ''
+ refs:
+ - {parentEndpoint: /shardingsphere-4.0.x-scenario/case/execute, networkAddress: '',
+ refType: CrossThread, parentSpanId: 2, parentTraceSegmentId: not null, parentServiceInstance: not
+ null, parentService: shardingsphere-4.0.x-scenario, traceId: not null}
+ skipAnalysis: 'false'
+ - segmentId: not null
+ spans:
+ - operationName: /ShardingSphere/parseSQL/
+ operationId: 0
+ parentSpanId: 0
+ spanId: 1
+ spanLayer: Unknown
+ startTime: not null
+ endTime: not null
+ componentId: 60
+ isError: false
+ spanType: Local
+ peer: ''
+ tags:
+ - {key: db.statement, value: SELECT * FROM t_order}
+ skipAnalysis: 'false'
+ - operationName: H2/JDBI/PreparedStatement/executeQuery
+ operationId: 0
+ parentSpanId: 3
+ spanId: 4
+ spanLayer: Database
+ startTime: not null
+ endTime: not null
+ componentId: 32
+ isError: false
+ spanType: Exit
+ peer: localhost:-1
+ tags:
+ - {key: db.type, value: sql}
+ - {key: db.instance, value: demo_ds_0}
+ - {key: db.statement, value: SELECT * FROM t_order_0}
+ skipAnalysis: 'false'
+ - {operationName: /ShardingSphere/executeSQL/, operationId: 0, parentSpanId: 2,
+ spanId: 3, spanLayer: Unknown, startTime: not null, endTime: not null, componentId: 60,
+ isError: false, spanType: Local, peer: '', skipAnalysis: 'false'}
+ - {operationName: /ShardingSphere/JDBCRootInvoke/, operationId: 0, parentSpanId: 0,
+ spanId: 2, spanLayer: Unknown, startTime: not null, endTime: not null, componentId: 60,
+ isError: false, spanType: Local, peer: '', skipAnalysis: 'false'}
+ - operationName: /shardingsphere-4.0.x-scenario/case/execute
+ operationId: 0
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Http
+ startTime: not null
+ endTime: not null
+ componentId: 1
+ isError: false
+ spanType: Entry
+ peer: ''
+ tags:
+ - {key: url, value: 'http://localhost:8080/shardingsphere-4.0.x-scenario/case/execute'}
+ - {key: http.method, value: GET}
+ skipAnalysis: 'false'
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/configuration.yml b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/configuration.yml
new file mode 100644
index 0000000..192a096
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/configuration.yml
@@ -0,0 +1,20 @@
+# 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.
+
+type: jvm
+entryService: http://localhost:8080/shardingsphere-4.0.x-scenario/case/execute
+healthCheck: http://localhost:8080/shardingsphere-4.0.x-scenario/case/healthCheck
+startScript: ./bin/startup.sh
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/pom.xml b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/pom.xml
new file mode 100644
index 0000000..b9a578f
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/pom.xml
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ ~
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.example</groupId>
+ <artifactId>shardingsphere-4.0.x-scenario</artifactId>
+ <version>5.0.0</version>
+
+ <name>skywalking-shardingsphere-4.0.x-scenario</name>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <test.framework.version>4.0.0</test.framework.version>
+
+ <log4j.version>2.6.2</log4j.version>
+ <spring.version>4.3.8.RELEASE</spring.version>
+ <spring-boot-version>1.5.2.RELEASE</spring-boot-version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>sharding-core-execute</artifactId>
+ <version>${test.framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>sharding-jdbc-core</artifactId>
+ <version>${test.framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-dbcp2</artifactId>
+ <version>2.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <version>${spring-boot-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-jcl</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-tomcat</artifactId>
+ <version>${spring-boot-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <version>${spring-boot-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.4.196</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>shardingsphere-4.0.x-scenario</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.6.0</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>1.5.9.RELEASE</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>assemble</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/assembly.xml</descriptor>
+ </descriptors>
+ <outputDirectory>./target/</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>spring-snapshots</id>
+ <url>http://repo.spring.io/snapshot</url>
+ </pluginRepository>
+ <pluginRepository>
+ <id>spring-milestones</id>
+ <url>http://repo.spring.io/milestone</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+</project>
\ No newline at end of file
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/assembly/assembly.xml
new file mode 100644
index 0000000..fd6471b
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/assembly/assembly.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ ~
+ -->
+<assembly
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <fileSets>
+ <fileSet>
+ <directory>./bin</directory>
+ <fileMode>0775</fileMode>
+ </fileSet>
+ </fileSets>
+
+ <files>
+ <file>
+ <source>${project.build.directory}/shardingsphere-4.0.x-scenario.jar</source>
+ <outputDirectory>./libs</outputDirectory>
+ <fileMode>0775</fileMode>
+ </file>
+ </files>
+</assembly>
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/Application.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/Application.java
new file mode 100644
index 0000000..6bda0f1
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/Application.java
@@ -0,0 +1,51 @@
+/*
+ * 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.testcase.shardingsphere;
+
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.service.CommonService;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.config.ShardingDatabasesAndTablesConfigurationPrecise;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service.RawPojoService;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.DataSourceUtil;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.support.SpringBootServletInitializer;
+
+import javax.sql.DataSource;
+
+@SpringBootApplication
+public class Application extends SpringBootServletInitializer {
+
+ public static void main(String[] args) {
+ try {
+ DataSourceUtil.createDataSource("");
+ DataSourceUtil.createSchema("demo_ds_0");
+ DataSourceUtil.createSchema("demo_ds_1");
+ DataSourceUtil.createDataSource("demo_ds_0");
+ DataSourceUtil.createDataSource("demo_ds_1");
+ DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
+ CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
+ commonService.initEnvironment();
+ SpringApplication.run(Application.class, args);
+ } catch (Exception e) {
+ // Never do this
+ }
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/controller/CaseController.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/controller/CaseController.java
new file mode 100644
index 0000000..ebc5f00
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/controller/CaseController.java
@@ -0,0 +1,50 @@
+/*
+ * 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.testcase.shardingsphere.controller;
+
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.service.CommonService;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.config.ShardingDatabasesAndTablesConfigurationPrecise;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service.RawPojoService;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.sql.DataSource;
+
+@RestController
+@RequestMapping("/case")
+public class CaseController {
+
+ @RequestMapping("/healthCheck")
+ @ResponseBody
+ public String healthCheck() {
+ return "Success";
+ }
+
+ @RequestMapping("/execute")
+ @ResponseBody
+ public String execute() {
+ DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().getDataSource();
+ CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
+ commonService.processSuccess(false);
+ return "Success";
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/Order.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/Order.java
new file mode 100644
index 0000000..5d00a35
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/Order.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.
+ *
+ */
+
+package org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity;
+
+import java.io.Serializable;
+
+public class Order implements Serializable {
+
+ private static final long serialVersionUID = 661434701950670670L;
+
+ private long orderId;
+
+ private int userId;
+
+ private String status;
+
+ public long getOrderId() {
+ return orderId;
+ }
+
+ public void setOrderId(final long orderId) {
+ this.orderId = orderId;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(final int userId) {
+ this.userId = userId;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("order_id: %s, user_id: %s, status: %s", orderId, userId, status);
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/OrderItem.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/OrderItem.java
new file mode 100644
index 0000000..8ffa5b9
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/entity/OrderItem.java
@@ -0,0 +1,71 @@
+/*
+ * 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.testcase.shardingsphere.service.api.entity;
+
+import java.io.Serializable;
+
+public class OrderItem implements Serializable {
+
+ private static final long serialVersionUID = 263434701950670170L;
+
+ private long orderItemId;
+
+ private long orderId;
+
+ private int userId;
+
+ private String status;
+
+ public long getOrderItemId() {
+ return orderItemId;
+ }
+
+ public void setOrderItemId(final long orderItemId) {
+ this.orderItemId = orderItemId;
+ }
+
+ public long getOrderId() {
+ return orderId;
+ }
+
+ public void setOrderId(final long orderId) {
+ this.orderId = orderId;
+ }
+
+ public int getUserId() {
+ return userId;
+ }
+
+ public void setUserId(final int userId) {
+ this.userId = userId;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("order_item_id:%s, order_id: %s, user_id: %s, status: %s", orderItemId, orderId, userId, status);
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/CommonRepository.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/CommonRepository.java
new file mode 100644
index 0000000..51da35e
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/CommonRepository.java
@@ -0,0 +1,38 @@
+/*
+ * 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.testcase.shardingsphere.service.api.repository;
+
+import java.util.List;
+
+public interface CommonRepository<T> {
+
+ void createTableIfNotExists();
+
+ void dropTable();
+
+ void truncateTable();
+
+ Long insert(T entity);
+
+ void delete(Long id);
+
+ List<T> selectAll();
+
+ List<T> selectRange();
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderItemRepository.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderItemRepository.java
new file mode 100644
index 0000000..ded0048
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderItemRepository.java
@@ -0,0 +1,24 @@
+/*
+ * 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.testcase.shardingsphere.service.api.repository;
+
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity.OrderItem;
+
+public interface OrderItemRepository extends CommonRepository<OrderItem> {
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderRepository.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderRepository.java
new file mode 100644
index 0000000..95e55a7
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/repository/OrderRepository.java
@@ -0,0 +1,24 @@
+/*
+ * 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.testcase.shardingsphere.service.api.repository;
+
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity.Order;
+
+public interface OrderRepository extends CommonRepository<Order> {
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonService.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonService.java
new file mode 100644
index 0000000..066f122
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.testcase.shardingsphere.service.api.service;
+
+public interface CommonService {
+
+ void initEnvironment();
+
+ void cleanEnvironment();
+
+ void processSuccess(boolean isRangeSharding);
+
+ void processFailure();
+
+ void printData(boolean isRangeSharding);
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonServiceImpl.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonServiceImpl.java
new file mode 100644
index 0000000..52cdd89
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/api/service/CommonServiceImpl.java
@@ -0,0 +1,109 @@
+/*
+ * 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.testcase.shardingsphere.service.api.service;
+
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity.Order;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity.OrderItem;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.OrderItemRepository;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.OrderRepository;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class CommonServiceImpl implements CommonService {
+
+ @Override
+ public void initEnvironment() {
+ getOrderRepository().createTableIfNotExists();
+ getOrderItemRepository().createTableIfNotExists();
+ getOrderRepository().truncateTable();
+ getOrderItemRepository().truncateTable();
+ insertData();
+ }
+
+ @Override
+ public void cleanEnvironment() {
+ getOrderRepository().dropTable();
+ getOrderItemRepository().dropTable();
+ }
+
+ @Override
+ public void processSuccess(final boolean isRangeSharding) {
+ printData(isRangeSharding);
+ }
+
+ @Override
+ public void processFailure() {
+ insertData();
+ throw new RuntimeException("Exception occur for transaction test.");
+ }
+
+ private List<Long> insertData() {
+ List<Long> result = new ArrayList<>(10);
+ for (int i = 1; i <= 10; i++) {
+ Order order = newOrder();
+ order.setUserId(i);
+ order.setStatus("INSERT_TEST");
+ getOrderRepository().insert(order);
+ OrderItem item = newOrderItem();
+ item.setOrderId(order.getOrderId());
+ item.setUserId(i);
+ item.setStatus("INSERT_TEST");
+ getOrderItemRepository().insert(item);
+ result.add(order.getOrderId());
+ }
+ return result;
+ }
+
+ private void deleteData(final List<Long> orderIds) {
+ for (Long each : orderIds) {
+ getOrderRepository().delete(each);
+ getOrderItemRepository().delete(each);
+ }
+ }
+
+ @Override
+ public void printData(final boolean isRangeSharding) {
+ if (isRangeSharding) {
+ printDataRange();
+ } else {
+ printDataAll();
+ }
+ }
+
+ private void printDataRange() {
+ for (Object each : getOrderRepository().selectRange()) {
+ }
+ for (Object each : getOrderItemRepository().selectRange()) {
+ }
+ }
+
+ private void printDataAll() {
+ for (Object each : getOrderRepository().selectAll()) {
+ }
+ }
+
+ protected abstract OrderRepository getOrderRepository();
+
+ protected abstract OrderItemRepository getOrderItemRepository();
+
+ protected abstract Order newOrder();
+
+ protected abstract OrderItem newOrderItem();
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/config/ShardingDatabasesAndTablesConfigurationPrecise.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/config/ShardingDatabasesAndTablesConfigurationPrecise.java
new file mode 100644
index 0000000..29c0593
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/config/ShardingDatabasesAndTablesConfigurationPrecise.java
@@ -0,0 +1,76 @@
+/*
+ * 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.testcase.shardingsphere.service.config;
+
+import org.apache.shardingsphere.api.config.sharding.KeyGeneratorConfiguration;
+import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;
+import org.apache.shardingsphere.api.config.sharding.TableRuleConfiguration;
+import org.apache.shardingsphere.api.config.sharding.strategy.InlineShardingStrategyConfiguration;
+import org.apache.shardingsphere.api.config.sharding.strategy.StandardShardingStrategyConfiguration;
+import org.apache.shardingsphere.shardingjdbc.api.ShardingDataSourceFactory;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.algorithm.PreciseModuloShardingTableAlgorithm;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.DataSourceUtil;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.ExampleConfiguration;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+public final class ShardingDatabasesAndTablesConfigurationPrecise implements ExampleConfiguration {
+
+ private static DataSource dataSource;
+
+ @Override
+ public DataSource createDataSource() throws SQLException {
+ ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
+ shardingRuleConfig.getTableRuleConfigs().add(getOrderTableRuleConfiguration());
+ shardingRuleConfig.getTableRuleConfigs().add(getOrderItemTableRuleConfiguration());
+ shardingRuleConfig.getBindingTableGroups().add("t_order, t_order_item");
+ shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new InlineShardingStrategyConfiguration("user_id", "demo_ds_${user_id % 2}"));
+ shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("order_id", new PreciseModuloShardingTableAlgorithm()));
+ Properties properties = new Properties();
+ properties.setProperty("max.connections.size.per.query", "16");
+ dataSource = ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, properties);
+ return dataSource;
+ }
+
+ @Override
+ public DataSource getDataSource() {
+ return dataSource;
+ }
+
+ private static TableRuleConfiguration getOrderTableRuleConfiguration() {
+ TableRuleConfiguration result = new TableRuleConfiguration("t_order", "demo_ds_${0..1}.t_order_${[0, 1]}");
+ result.setKeyGeneratorConfig(new KeyGeneratorConfiguration("SNOWFLAKE", "order_id"));
+ return result;
+ }
+
+ private static TableRuleConfiguration getOrderItemTableRuleConfiguration() {
+ return new TableRuleConfiguration("t_order_item", "demo_ds_${0..1}.t_order_item_${[0, 1]}");
+ }
+
+ private static Map<String, DataSource> createDataSourceMap() {
+ Map<String, DataSource> result = new HashMap<>();
+ result.put("demo_ds_0", DataSourceUtil.getDataSource("demo_ds_0"));
+ result.put("demo_ds_1", DataSourceUtil.getDataSource("demo_ds_1"));
+ return result;
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderItemRepositoryImpl.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderItemRepositoryImpl.java
new file mode 100644
index 0000000..4528c6e
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderItemRepositoryImpl.java
@@ -0,0 +1,120 @@
+/*
+ * 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.testcase.shardingsphere.service.repository.jdbc;
+
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity.OrderItem;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.OrderItemRepository;
+
+import javax.sql.DataSource;
+import java.sql.*;
+import java.util.LinkedList;
+import java.util.List;
+
+public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
+
+ private final DataSource dataSource;
+
+ public JDBCOrderItemRepositoryImpl(final DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ @Override
+ public void createTableIfNotExists() {
+ String sql = "CREATE TABLE IF NOT EXISTS t_order_item " + "(order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id))";
+ try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ } catch (final SQLException ignored) {
+ }
+ }
+
+ @Override
+ public void dropTable() {
+ String sql = "DROP TABLE t_order_item";
+ try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ } catch (final SQLException ignored) {
+ }
+ }
+
+ @Override
+ public void truncateTable() {
+ String sql = "TRUNCATE TABLE t_order_item";
+ try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ } catch (final SQLException ignored) {
+ }
+ }
+
+ @Override
+ public Long insert(final OrderItem orderItem) {
+ String sql = "INSERT INTO t_order_item (order_id, user_id, status) VALUES (?, ?, ?)";
+ try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
+ preparedStatement.setLong(1, orderItem.getOrderId());
+ preparedStatement.setInt(2, orderItem.getUserId());
+ preparedStatement.setString(3, orderItem.getStatus());
+ preparedStatement.executeUpdate();
+ try (ResultSet resultSet = preparedStatement.getGeneratedKeys()) {
+ if (resultSet.next()) {
+ orderItem.setOrderItemId(resultSet.getLong(1));
+ }
+ }
+ } catch (final SQLException ignored) {
+ }
+ return orderItem.getOrderItemId();
+ }
+
+ @Override
+ public void delete(final Long orderItemId) {
+ String sql = "DELETE FROM t_order_item WHERE order_item_id=?";
+ try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, orderItemId);
+ preparedStatement.executeUpdate(sql);
+ } catch (final SQLException ignored) {
+ }
+ }
+
+ @Override
+ public List<OrderItem> selectAll() {
+ String sql = "SELECT i.* FROM t_order o, t_order_item i WHERE o.order_id = i.order_id";
+ return getOrderItems(sql);
+ }
+
+ @Override
+ public List<OrderItem> selectRange() {
+ String sql = "SELECT i.* FROM t_order o, t_order_item i WHERE o.order_id = i.order_id AND o.user_id BETWEEN 1 AND 5";
+ return getOrderItems(sql);
+ }
+
+ private List<OrderItem> getOrderItems(final String sql) {
+ List<OrderItem> result = new LinkedList<>();
+ try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
+ .executeQuery()) {
+ while (resultSet.next()) {
+ OrderItem orderItem = new OrderItem();
+ orderItem.setOrderItemId(resultSet.getLong(1));
+ orderItem.setOrderId(resultSet.getLong(2));
+ orderItem.setUserId(resultSet.getInt(3));
+ orderItem.setStatus(resultSet.getString(4));
+ result.add(orderItem);
+ }
+ } catch (final SQLException ignored) {
+ }
+ return result;
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderRepositoryImpl.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderRepositoryImpl.java
new file mode 100644
index 0000000..befcf6b
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/jdbc/JDBCOrderRepositoryImpl.java
@@ -0,0 +1,118 @@
+/*
+ * 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.testcase.shardingsphere.service.repository.jdbc;
+
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity.Order;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.OrderRepository;
+
+import javax.sql.DataSource;
+import java.sql.*;
+import java.util.LinkedList;
+import java.util.List;
+
+public final class JDBCOrderRepositoryImpl implements OrderRepository {
+
+ private final DataSource dataSource;
+
+ public JDBCOrderRepositoryImpl(final DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ @Override
+ public void createTableIfNotExists() {
+ String sql = "CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id))";
+ try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ } catch (final SQLException ignored) {
+ }
+ }
+
+ @Override
+ public void dropTable() {
+ String sql = "DROP TABLE t_order";
+ try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ } catch (final SQLException ignored) {
+ }
+ }
+
+ @Override
+ public void truncateTable() {
+ String sql = "TRUNCATE TABLE t_order";
+ try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
+ statement.executeUpdate(sql);
+ } catch (final SQLException ignored) {
+ }
+ }
+
+ @Override
+ public Long insert(final Order order) {
+ String sql = "INSERT INTO t_order (user_id, status) VALUES (?, ?)";
+ try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
+ preparedStatement.setInt(1, order.getUserId());
+ preparedStatement.setString(2, order.getStatus());
+ preparedStatement.executeUpdate();
+ try (ResultSet resultSet = preparedStatement.getGeneratedKeys()) {
+ if (resultSet.next()) {
+ order.setOrderId(resultSet.getLong(1));
+ }
+ }
+ } catch (final SQLException ignored) {
+ }
+ return order.getOrderId();
+ }
+
+ @Override
+ public void delete(final Long orderId) {
+ String sql = "DELETE FROM t_order WHERE order_id=?";
+ try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ preparedStatement.setLong(1, orderId);
+ preparedStatement.executeUpdate();
+ } catch (final SQLException ignored) {
+ }
+ }
+
+ @Override
+ public List<Order> selectAll() {
+ String sql = "SELECT * FROM t_order";
+ return getOrders(sql);
+ }
+
+ @Override
+ public List<Order> selectRange() {
+ String sql = "SELECT * FROM t_order WHERE order_id BETWEEN 200000000000000000 AND 400000000000000000";
+ return getOrders(sql);
+ }
+
+ private List<Order> getOrders(final String sql) {
+ List<Order> result = new LinkedList<>();
+ try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
+ .executeQuery()) {
+ while (resultSet.next()) {
+ Order order = new Order();
+ order.setOrderId(resultSet.getLong(1));
+ order.setUserId(resultSet.getInt(2));
+ order.setStatus(resultSet.getString(3));
+ result.add(order);
+ }
+ } catch (final SQLException ignored) {
+ }
+ return result;
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/service/RawPojoService.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/service/RawPojoService.java
new file mode 100644
index 0000000..796856a
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/repository/service/RawPojoService.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.
+ *
+ */
+
+package org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service;
+
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity.Order;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity.OrderItem;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.OrderItemRepository;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.OrderRepository;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.api.service.CommonServiceImpl;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
+import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
+
+public class RawPojoService extends CommonServiceImpl {
+
+ private final OrderRepository orderRepository;
+
+ private final OrderItemRepository orderItemRepository;
+
+ public RawPojoService(final JDBCOrderRepositoryImpl orderRepository,
+ final JDBCOrderItemRepositoryImpl orderItemRepository) {
+ this.orderRepository = orderRepository;
+ this.orderItemRepository = orderItemRepository;
+ }
+
+ @Override
+ protected OrderRepository getOrderRepository() {
+ return orderRepository;
+ }
+
+ @Override
+ protected OrderItemRepository getOrderItemRepository() {
+ return orderItemRepository;
+ }
+
+ @Override
+ protected Order newOrder() {
+ return new Order();
+ }
+
+ @Override
+ protected OrderItem newOrderItem() {
+ return new OrderItem();
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingDatabaseAlgorithm.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingDatabaseAlgorithm.java
new file mode 100644
index 0000000..465e568
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingDatabaseAlgorithm.java
@@ -0,0 +1,38 @@
+/*
+ * 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.testcase.shardingsphere.service.utility.algorithm;
+
+import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
+import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
+
+import java.util.Collection;
+
+public class PreciseModuloShardingDatabaseAlgorithm implements PreciseShardingAlgorithm<Integer> {
+
+ @Override
+ public String doSharding(final Collection<String> databaseNames,
+ final PreciseShardingValue<Integer> shardingValue) {
+ for (String each : databaseNames) {
+ if (each.endsWith(shardingValue.getValue() % 2 + "")) {
+ return each;
+ }
+ }
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingTableAlgorithm.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingTableAlgorithm.java
new file mode 100644
index 0000000..ffa9c2d
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/PreciseModuloShardingTableAlgorithm.java
@@ -0,0 +1,37 @@
+/*
+ * 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.testcase.shardingsphere.service.utility.algorithm;
+
+import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
+import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
+
+import java.util.Collection;
+
+public class PreciseModuloShardingTableAlgorithm implements PreciseShardingAlgorithm<Long> {
+
+ @Override
+ public String doSharding(final Collection<String> tableNames, final PreciseShardingValue<Long> shardingValue) {
+ for (String each : tableNames) {
+ if (each.endsWith(shardingValue.getValue() % 2 + "")) {
+ return each;
+ }
+ }
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingDatabaseAlgorithm.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingDatabaseAlgorithm.java
new file mode 100644
index 0000000..1ba1e8b
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingDatabaseAlgorithm.java
@@ -0,0 +1,54 @@
+/*
+ * 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.testcase.shardingsphere.service.utility.algorithm;
+
+import com.google.common.collect.Range;
+import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
+import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;
+
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+public class RangeModuloShardingDatabaseAlgorithm implements RangeShardingAlgorithm<Integer> {
+
+ @Override
+ public Collection<String> doSharding(final Collection<String> databaseNames,
+ final RangeShardingValue<Integer> shardingValue) {
+ Set<String> result = new LinkedHashSet<>();
+ if (Range.closed(1, 5).encloses(shardingValue.getValueRange())) {
+ for (String each : databaseNames) {
+ if (each.endsWith("0")) {
+ result.add(each);
+ }
+ }
+ } else if (Range.closed(6, 10).encloses(shardingValue.getValueRange())) {
+ for (String each : databaseNames) {
+ if (each.endsWith("1")) {
+ result.add(each);
+ }
+ }
+ } else if (Range.closed(1, 10).encloses(shardingValue.getValueRange())) {
+ result.addAll(databaseNames);
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ return result;
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingTableAlgorithm.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingTableAlgorithm.java
new file mode 100644
index 0000000..1339afd
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/algorithm/RangeModuloShardingTableAlgorithm.java
@@ -0,0 +1,46 @@
+/*
+ * 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.testcase.shardingsphere.service.utility.algorithm;
+
+import com.google.common.collect.Range;
+import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
+import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;
+
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+public class RangeModuloShardingTableAlgorithm implements RangeShardingAlgorithm<Long> {
+
+ @Override
+ public Collection<String> doSharding(final Collection<String> tableNames,
+ final RangeShardingValue<Long> shardingValue) {
+ Set<String> result = new LinkedHashSet<>();
+ if (Range.closed(200000000000000000L, 400000000000000000L).encloses(shardingValue.getValueRange())) {
+ for (String each : tableNames) {
+ if (each.endsWith("0")) {
+ result.add(each);
+ }
+ }
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ return result;
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/DataSourceUtil.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/DataSourceUtil.java
new file mode 100644
index 0000000..65b3f53
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/DataSourceUtil.java
@@ -0,0 +1,56 @@
+/*
+ * 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.testcase.shardingsphere.service.utility.config;
+
+import org.apache.commons.dbcp2.BasicDataSource;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+
+public class DataSourceUtil {
+
+ private static final String DEFAULT_SCHEMA = "";
+
+ private static final Map<String, DataSource> datasourceMap = new HashMap<>();
+
+ public static void createDataSource(final String dataSourceName) {
+ BasicDataSource result = new BasicDataSource();
+ result.setDriverClassName("org.h2.Driver");
+ result.setUrl(String.format("jdbc:h2:mem:%s", dataSourceName));
+ result.setUsername("sa");
+ result.setPassword("");
+ datasourceMap.put(dataSourceName, result);
+ }
+
+ public static DataSource getDataSource(final String dataSourceName) {
+ return datasourceMap.get(dataSourceName);
+ }
+
+ public static void createSchema(final String dataSourceName) {
+ String sql = "CREATE SCHEMA " + dataSourceName;
+ try (Connection connection = getDataSource(DEFAULT_SCHEMA).getConnection(); Statement statement = connection.createStatement()) {
+ statement.execute(sql);
+ } catch (final SQLException ignored) {
+ }
+ }
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/ExampleConfiguration.java b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/ExampleConfiguration.java
new file mode 100644
index 0000000..cdae835
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/shardingsphere/service/utility/config/ExampleConfiguration.java
@@ -0,0 +1,29 @@
+/*
+ * 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.testcase.shardingsphere.service.utility.config;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+
+public interface ExampleConfiguration {
+
+ DataSource createDataSource() throws SQLException;
+
+ DataSource getDataSource();
+}
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/resources/application.properties b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/resources/application.properties
new file mode 100644
index 0000000..882f079
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/src/main/resources/application.properties
@@ -0,0 +1,17 @@
+# 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.
+server.port=8080
+server.contextPath=/shardingsphere-4.0.x-scenario
\ No newline at end of file
diff --git a/test/plugin/scenarios/shardingsphere-4.0.x-scenario/support-version.list b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/support-version.list
new file mode 100644
index 0000000..f0e29f0
--- /dev/null
+++ b/test/plugin/scenarios/shardingsphere-4.0.x-scenario/support-version.list
@@ -0,0 +1,18 @@
+# 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
+# "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.
+
+4.0.0
+4.0.1