Add support for C3P0 connection pool tracing (#683)

This commit is contained in:
Chen Ziyan 2024-04-26 14:01:13 +08:00 committed by GitHub
parent 1a01047007
commit d37ee271c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
41 changed files with 2229 additions and 0 deletions

View File

@ -60,6 +60,8 @@ jobs:
- gateway-4.x-scenario
- httpexchange-scenario
- activemq-artemis-2.x-scenario
- c3p0-0.9.0.x-0.9.1.x-scenario
- c3p0-0.9.2.x-0.10.x-scenario
steps:
- uses: actions/checkout@v2
with:

View File

@ -7,6 +7,7 @@ Release Notes.
* Remove `idleCount` tag in Alibaba Druid meter plugin.
* Fix NPE in handleMethodException method of apm-jdk-threadpool-plugin.
* Support for C3P0 connection pool tracing.
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/213?closed=1)

View File

@ -244,4 +244,7 @@ public class ComponentsDefine {
public static final OfficialComponent NACOS = new OfficialComponent(150, "Nacos");
public static final OfficialComponent NETTY_HTTP = new OfficialComponent(151, "Netty-http");
public static final OfficialComponent C3P0 = new OfficialComponent(152, "c3p0");
}

View File

@ -0,0 +1,49 @@
<?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>9.3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-c3p0-0.9.x-plugin</artifactId>
<packaging>jar</packaging>
<name>c3p0-0.9.x-plugin</name>
<properties>
<c3p0.version>0.9.5</c3p0.version>
</properties>
<dependencies>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-jdbc-commons</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,34 @@
/*
* 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.c3p0;
public class PoolConstants {
public static final String POOL_CONNECTION = "C3P0/Connection/";
public static final String METER_NAME = "datasource";
public static final String METER_TAG_NAME = "name";
public static final String METER_TAG_STATUS = "status";
//==================== METRICS ========================//
public static final String NUM_TOTAL_CONNECTIONS = "numTotalConnections";
public static final String NUM_BUSY_CONNECTIONS = "numBusyConnections";
public static final String NUM_IDLE_CONNECTIONS = "numIdleConnections";
public static final String MAX_IDLE_TIME = "maxIdleTime";
public static final String MIN_POOL_SIZE = "minPoolSize";
public static final String MAX_POOL_SIZE = "maxPoolSize";
public static final String INITIAL_POOL_SIZE = "initialPoolSize";
}

View File

@ -0,0 +1,62 @@
/*
* 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.c3p0;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
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 PoolingConnectionCloseInterceptor} intercepted the method of C3P0 closing connection.
*/
public class PoolingConnectionCloseInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst,
Method method,
Object[] allArguments,
Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
AbstractSpan span = ContextManager.createLocalSpan(PoolConstants.POOL_CONNECTION + method.getName());
span.setComponent(ComponentsDefine.C3P0);
}
@Override
public Object afterMethod(EnhancedInstance objInst,
Method method,
Object[] allArguments,
Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ContextManager.stopSpan();
return ret;
}
@Override
public void handleMethodException(EnhancedInstance objInst,
Method method,
Object[] allArguments,
Class<?>[] argumentsTypes,
Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
}
}

View File

@ -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.plugin.c3p0;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
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;
/**
* {@link PoolingConnectionGetInterceptor} intercepted the method of C3P0 getting connection.
*/
public class PoolingConnectionGetInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst,
Method method,
Object[] allArguments,
Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
AbstractSpan span = ContextManager.createLocalSpan(PoolConstants.POOL_CONNECTION + method.getName());
span.setComponent(ComponentsDefine.C3P0);
}
@Override
public Object afterMethod(EnhancedInstance objInst,
Method method,
Object[] allArguments,
Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ContextManager.stopSpan();
return ret;
}
@Override
public void handleMethodException(EnhancedInstance objInst,
Method method,
Object[] allArguments,
Class<?>[] argumentsTypes,
Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
}
}

View File

@ -0,0 +1,132 @@
/*
* 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.c3p0;
import com.mchange.v2.c3p0.C3P0Registry;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.meter.MeterFactory;
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.plugin.jdbc.connectionurl.parser.URLParser;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
/**
* {@link PoolingCreationInterceptor} intercepted the method of pool creation.
*/
public class PoolingCreationInterceptor implements InstanceMethodsAroundInterceptor {
private static final Set<String> TOKEN_MAP = new HashSet<>(16);
@Override
public void beforeMethod(final EnhancedInstance enhancedInstance,
final Method method,
final Object[] objects,
final Class<?>[] classes,
final MethodInterceptResult methodInterceptResult) throws Throwable {
}
@Override
public Object afterMethod(final EnhancedInstance enhancedInstance,
final Method method,
final Object[] objects,
final Class<?>[] classes,
final Object ret) throws Throwable {
C3P0Registry.getPooledDataSources().forEach(obj -> {
ComboPooledDataSource pooledDataSource = (ComboPooledDataSource) obj;
if (!TOKEN_MAP.contains(pooledDataSource.getIdentityToken())) {
ConnectionInfo connectionInfo = URLParser.parser(pooledDataSource.getJdbcUrl());
String tagValue = connectionInfo.getDatabaseName() + "_" + connectionInfo.getDatabasePeer();
Map<String, Function<ComboPooledDataSource, Supplier<Double>>> metricMap = getMetrics();
metricMap.forEach(
(key, value) -> MeterFactory.gauge(PoolConstants.METER_NAME, value.apply(pooledDataSource))
.tag(PoolConstants.METER_TAG_NAME, tagValue)
.tag(PoolConstants.METER_TAG_STATUS, key)
.build());
TOKEN_MAP.add(pooledDataSource.getIdentityToken());
}
});
return ret;
}
@Override
public void handleMethodException(final EnhancedInstance enhancedInstance,
final Method method,
final Object[] objects,
final Class<?>[] classes,
final Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
}
private Map<String, Function<ComboPooledDataSource, Supplier<Double>>> getMetrics() {
Map<String, Function<ComboPooledDataSource, Supplier<Double>>> metricMap = new HashMap<>();
metricMap.put(PoolConstants.NUM_TOTAL_CONNECTIONS, (ComboPooledDataSource pooledDataSource) -> () -> {
double numConnections = 0;
try {
numConnections = pooledDataSource.getNumConnections();
} catch (SQLException e) {
ContextManager.activeSpan().errorOccurred().log(e);
}
return numConnections;
});
metricMap.put(PoolConstants.NUM_BUSY_CONNECTIONS, (ComboPooledDataSource pooledDataSource) -> () -> {
double numBusyConnections = 0;
try {
numBusyConnections = pooledDataSource.getNumBusyConnections();
} catch (SQLException e) {
ContextManager.activeSpan().errorOccurred().log(e);
}
return numBusyConnections;
});
metricMap.put(PoolConstants.NUM_IDLE_CONNECTIONS, (ComboPooledDataSource pooledDataSource) -> () -> {
double numIdleConnections = 0;
try {
numIdleConnections = pooledDataSource.getNumIdleConnections();
} catch (SQLException e) {
ContextManager.activeSpan().errorOccurred().log(e);
}
return numIdleConnections;
});
metricMap.put(
PoolConstants.MAX_IDLE_TIME,
(ComboPooledDataSource pooledDataSource) -> () -> (double) pooledDataSource.getMaxIdleTime()
);
metricMap.put(
PoolConstants.MIN_POOL_SIZE,
(ComboPooledDataSource pooledDataSource) -> () -> (double) pooledDataSource.getMinPoolSize()
);
metricMap.put(
PoolConstants.MAX_POOL_SIZE,
(ComboPooledDataSource pooledDataSource) -> () -> (double) pooledDataSource.getMaxPoolSize()
);
metricMap.put(
PoolConstants.INITIAL_POOL_SIZE,
(ComboPooledDataSource pooledDataSource) -> () -> (double) pooledDataSource.getInitialPoolSize()
);
return metricMap;
}
}

View File

@ -0,0 +1,72 @@
/*
* 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.c3p0.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 static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* C3p0 is a mature, highly concurrent JDBC Connection pooling library, with support for caching and reuse of
* PreparedStatement objects. Defined by the jdbc3 spec and the optional extensions to jdbc2. c3p0 now also fully
* supports the jdbc4. {@link C3P0NewProxyConnectionInstrumentation} defines the instance methods enhance plugin for
* connection closed
*/
public class C3P0NewProxyConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.mchange.v2.c3p0.impl.NewProxyConnection";
private static final String ENHANCE_METHOD = "close";
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.c3p0.PoolingConnectionCloseInterceptor";
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(ENHANCE_METHOD);
}
@Override
public String getMethodsInterceptor() {
return INTERCEPTOR_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}

View File

@ -0,0 +1,72 @@
/*
* 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.c3p0.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 static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* C3p0 is a mature, highly concurrent JDBC Connection pooling library, with support for caching and reuse of
* PreparedStatement objects. Defined by the jdbc3 spec and the optional extensions to jdbc2. c3p0 now also fully
* supports the jdbc4. { @link C3P0PoolManagerInstrumentation} defines the instance methods enhance plugin for pool
* creation.
*/
public class C3P0PoolManagerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager";
private static final String ENHANCE_METHOD = "createPooledConnectionPool";
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.c3p0.PoolingCreationInterceptor";
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(ENHANCE_METHOD);
}
@Override
public String getMethodsInterceptor() {
return INTERCEPTOR_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}

View File

@ -0,0 +1,72 @@
/*
* 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.c3p0.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 static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* C3p0 is a mature, highly concurrent JDBC Connection pooling library, with support for caching and reuse of
* PreparedStatement objects. Defined by the jdbc3 spec and the optional extensions to jdbc2. c3p0 now also fully
* supports the jdbc4. { @link C3P0PooledDataSourceInstrumentation} defines the instance methods enhance plugin for
* connection init
*/
public class C3P0PooledDataSourceInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.mchange.v2.c3p0.ComboPooledDataSource";
private static final String ENHANCE_METHOD = "getConnection";
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.c3p0.PoolingConnectionGetInterceptor";
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(ENHANCE_METHOD);
}
@Override
public String getMethodsInterceptor() {
return INTERCEPTOR_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}

View File

@ -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.
c3p0-0.9.x=org.apache.skywalking.apm.plugin.c3p0.define.C3P0NewProxyConnectionInstrumentation
c3p0-0.9.x=org.apache.skywalking.apm.plugin.c3p0.define.C3P0PoolManagerInstrumentation
c3p0-0.9.x=org.apache.skywalking.apm.plugin.c3p0.define.C3P0PooledDataSourceInstrumentation

View File

@ -136,6 +136,7 @@
<module>aerospike-plugin</module>
<module>rocketMQ-client-java-5.x-plugin</module>
<module>activemq-artemis-jakarta-client-2.x-plugin</module>
<module>c3p0-0.9.x-plugin</module>
</modules>
<packaging>pom</packaging>

View File

@ -176,3 +176,4 @@
- spring-webflux-6.x
- spring-webflux-6.x-webclient
- activemq-artemis-jakarta-client-2.x
- c3p0-0.9.x

View File

@ -148,6 +148,7 @@ metrics based on the tracing data.
* [Apache Commons DBCP](https://github.com/apache/commons-dbcp) 2.x
* [Alibaba Druid](https://github.com/alibaba/druid) 1.x
* [HikariCP](https://github.com/brettwooldridge/HikariCP) 3.x -> 4.x
* [C3P0](https://github.com/swaldman/c3p0) 0.9.0 -> 0.10.0
* Logging Framework
* [log4j](https://github.com/apache/log4j) 2.x
* [log4j2](https://github.com/apache/logging-log4j2) 1.2.x
@ -166,6 +167,11 @@ The meter plugin provides the advanced metrics collections, which are not a part
* [Dubbo](https://github.com/apache/dubbo) 2.5.x -> 2.7.x
* [Jetty](https://github.com/eclipse/jetty.project) 9.1.x -> 11.x
* [Grizzly](https://github.com/eclipse-ee4j/grizzly) 2.3.x -> 4.x
* Connection Pool
* [Apache Commons DBCP](https://github.com/apache/commons-dbcp) 2.x
* [Alibaba Druid](https://github.com/alibaba/druid) 1.x
* [HikariCP](https://github.com/brettwooldridge/HikariCP) 3.x -> 4.x
* [C3P0](https://github.com/swaldman/c3p0) 0.9.0 -> 0.10.0
___
¹Due to license incompatibilities/restrictions these plugins are hosted and released in 3rd part repository,
go to [SkyAPM java plugin extension repository](https://github.com/SkyAPM/java-plugin-extensions) to get these.

View File

@ -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/c3p0-0.9.0.x-0.9.1.x-scenario.jar &

View File

@ -0,0 +1,288 @@
# 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: c3p0-0.9.0.x-0.9.1.x-scenario
segmentSize: nq 0
segments:
- segmentId: not null
spans:
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 1
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 2
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: "CREATE TABLE test_C3P0(\nid VARCHAR(1) PRIMARY KEY, \nvalue VARCHAR(1)\
\ NOT NULL)"
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 3
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 4
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 5
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: 'INSERT INTO test_C3P0(id, value) VALUES(1,1)'
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 6
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 7
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 8
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: 'SELECT id, value FROM test_C3P0 WHERE id=1'
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 9
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 10
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 11
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: "DELETE FROM test_C3P0 WHERE id=1"
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 12
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 13
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 14
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: "DROP table test_C3P0"
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 15
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: GET:/c3p0-0.9.0.x-0.9.1.x-scenario/case/c3p0-0.9.0.x-0.9.1.x-scenario
parentSpanId: -1
spanId: 0
spanLayer: Http
startTime: gt 0
endTime: gt 0
componentId: 1
isError: false
spanType: Entry
peer: ''
skipAnalysis: false
tags:
- {key: url, value: 'http://localhost:8080/c3p0-0.9.0.x-0.9.1.x-scenario/case/c3p0-0.9.0.x-0.9.1.x-scenario'}
- {key: http.method, value: GET}
- {key: http.status_code, value: '200'}
meterItems:
- serviceName: c3p0-0.9.0.x-0.9.1.x-scenario
meterSize: 12
meters:
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: initialPoolSize}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: maxIdleTime}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: maxPoolSize}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: minPoolSize}
singleValue: ge -1
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: numBusyConnections}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: numIdleConnections}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: numTotalConnections}
singleValue: ge 0
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: core_pool_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 1
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: max_pool_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 1
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: pool_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 0
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: active_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 0
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: queue_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 0

View File

@ -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.
type: jvm
entryService: http://localhost:8080/c3p0-0.9.0.x-0.9.1.x-scenario/case/c3p0-0.9.0.x-0.9.1.x-scenario
healthCheck: http://localhost:8080/c3p0-0.9.0.x-0.9.1.x-scenario/case/healthCheck
startScript: ./bin/startup.sh
environment:
depends_on:
- mysql-server
dependencies:
mysql-server:
image: mysql:5.7
hostname: mysql-server
expose:
- "3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test

View File

@ -0,0 +1,127 @@
<?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">
<groupId>org.apache.skywalking.apm.testcase</groupId>
<artifactId>c3p0-0.9.0.x-0.9.1.x-scenario</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>1.8</compiler.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<test.framework.version>0.9.1.2</test.framework.version>
<docker.image.version>${test.framework.version}</docker.image.version>
<spring.boot.version>2.1.6.RELEASE</spring.boot.version>
</properties>
<name>skywalking-c3p0-0.9.0.x-0.9.1.x-scenario</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>${test.framework.version}</version>
</dependency>
</dependencies>
<build>
<finalName>c3p0-0.9.0.x-0.9.1.x-scenario</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</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>
</project>

View File

@ -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}/c3p0-0.9.0.x-0.9.1.x-scenario.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
</files>
</assembly>

View File

@ -0,0 +1,34 @@
/*
* 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.c3p0.c3p0;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
try {
SpringApplication.run(Application.class, args);
} catch (Exception e) {
// Never do this
}
}
}

View File

@ -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.testcase.c3p0.c3p0;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class MysqlConfig {
private static Logger LOGGER = LogManager.getLogger(MysqlConfig.class);
private static String URL;
private static String USER_NAME;
private static String PASSWORD;
static {
InputStream inputStream = MysqlConfig.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties properties = new Properties();
try {
properties.load(inputStream);
} catch (IOException e) {
LOGGER.error("Failed to load config", e);
}
URL = properties.getProperty("mysql.url");
USER_NAME = properties.getProperty("mysql.username");
PASSWORD = properties.getProperty("mysql.password");
}
public static String getUrl() {
return URL;
}
public static String getUserName() {
return USER_NAME;
}
public static String getPassword() {
return PASSWORD;
}
}

View File

@ -0,0 +1,58 @@
/*
* 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.c3p0.c3p0.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.apm.testcase.c3p0.c3p0.service.CaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/case")
public class CaseController {
@Autowired
CaseService caseService;
private static final Logger LOGGER = LogManager.getLogger(CaseController.class);
private static final String SUCCESS = "Success";
@RequestMapping("/c3p0-0.9.0.x-0.9.1.x-scenario")
@ResponseBody
public String testcase() throws Exception {
try {
caseService.testCase();
} catch (Exception e) {
LOGGER.error("Failed to execute sql.", e);
throw e;
}
return SUCCESS;
}
@RequestMapping("/healthCheck")
@ResponseBody
public String healthCheck() throws Exception {
return SUCCESS;
}
}

View File

@ -0,0 +1,72 @@
/*
* 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.c3p0.c3p0.service;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.skywalking.apm.testcase.c3p0.c3p0.MysqlConfig;
import org.springframework.stereotype.Service;
@Service
public class CaseService {
public static ComboPooledDataSource DS;
private static final String CREATE_TABLE_SQL = "CREATE TABLE test_C3P0(\n" + "id VARCHAR(1) PRIMARY KEY, \n" + "value VARCHAR(1) NOT NULL)";
private static final String INSERT_DATA_SQL = "INSERT INTO test_C3P0(id, value) VALUES(1,1)";
private static final String QUERY_DATA_SQL = "SELECT id, value FROM test_C3P0 WHERE id=1";
private static final String DELETE_DATA_SQL = "DELETE FROM test_C3P0 WHERE id=1";
private static final String DROP_TABLE_SQL = "DROP table test_C3P0";
static {
try {
DS = new ComboPooledDataSource();
DS.setDriverClass("com.mysql.jdbc.Driver");
DS.setJdbcUrl(MysqlConfig.getUrl());
DS.setUser(MysqlConfig.getUserName());
DS.setPassword(MysqlConfig.getPassword());
DS.setAcquireIncrement(1);
DS.setInitialPoolSize(5);
DS.setMinPoolSize(1);
DS.setMaxIdleTime(10);
DS.setTestConnectionOnCheckin(false);
DS.setTestConnectionOnCheckout(false);
} catch (Exception e) {
e.printStackTrace();
}
}
public void testCase() {
sqlExecutor(DS, CREATE_TABLE_SQL);
sqlExecutor(DS, INSERT_DATA_SQL);
sqlExecutor(DS, QUERY_DATA_SQL);
sqlExecutor(DS, DELETE_DATA_SQL);
sqlExecutor(DS, DROP_TABLE_SQL);
}
public void sqlExecutor(ComboPooledDataSource dataSource, String sql) {
try (Connection conn = dataSource.getConnection();) {
Statement statement = conn.createStatement();
statement.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,23 @@
#
# 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
servlet:
context-path: /c3p0-0.9.0.x-0.9.1.x-scenario
logging:
config: classpath:log4j2.xml

View File

@ -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.
#
mysql.url=jdbc:mysql://mysql-server:3306/test?serverTimezone=CST&useLocalSessionState=true
mysql.username=root
mysql.password=root

View File

@ -0,0 +1,30 @@
<?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.
~
-->
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_ERR">
<PatternLayout charset="UTF-8" pattern="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="WARN">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

View File

@ -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 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.
0.9.0.4
0.9.1.2

View File

@ -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/c3p0-0.9.2.x-0.10.x-scenario.jar &

View File

@ -0,0 +1,288 @@
# 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: c3p0-0.9.2.x-0.10.x-scenario
segmentSize: nq 0
segments:
- segmentId: not null
spans:
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 1
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 2
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: "CREATE TABLE test_C3P0(\nid VARCHAR(1) PRIMARY KEY, \nvalue VARCHAR(1)\
\ NOT NULL)"
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 3
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 4
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 5
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: 'INSERT INTO test_C3P0(id, value) VALUES(1,1)'
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 6
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 7
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 8
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: 'SELECT id, value FROM test_C3P0 WHERE id=1'
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 9
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 10
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 11
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: "DELETE FROM test_C3P0 WHERE id=1"
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 12
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: C3P0/Connection/getConnection
parentSpanId: 0
spanId: 13
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: Mysql/JDBC/Statement/execute
parentSpanId: 0
spanId: 14
startTime: gt 0
endTime: gt 0
componentId: 33
isError: false
spanType: Exit
peer: mysql-server:3306
skipAnalysis: false
tags:
- {key: db.type, value: Mysql}
- {key: db.instance, value: test}
- key: db.statement
value: "DROP table test_C3P0"
- operationName: C3P0/Connection/close
parentSpanId: 0
spanId: 15
startTime: gt 0
endTime: gt 0
componentId: 152
isError: false
spanType: Local
peer: ''
skipAnalysis: false
- operationName: GET:/c3p0-0.9.2.x-0.10.x-scenario/case/c3p0-0.9.2.x-0.10.x-scenario
parentSpanId: -1
spanId: 0
spanLayer: Http
startTime: gt 0
endTime: gt 0
componentId: 1
isError: false
spanType: Entry
peer: ''
skipAnalysis: false
tags:
- {key: url, value: 'http://localhost:8080/c3p0-0.9.2.x-0.10.x-scenario/case/c3p0-0.9.2.x-0.10.x-scenario'}
- {key: http.method, value: GET}
- {key: http.status_code, value: '200'}
meterItems:
- serviceName: c3p0-0.9.2.x-0.10.x-scenario
meterSize: 12
meters:
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: initialPoolSize}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: maxIdleTime}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: maxPoolSize}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: minPoolSize}
singleValue: ge -1
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: numBusyConnections}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: numIdleConnections}
singleValue: ge 0
- meterId:
name: datasource
tags:
- {name: name, value: test_mysql-server:3306}
- {name: status, value: numTotalConnections}
singleValue: ge 0
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: core_pool_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 1
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: max_pool_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 1
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: pool_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 0
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: active_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 0
- meterId:
name: thread_pool
tags:
- {name: metric_type, value: queue_size}
- {name: pool_name, value: tomcat_execute_pool}
singleValue: ge 0

View File

@ -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.
type: jvm
entryService: http://localhost:8080/c3p0-0.9.2.x-0.10.x-scenario/case/c3p0-0.9.2.x-0.10.x-scenario
healthCheck: http://localhost:8080/c3p0-0.9.2.x-0.10.x-scenario/case/healthCheck
startScript: ./bin/startup.sh
environment:
depends_on:
- mysql-server
dependencies:
mysql-server:
image: mysql:5.7
hostname: mysql-server
expose:
- "3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test

View File

@ -0,0 +1,127 @@
<?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">
<groupId>org.apache.skywalking.apm.testcase</groupId>
<artifactId>c3p0-0.9.2.x-0.10.x-scenario</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>1.8</compiler.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<test.framework.version>0.9.5.5</test.framework.version>
<docker.image.version>${test.framework.version}</docker.image.version>
<spring.boot.version>2.1.6.RELEASE</spring.boot.version>
</properties>
<name>skywalking-c3p0-0.9.2.x-0.10.x-scenario</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>${test.framework.version}</version>
</dependency>
</dependencies>
<build>
<finalName>c3p0-0.9.2.x-0.10.x-scenario</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</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>
</project>

View File

@ -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}/c3p0-0.9.2.x-0.10.x-scenario.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
</files>
</assembly>

View File

@ -0,0 +1,34 @@
/*
* 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.c3p0.mchange;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
try {
SpringApplication.run(Application.class, args);
} catch (Exception e) {
// Never do this
}
}
}

View File

@ -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.testcase.c3p0.mchange;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class MysqlConfig {
private static Logger LOGGER = LogManager.getLogger(MysqlConfig.class);
private static String URL;
private static String USER_NAME;
private static String PASSWORD;
static {
InputStream inputStream = MysqlConfig.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties properties = new Properties();
try {
properties.load(inputStream);
} catch (IOException e) {
LOGGER.error("Failed to load config", e);
}
URL = properties.getProperty("mysql.url");
USER_NAME = properties.getProperty("mysql.username");
PASSWORD = properties.getProperty("mysql.password");
}
public static String getUrl() {
return URL;
}
public static String getUserName() {
return USER_NAME;
}
public static String getPassword() {
return PASSWORD;
}
}

View File

@ -0,0 +1,58 @@
/*
* 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.c3p0.mchange.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.skywalking.apm.testcase.c3p0.mchange.service.CaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/case")
public class CaseController {
@Autowired
CaseService caseService;
private static final Logger LOGGER = LogManager.getLogger(CaseController.class);
private static final String SUCCESS = "Success";
@RequestMapping("/c3p0-0.9.2.x-0.10.x-scenario")
@ResponseBody
public String testcase() throws Exception {
try {
caseService.testCase();
} catch (Exception e) {
LOGGER.error("Failed to execute sql.", e);
throw e;
}
return SUCCESS;
}
@RequestMapping("/healthCheck")
@ResponseBody
public String healthCheck() throws Exception {
return SUCCESS;
}
}

View File

@ -0,0 +1,73 @@
/*
* 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.c3p0.mchange.service;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.skywalking.apm.testcase.c3p0.mchange.MysqlConfig;
import org.springframework.stereotype.Service;
@Service
public class CaseService {
public static ComboPooledDataSource DS;
private static final String CREATE_TABLE_SQL = "CREATE TABLE test_C3P0(\n" + "id VARCHAR(1) PRIMARY KEY, \n" + "value VARCHAR(1) NOT NULL)";
private static final String INSERT_DATA_SQL = "INSERT INTO test_C3P0(id, value) VALUES(1,1)";
private static final String QUERY_DATA_SQL = "SELECT id, value FROM test_C3P0 WHERE id=1";
private static final String DELETE_DATA_SQL = "DELETE FROM test_C3P0 WHERE id=1";
private static final String DROP_TABLE_SQL = "DROP table test_C3P0";
static {
try {
DS = new ComboPooledDataSource();
DS.setDriverClass("com.mysql.jdbc.Driver");
DS.setJdbcUrl(MysqlConfig.getUrl());
DS.setUser(MysqlConfig.getUserName());
DS.setPassword(MysqlConfig.getPassword());
DS.setAcquireIncrement(1);
DS.setInitialPoolSize(5);
DS.setMinPoolSize(1);
DS.setMaxIdleTime(10);
DS.setTestConnectionOnCheckin(false);
DS.setTestConnectionOnCheckout(false);
} catch (Exception e) {
e.printStackTrace();
}
}
public void testCase() {
sqlExecutor(DS, CREATE_TABLE_SQL);
sqlExecutor(DS, INSERT_DATA_SQL);
sqlExecutor(DS, QUERY_DATA_SQL);
sqlExecutor(DS, DELETE_DATA_SQL);
sqlExecutor(DS, DROP_TABLE_SQL);
}
public void sqlExecutor(ComboPooledDataSource dataSource, String sql) {
try (Connection conn = dataSource.getConnection();) {
Statement statement = conn.createStatement();
statement.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,23 @@
#
# 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
servlet:
context-path: /c3p0-0.9.2.x-0.10.x-scenario
logging:
config: classpath:log4j2.xml

View File

@ -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.
#
mysql.url=jdbc:mysql://mysql-server:3306/test?serverTimezone=CST&useLocalSessionState=true
mysql.username=root
mysql.password=root

View File

@ -0,0 +1,30 @@
<?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.
~
-->
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_ERR">
<PatternLayout charset="UTF-8" pattern="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="WARN">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

View File

@ -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.
0.10.0
0.9.5.5
0.9.2.1