mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-09 04:46:06 +10:00
#2354 extract profiler-test
This commit is contained in:
@@ -20,6 +20,10 @@
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-profiler</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-profiler-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-profiler-optional</artifactId>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Licensed 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.
|
||||
@@ -16,6 +16,7 @@ package com.navercorp.pinpoint.bootstrap;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -34,7 +35,6 @@ import com.navercorp.pinpoint.common.util.SimpleProperty;
|
||||
import com.navercorp.pinpoint.common.util.SystemProperty;
|
||||
import com.navercorp.pinpoint.common.util.logger.CommonLoggerFactory;
|
||||
import com.navercorp.pinpoint.common.util.logger.StdoutCommonLoggerFactory;
|
||||
import com.navercorp.pinpoint.exception.PinpointException;
|
||||
|
||||
/**
|
||||
* @author Jongho Moon
|
||||
@@ -44,7 +44,12 @@ class PinpointStarter {
|
||||
|
||||
private final BootLogger logger = BootLogger.getLogger(PinpointStarter.class.getName());
|
||||
|
||||
public static final String AGENT_TYPE = "AGENT_TYPE";
|
||||
|
||||
public static final String DEFAULT_AGENT = "DEFAULT_AGENT";
|
||||
public static final String BOOT_CLASS = "com.navercorp.pinpoint.profiler.DefaultAgent";
|
||||
|
||||
public static final String PLUGIN_TEST_AGENT = "PLUGIN_TEST";
|
||||
public static final String PLUGIN_TEST_BOOT_CLASS = "com.navercorp.pinpoint.test.PluginTestAgent";
|
||||
|
||||
private SimpleProperty systemProperty = SystemProperty.INSTANCE;
|
||||
@@ -85,13 +90,13 @@ class PinpointStarter {
|
||||
if (applicationName == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
URL[] pluginJars = classPathResolver.resolvePlugins();
|
||||
|
||||
// TODO using PLogger instead of CommonLogger
|
||||
CommonLoggerFactory loggerFactory = StdoutCommonLoggerFactory.INSTANCE;
|
||||
TraceMetadataLoaderService typeLoaderService = new DefaultTraceMetadataLoaderService(pluginJars, loggerFactory);
|
||||
ServiceTypeRegistryService serviceTypeRegistryService = new DefaultServiceTypeRegistryService(typeLoaderService, loggerFactory);
|
||||
ServiceTypeRegistryService serviceTypeRegistryService = new DefaultServiceTypeRegistryService(typeLoaderService, loggerFactory);
|
||||
AnnotationKeyRegistryService annotationKeyRegistryService = new DefaultAnnotationKeyRegistryService(typeLoaderService, loggerFactory);
|
||||
|
||||
String configPath = getConfigPath(classPathResolver);
|
||||
@@ -131,16 +136,16 @@ class PinpointStarter {
|
||||
|
||||
private String getBootClass() {
|
||||
final String agentType = getAgentType().toUpperCase();
|
||||
if ("PLUGIN_TEST".equals(agentType)) {
|
||||
if (PLUGIN_TEST_AGENT.equals(agentType)) {
|
||||
return PLUGIN_TEST_BOOT_CLASS;
|
||||
}
|
||||
return BOOT_CLASS;
|
||||
}
|
||||
|
||||
private String getAgentType() {
|
||||
String agentType = agentArgs.get("AGENT_TYPE");
|
||||
String agentType = agentArgs.get(AGENT_TYPE);
|
||||
if (agentType == null) {
|
||||
return "DEFAULT_AGENT";
|
||||
return DEFAULT_AGENT;
|
||||
}
|
||||
return agentType;
|
||||
|
||||
@@ -196,7 +201,7 @@ class PinpointStarter {
|
||||
|
||||
String classPathAgentConfigPath = classPathResolver.getAgentConfigPath();
|
||||
if (classPathAgentConfigPath != null) {
|
||||
logger.info("classpath " + configName + " found. " + classPathAgentConfigPath);
|
||||
logger.info("classpath " + configName + " found. " + classPathAgentConfigPath);
|
||||
return classPathAgentConfigPath;
|
||||
}
|
||||
|
||||
@@ -205,11 +210,11 @@ class PinpointStarter {
|
||||
}
|
||||
|
||||
|
||||
private List<URL> resolveLib(ClassPathResolver classPathResolver) {
|
||||
private List<URL> resolveLib(ClassPathResolver classPathResolver) {
|
||||
// this method may handle only absolute path, need to handle relative path (./..agentlib/lib)
|
||||
String agentJarFullPath = classPathResolver.getAgentJarFullPath();
|
||||
String agentLibPath = classPathResolver.getAgentLibPath();
|
||||
List<URL> urlList = classPathResolver.resolveLib();
|
||||
List<URL> urlList = resolveLib(classPathResolver.resolveLib());
|
||||
String agentConfigPath = classPathResolver.getAgentConfigPath();
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
@@ -224,4 +229,21 @@ class PinpointStarter {
|
||||
return urlList;
|
||||
}
|
||||
|
||||
private List<URL> resolveLib(List<URL> urlList) {
|
||||
if (DEFAULT_AGENT.equals(getAgentType().toUpperCase())) {
|
||||
final List<URL> releaseLib = new ArrayList<URL>(urlList.size());
|
||||
for (URL url : urlList) {
|
||||
//
|
||||
if (!url.toExternalForm().contains("pinpoint-profiler-test")) {
|
||||
releaseLib.add(url);
|
||||
}
|
||||
}
|
||||
return releaseLib;
|
||||
} else {
|
||||
logger.info("load " + PLUGIN_TEST_AGENT + " lib");
|
||||
// plugin test
|
||||
return urlList;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,11 @@
|
||||
<artifactId>pinpoint-profiler</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-profiler-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-test</artifactId>
|
||||
|
||||
@@ -27,6 +27,11 @@
|
||||
<artifactId>pinpoint-profiler</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-profiler-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-commons-server</artifactId>
|
||||
|
||||
@@ -28,6 +28,11 @@
|
||||
<artifactId>pinpoint-profiler</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-profiler-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-test</artifactId>
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
<module>plugins</module>
|
||||
<module>profiler</module>
|
||||
<module>profiler-optional</module>
|
||||
<module>profiler-test</module>
|
||||
<module>rpc</module>
|
||||
<module>thrift</module>
|
||||
<module>test</module>
|
||||
@@ -163,6 +164,11 @@
|
||||
<type>pom</type>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-profiler-test</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-collector</artifactId>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/.settings/
|
||||
/*.iml
|
||||
/.project
|
||||
/target/
|
||||
/.classpath
|
||||
@@ -0,0 +1,5 @@
|
||||
RMRqrdbgbKFhbaVnDxHUdDQvrOQXxIBklnvcmahheubVC
|
||||
mh2KM35CLkwUHS4DH7QVhxy52J5hnWbyEm6Cyd3KkF<mV
|
||||
RmmnSVOqOMnOnMMrmMqwXomoroNrqPNRrPSsWwtUxXuUU
|
||||
sRONqpnmqmUUnqonmstsmmmmmUUnqonmstsmmmmmUUGfk
|
||||
mlfkqUUnmmmm
|
||||
@@ -0,0 +1,199 @@
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint</artifactId>
|
||||
<version>1.6.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pinpoint-profiler-test</artifactId>
|
||||
<name>pinpoint-profiler-test</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-commons</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.thrift</groupId>
|
||||
<artifactId>libthrift</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-commons-server</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-commons-hbase</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-profiler</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-thrift</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.thrift</groupId>
|
||||
<artifactId>libthrift</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-bootstrap-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-rpc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-google-guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- [End] Compile Interceptors -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-debug-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.thrift</groupId>
|
||||
<artifactId>libthrift</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<groupId>org.slf4j</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Logging depedencies -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<!-- commons-logging-adapter -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- serving performance metrics -->
|
||||
<dependency>
|
||||
<groupId>io.dropwizard.metrics</groupId>
|
||||
<artifactId>metrics-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dropwizard.metrics</groupId>
|
||||
<artifactId>metrics-jvm</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency> -->
|
||||
<!--<groupId>io.dropwizard.metrics</groupId> -->
|
||||
<!--<artifactId>metrics-json</artifactId> -->
|
||||
<!--<version>${metrics.version}</version> -->
|
||||
<!--</dependency> -->
|
||||
<!--<dependency> -->
|
||||
<!--<groupId>io.dropwizard.metrics</groupId> -->
|
||||
<!--<artifactId>metrics-healthchecks</artifactId> -->
|
||||
<!--<version>${metrics.version}</version> -->
|
||||
<!--</dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/pinpoint.config</exclude>
|
||||
<exclude>**/log4j.xml</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+217
-217
@@ -1,217 +1,217 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplate;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplateAware;
|
||||
import com.navercorp.pinpoint.profiler.plugin.GuardProfilerPluginContext;
|
||||
import org.apache.thrift.TBase;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.DefaultAgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation;
|
||||
import com.navercorp.pinpoint.common.plugin.PluginLoader;
|
||||
import com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService;
|
||||
import com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgent;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ClassInjector;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
import com.navercorp.pinpoint.thrift.dto.TAnnotation;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author koo.taejin
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
public class MockAgent extends DefaultAgent {
|
||||
|
||||
|
||||
public static MockAgent of(String configPath) {
|
||||
ProfilerConfig profilerConfig = null;
|
||||
try {
|
||||
URL resource = MockAgent.class.getClassLoader().getResource(configPath);
|
||||
if (resource == null) {
|
||||
throw new FileNotFoundException("pinpoint.config not found. configPath:" + configPath);
|
||||
}
|
||||
profilerConfig = DefaultProfilerConfig.load(resource.getPath());
|
||||
((DefaultProfilerConfig)profilerConfig).setApplicationServerType(ServiceType.TEST_STAND_ALONE.getName());
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
return of(profilerConfig);
|
||||
}
|
||||
|
||||
public static MockAgent of(ProfilerConfig config) {
|
||||
AgentOption agentOption = new DefaultAgentOption(new DummyInstrumentation(), "mockAgent", "mockApplicationName", config, new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService());
|
||||
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
|
||||
|
||||
return new MockAgent(agentOption, binder);
|
||||
}
|
||||
|
||||
public MockAgent(AgentOption agentOption) {
|
||||
this(agentOption, new TestInterceptorRegistryBinder());
|
||||
}
|
||||
|
||||
public MockAgent(AgentOption agentOption, InterceptorRegistryBinder binder) {
|
||||
super(agentOption, binder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataSender createUdpStatDataSender(int port, String threadName, int writeQueueSize, int timeout, int sendBufferSize) {
|
||||
return new ListenableDataSender<TBase<?, ?>>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataSender createUdpSpanDataSender(int port, String threadName, int writeQueueSize, int timeout, int sendBufferSize) {
|
||||
return new ListenableDataSender<TBase<?, ?>>();
|
||||
}
|
||||
|
||||
public DataSender getSpanDataSender() {
|
||||
return super.getSpanDataSender();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected StorageFactory createStorageFactory() {
|
||||
return new SimpleSpanStorageFactory(super.getSpanDataSender());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected EnhancedDataSender createTcpDataSender(CommandDispatcher commandDispatcher) {
|
||||
return new TestTcpDataSender();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerMetaDataHolder createServerMetaDataHolder() {
|
||||
List<String> vmArgs = RuntimeMXBeanUtils.getVmArgs();
|
||||
return new ResettableServerMetaDataHolder(vmArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultProfilerPluginContext> loadPlugins(AgentOption agentOption) {
|
||||
List<DefaultProfilerPluginContext> pluginContexts = new ArrayList<DefaultProfilerPluginContext>();
|
||||
ClassInjector classInjector = new TestProfilerPluginClassLoader();
|
||||
|
||||
List<ProfilerPlugin> plugins = PluginLoader.load(ProfilerPlugin.class, ClassLoader.getSystemClassLoader());
|
||||
|
||||
for (ProfilerPlugin plugin : plugins) {
|
||||
final DefaultProfilerPluginContext context = new DefaultProfilerPluginContext(this, classInjector);
|
||||
final GuardProfilerPluginContext guard = new GuardProfilerPluginContext(context);
|
||||
try {
|
||||
preparePlugin(plugin, context);
|
||||
plugin.setup(guard);
|
||||
} finally {
|
||||
guard.close();
|
||||
}
|
||||
pluginContexts.add(context);
|
||||
}
|
||||
|
||||
|
||||
return pluginContexts;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicated code : com/navercorp/pinpoint/profiler/plugin/ProfilerPluginLoader.java
|
||||
* @param plugin
|
||||
* @param context
|
||||
*/
|
||||
private void preparePlugin(ProfilerPlugin plugin, InstrumentContext context) {
|
||||
|
||||
if (plugin instanceof TransformTemplateAware) {
|
||||
final TransformTemplate transformTemplate = new TransformTemplate(context);
|
||||
((TransformTemplateAware) plugin).setTransformTemplate(transformTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String toString(Span span) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append('(');
|
||||
builder.append(span.getServiceType());
|
||||
builder.append(", [");
|
||||
appendAnnotations(builder, span.getAnnotations());
|
||||
builder.append("])");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String toString(SpanEvent span) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append('(');
|
||||
builder.append(span.getServiceType());
|
||||
builder.append(", [");
|
||||
appendAnnotations(builder, span.getAnnotations());
|
||||
builder.append("])");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void appendAnnotations(StringBuilder builder, List<TAnnotation> annotations) {
|
||||
boolean first = true;
|
||||
|
||||
if (annotations != null) {
|
||||
for (TAnnotation a : annotations) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
builder.append(", ");
|
||||
}
|
||||
|
||||
builder.append(toString(a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String toString(TAnnotation a) {
|
||||
return a.getKey() + "=" + a.getValue().getFieldValue();
|
||||
}
|
||||
|
||||
public static String toString(short serviceCode, ExpectedAnnotation...annotations) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append('(');
|
||||
builder.append(serviceCode);
|
||||
builder.append(", ");
|
||||
builder.append(Arrays.deepToString(annotations));
|
||||
builder.append(")");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentContext;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplate;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformTemplateAware;
|
||||
import com.navercorp.pinpoint.profiler.plugin.GuardProfilerPluginContext;
|
||||
import org.apache.thrift.TBase;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.AgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.DefaultAgentOption;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation;
|
||||
import com.navercorp.pinpoint.common.plugin.PluginLoader;
|
||||
import com.navercorp.pinpoint.common.service.DefaultAnnotationKeyRegistryService;
|
||||
import com.navercorp.pinpoint.common.service.DefaultServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgent;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.instrument.ClassInjector;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.receiver.CommandDispatcher;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
import com.navercorp.pinpoint.thrift.dto.TAnnotation;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
* @author koo.taejin
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
public class MockAgent extends DefaultAgent {
|
||||
|
||||
|
||||
public static MockAgent of(String configPath) {
|
||||
ProfilerConfig profilerConfig = null;
|
||||
try {
|
||||
URL resource = MockAgent.class.getClassLoader().getResource(configPath);
|
||||
if (resource == null) {
|
||||
throw new FileNotFoundException("pinpoint.config not found. configPath:" + configPath);
|
||||
}
|
||||
profilerConfig = DefaultProfilerConfig.load(resource.getPath());
|
||||
((DefaultProfilerConfig)profilerConfig).setApplicationServerType(ServiceType.TEST_STAND_ALONE.getName());
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
return of(profilerConfig);
|
||||
}
|
||||
|
||||
public static MockAgent of(ProfilerConfig config) {
|
||||
AgentOption agentOption = new DefaultAgentOption(new DummyInstrumentation(), "mockAgent", "mockApplicationName", config, new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService());
|
||||
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
|
||||
|
||||
return new MockAgent(agentOption, binder);
|
||||
}
|
||||
|
||||
public MockAgent(AgentOption agentOption) {
|
||||
this(agentOption, new TestInterceptorRegistryBinder());
|
||||
}
|
||||
|
||||
public MockAgent(AgentOption agentOption, InterceptorRegistryBinder binder) {
|
||||
super(agentOption, binder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataSender createUdpStatDataSender(int port, String threadName, int writeQueueSize, int timeout, int sendBufferSize) {
|
||||
return new ListenableDataSender<TBase<?, ?>>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataSender createUdpSpanDataSender(int port, String threadName, int writeQueueSize, int timeout, int sendBufferSize) {
|
||||
return new ListenableDataSender<TBase<?, ?>>();
|
||||
}
|
||||
|
||||
public DataSender getSpanDataSender() {
|
||||
return super.getSpanDataSender();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected StorageFactory createStorageFactory() {
|
||||
return new SimpleSpanStorageFactory(super.getSpanDataSender());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected EnhancedDataSender createTcpDataSender(CommandDispatcher commandDispatcher) {
|
||||
return new TestTcpDataSender();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerMetaDataHolder createServerMetaDataHolder() {
|
||||
List<String> vmArgs = RuntimeMXBeanUtils.getVmArgs();
|
||||
return new ResettableServerMetaDataHolder(vmArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultProfilerPluginContext> loadPlugins(AgentOption agentOption) {
|
||||
List<DefaultProfilerPluginContext> pluginContexts = new ArrayList<DefaultProfilerPluginContext>();
|
||||
ClassInjector classInjector = new TestProfilerPluginClassLoader();
|
||||
|
||||
List<ProfilerPlugin> plugins = PluginLoader.load(ProfilerPlugin.class, ClassLoader.getSystemClassLoader());
|
||||
|
||||
for (ProfilerPlugin plugin : plugins) {
|
||||
final DefaultProfilerPluginContext context = new DefaultProfilerPluginContext(this, classInjector);
|
||||
final GuardProfilerPluginContext guard = new GuardProfilerPluginContext(context);
|
||||
try {
|
||||
preparePlugin(plugin, context);
|
||||
plugin.setup(guard);
|
||||
} finally {
|
||||
guard.close();
|
||||
}
|
||||
pluginContexts.add(context);
|
||||
}
|
||||
|
||||
|
||||
return pluginContexts;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO duplicated code : com/navercorp/pinpoint/profiler/plugin/ProfilerPluginLoader.java
|
||||
* @param plugin
|
||||
* @param context
|
||||
*/
|
||||
private void preparePlugin(ProfilerPlugin plugin, InstrumentContext context) {
|
||||
|
||||
if (plugin instanceof TransformTemplateAware) {
|
||||
final TransformTemplate transformTemplate = new TransformTemplate(context);
|
||||
((TransformTemplateAware) plugin).setTransformTemplate(transformTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String toString(Span span) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append('(');
|
||||
builder.append(span.getServiceType());
|
||||
builder.append(", [");
|
||||
appendAnnotations(builder, span.getAnnotations());
|
||||
builder.append("])");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String toString(SpanEvent span) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append('(');
|
||||
builder.append(span.getServiceType());
|
||||
builder.append(", [");
|
||||
appendAnnotations(builder, span.getAnnotations());
|
||||
builder.append("])");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void appendAnnotations(StringBuilder builder, List<TAnnotation> annotations) {
|
||||
boolean first = true;
|
||||
|
||||
if (annotations != null) {
|
||||
for (TAnnotation a : annotations) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
builder.append(", ");
|
||||
}
|
||||
|
||||
builder.append(toString(a));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String toString(TAnnotation a) {
|
||||
return a.getKey() + "=" + a.getValue().getFieldValue();
|
||||
}
|
||||
|
||||
public static String toString(short serviceCode, ExpectedAnnotation...annotations) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append('(');
|
||||
builder.append(serviceCode);
|
||||
builder.append(", ");
|
||||
builder.append(Arrays.deepToString(annotations));
|
||||
builder.append(")");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
+23
-23
@@ -35,16 +35,16 @@ public class OrderedSpanRecorder implements ListenableDataSender.Listener, Itera
|
||||
private static final int ASYNC_ID_NOT_SET = -1;
|
||||
|
||||
private final List<Item> list = new ArrayList<Item>();
|
||||
|
||||
|
||||
private static final class Item implements Comparable<Item> {
|
||||
|
||||
|
||||
|
||||
private final TBase<?, ?> value;
|
||||
private final long time;
|
||||
private final long spanId;
|
||||
private final int sequence;
|
||||
private final int asyncId;
|
||||
|
||||
|
||||
public Item(TBase<?, ?> value, long time, long spanId, int sequence) {
|
||||
this(value, time, spanId, sequence, ASYNC_ID_NOT_SET);
|
||||
}
|
||||
@@ -74,12 +74,12 @@ public class OrderedSpanRecorder implements ListenableDataSender.Listener, Itera
|
||||
} else if (this.asyncId > o.asyncId) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// if both async events have the same asyncId, do normal event comparison
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (this.time < o.time) {
|
||||
return -1;
|
||||
} else if (this.time > o.time) {
|
||||
@@ -97,71 +97,71 @@ public class OrderedSpanRecorder implements ListenableDataSender.Listener, Itera
|
||||
} else {
|
||||
int h1 = System.identityHashCode(this.value);
|
||||
int h2 = System.identityHashCode(o.value);
|
||||
|
||||
|
||||
return h1 < h2 ? -1 : (h1 > h2 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized boolean handleSend(TBase<?, ?> data) {
|
||||
if (data instanceof Span) {
|
||||
insertSpan((Span)data);
|
||||
insertSpan((Span) data);
|
||||
return true;
|
||||
} else if (data instanceof SpanEvent) {
|
||||
handleSpanEvent((SpanEvent)data);
|
||||
handleSpanEvent((SpanEvent) data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void insertSpan(Span span) {
|
||||
long startTime = span.getStartTime();
|
||||
long spanId = span.getSpanId();
|
||||
|
||||
insertItem(new Item(span, startTime, spanId, ROOT_SEQUENCE));
|
||||
}
|
||||
|
||||
|
||||
private void insertItem(Item item) {
|
||||
int pos = Collections.binarySearch(list, item);
|
||||
|
||||
|
||||
if (pos >= 0) {
|
||||
throw new IllegalArgumentException("Duplicated?? list: " + list + ", item: " + item);
|
||||
}
|
||||
|
||||
|
||||
int index = -(pos + 1);
|
||||
list.add(index, item);
|
||||
}
|
||||
|
||||
|
||||
private void handleSpanEvent(SpanEvent event) {
|
||||
Span span = event.getSpan();
|
||||
int asyncId = event.isSetAsyncId() ? event.getAsyncId() : ASYNC_ID_NOT_SET;
|
||||
insertItem(new Item(event, span.getStartTime() + event.getStartElapsed(), span.getSpanId(), event.getSequence(), asyncId));
|
||||
}
|
||||
|
||||
|
||||
public synchronized TBase<?, ?> pop() {
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return list.remove(0).value;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void print(PrintStream out) {
|
||||
out.println("TRACES(" + list.size() + "):");
|
||||
|
||||
|
||||
for (TBase<?, ?> obj : this) {
|
||||
out.println(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized void clear() {
|
||||
list.clear();
|
||||
}
|
||||
|
||||
|
||||
public synchronized int size() {
|
||||
return list.size();
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class OrderedSpanRecorder implements ListenableDataSender.Listener, Itera
|
||||
if (current == -1) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
||||
list.remove(current);
|
||||
current = -1;
|
||||
index--;
|
||||
+1
-1
@@ -587,7 +587,7 @@ public class PluginTestAgent extends DefaultAgent implements PluginTestVerifier
|
||||
|
||||
private static boolean equals(Object expected, Object actual) {
|
||||
// if expected is null, no need to compare.
|
||||
return expected == null ? true : (expected.equals(actual));
|
||||
return expected == null || (expected.equals(actual));
|
||||
}
|
||||
|
||||
private void verifySpan(ResolvedExpectedTrace expected, ActualTrace actual) {
|
||||
+37
-37
@@ -1,37 +1,37 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder;
|
||||
|
||||
/**
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
public class ResettableServerMetaDataHolder extends DefaultServerMetaDataHolder {
|
||||
|
||||
public ResettableServerMetaDataHolder(List<String> vmArgs) {
|
||||
super(vmArgs);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.serverName = null;
|
||||
this.serviceInfos.clear();
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataHolder;
|
||||
|
||||
/**
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
public class ResettableServerMetaDataHolder extends DefaultServerMetaDataHolder {
|
||||
|
||||
public ResettableServerMetaDataHolder(List<String> vmArgs) {
|
||||
super(vmArgs);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.serverName = null;
|
||||
this.serviceInfos.clear();
|
||||
}
|
||||
|
||||
}
|
||||
+42
-42
@@ -1,42 +1,42 @@
|
||||
/*
|
||||
* Copyright 2015 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import com.navercorp.pinpoint.common.Version;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class TestAgentInformation extends AgentInformation {
|
||||
|
||||
private static final String AGENT_ID = "test-agent";
|
||||
private static final String APPLICATION_NAME = "TEST_APPLICATION";
|
||||
private static final int PID = 10;
|
||||
private static final String MACHINE_NAME = "test-machine";
|
||||
private static final String HOST_IP = "127.0.0.1";
|
||||
private static final ServiceType SERVICE_TYPE = ServiceType.TEST_STAND_ALONE;
|
||||
private static final String JVM_VERSION = JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION);
|
||||
private static final String AGENT_VERSION = Version.VERSION;
|
||||
|
||||
public TestAgentInformation() {
|
||||
super(AGENT_ID, APPLICATION_NAME, System.currentTimeMillis(), PID, MACHINE_NAME, HOST_IP, SERVICE_TYPE, JVM_VERSION, AGENT_VERSION);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2015 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import com.navercorp.pinpoint.common.Version;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class TestAgentInformation extends AgentInformation {
|
||||
|
||||
private static final String AGENT_ID = "test-agent";
|
||||
private static final String APPLICATION_NAME = "TEST_APPLICATION";
|
||||
private static final int PID = 10;
|
||||
private static final String MACHINE_NAME = "test-machine";
|
||||
private static final String HOST_IP = "127.0.0.1";
|
||||
private static final ServiceType SERVICE_TYPE = ServiceType.TEST_STAND_ALONE;
|
||||
private static final String JVM_VERSION = JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION);
|
||||
private static final String AGENT_VERSION = Version.VERSION;
|
||||
|
||||
public TestAgentInformation() {
|
||||
super(AGENT_ID, APPLICATION_NAME, System.currentTimeMillis(), PID, MACHINE_NAME, HOST_IP, SERVICE_TYPE, JVM_VERSION, AGENT_VERSION);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Licensed 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.
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Licensed 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.
|
||||
+38
-38
@@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Copyright 2015 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaData;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder.ServerMetaDataListener;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class TestableServerMetaDataListener implements ServerMetaDataListener {
|
||||
|
||||
private volatile ServerMetaData serverMetaData;
|
||||
|
||||
@Override
|
||||
public void publishServerMetaData(ServerMetaData serverMetaData) {
|
||||
this.serverMetaData = serverMetaData;
|
||||
}
|
||||
|
||||
public ServerMetaData getServerMetaData() {
|
||||
return this.serverMetaData;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2015 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaData;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder.ServerMetaDataListener;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class TestableServerMetaDataListener implements ServerMetaDataListener {
|
||||
|
||||
private volatile ServerMetaData serverMetaData;
|
||||
|
||||
@Override
|
||||
public void publishServerMetaData(ServerMetaData serverMetaData) {
|
||||
this.serverMetaData = serverMetaData;
|
||||
}
|
||||
|
||||
public ServerMetaData getServerMetaData() {
|
||||
return this.serverMetaData;
|
||||
}
|
||||
|
||||
}
|
||||
+111
-111
@@ -1,111 +1,111 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test.junit4;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.navercorp.pinpoint.common.server.bo.SpanFactory;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.test.ListenableDataSender;
|
||||
import com.navercorp.pinpoint.test.MockAgent;
|
||||
import com.navercorp.pinpoint.test.ResettableServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.test.TestableServerMetaDataListener;
|
||||
|
||||
import org.apache.thrift.TBase;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaData;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.common.server.bo.SpanBo;
|
||||
import com.navercorp.pinpoint.common.server.bo.SpanEventBo;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
import com.navercorp.pinpoint.test.TBaseRecorder;
|
||||
|
||||
/**
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
@RunWith(value = PinpointJUnit4ClassRunner.class)
|
||||
public abstract class BasePinpointTest {
|
||||
|
||||
private volatile TBaseRecorder<? extends TBase<?, ?>> tBaseRecorder;
|
||||
private volatile ServerMetaDataHolder serverMetaDataHolder;
|
||||
private final TestableServerMetaDataListener listener = new TestableServerMetaDataListener();
|
||||
private final SpanFactory spanFactory = new SpanFactory();
|
||||
|
||||
protected List<SpanEventBo> getCurrentSpanEvents() {
|
||||
List<SpanEventBo> spanEvents = new ArrayList<SpanEventBo>();
|
||||
for (TBase<?, ?> span : this.tBaseRecorder) {
|
||||
if (span instanceof SpanEvent) {
|
||||
SpanEvent spanEvent = (SpanEvent)span;
|
||||
SpanEventBo spanEventBo = spanFactory.buildSpanEventBo(spanEvent);
|
||||
spanEvents.add(spanEventBo);
|
||||
}
|
||||
}
|
||||
return spanEvents;
|
||||
}
|
||||
|
||||
protected List<SpanBo> getCurrentRootSpans() {
|
||||
List<SpanBo> rootSpans = new ArrayList<SpanBo>();
|
||||
for (TBase<?, ?> span : this.tBaseRecorder) {
|
||||
if (span instanceof Span) {
|
||||
SpanBo spanBo = spanFactory.buildSpanBo((Span) span);
|
||||
rootSpans.add(spanBo);
|
||||
}
|
||||
}
|
||||
return rootSpans;
|
||||
}
|
||||
|
||||
protected ServerMetaData getServerMetaData() {
|
||||
return this.listener.getServerMetaData();
|
||||
}
|
||||
|
||||
private void setTBaseRecorder(TBaseRecorder tBaseRecorder) {
|
||||
this.tBaseRecorder = tBaseRecorder;
|
||||
}
|
||||
|
||||
private void setServerMetaDataHolder(ServerMetaDataHolder serverMetaDataHolder) {
|
||||
this.serverMetaDataHolder = serverMetaDataHolder;
|
||||
}
|
||||
|
||||
public void setup(TestContext testContext) {
|
||||
MockAgent mockAgent = testContext.getMockAgent();
|
||||
|
||||
DataSender spanDataSender = mockAgent.getSpanDataSender();
|
||||
if (spanDataSender instanceof ListenableDataSender) {
|
||||
ListenableDataSender listenableDataSender = (ListenableDataSender) spanDataSender;
|
||||
|
||||
final TBaseRecorder tBaseRecord = new TBaseRecorder();
|
||||
|
||||
listenableDataSender.setListener(new ListenableDataSender.Listener() {
|
||||
@Override
|
||||
public boolean handleSend(TBase<?, ?> data) {
|
||||
return tBaseRecord.add(data);
|
||||
}
|
||||
});
|
||||
setTBaseRecorder(tBaseRecord);
|
||||
}
|
||||
|
||||
ServerMetaDataHolder serverMetaDataHolder = mockAgent.getTraceContext().getServerMetaDataHolder();
|
||||
if (serverMetaDataHolder instanceof ResettableServerMetaDataHolder) {
|
||||
ResettableServerMetaDataHolder resettableServerMetaDataHolder = (ResettableServerMetaDataHolder) serverMetaDataHolder;
|
||||
this.setServerMetaDataHolder(resettableServerMetaDataHolder);
|
||||
}
|
||||
this.serverMetaDataHolder.addListener(this.listener);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test.junit4;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.navercorp.pinpoint.common.server.bo.SpanFactory;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.test.ListenableDataSender;
|
||||
import com.navercorp.pinpoint.test.MockAgent;
|
||||
import com.navercorp.pinpoint.test.ResettableServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.test.TestableServerMetaDataListener;
|
||||
|
||||
import org.apache.thrift.TBase;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaData;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.common.server.bo.SpanBo;
|
||||
import com.navercorp.pinpoint.common.server.bo.SpanEventBo;
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
import com.navercorp.pinpoint.test.TBaseRecorder;
|
||||
|
||||
/**
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
@RunWith(value = PinpointJUnit4ClassRunner.class)
|
||||
public abstract class BasePinpointTest {
|
||||
|
||||
private volatile TBaseRecorder<? extends TBase<?, ?>> tBaseRecorder;
|
||||
private volatile ServerMetaDataHolder serverMetaDataHolder;
|
||||
private final TestableServerMetaDataListener listener = new TestableServerMetaDataListener();
|
||||
private final SpanFactory spanFactory = new SpanFactory();
|
||||
|
||||
protected List<SpanEventBo> getCurrentSpanEvents() {
|
||||
List<SpanEventBo> spanEvents = new ArrayList<SpanEventBo>();
|
||||
for (TBase<?, ?> span : this.tBaseRecorder) {
|
||||
if (span instanceof SpanEvent) {
|
||||
SpanEvent spanEvent = (SpanEvent)span;
|
||||
SpanEventBo spanEventBo = spanFactory.buildSpanEventBo(spanEvent);
|
||||
spanEvents.add(spanEventBo);
|
||||
}
|
||||
}
|
||||
return spanEvents;
|
||||
}
|
||||
|
||||
protected List<SpanBo> getCurrentRootSpans() {
|
||||
List<SpanBo> rootSpans = new ArrayList<SpanBo>();
|
||||
for (TBase<?, ?> span : this.tBaseRecorder) {
|
||||
if (span instanceof Span) {
|
||||
SpanBo spanBo = spanFactory.buildSpanBo((Span) span);
|
||||
rootSpans.add(spanBo);
|
||||
}
|
||||
}
|
||||
return rootSpans;
|
||||
}
|
||||
|
||||
protected ServerMetaData getServerMetaData() {
|
||||
return this.listener.getServerMetaData();
|
||||
}
|
||||
|
||||
private void setTBaseRecorder(TBaseRecorder tBaseRecorder) {
|
||||
this.tBaseRecorder = tBaseRecorder;
|
||||
}
|
||||
|
||||
private void setServerMetaDataHolder(ServerMetaDataHolder serverMetaDataHolder) {
|
||||
this.serverMetaDataHolder = serverMetaDataHolder;
|
||||
}
|
||||
|
||||
public void setup(TestContext testContext) {
|
||||
MockAgent mockAgent = testContext.getMockAgent();
|
||||
|
||||
DataSender spanDataSender = mockAgent.getSpanDataSender();
|
||||
if (spanDataSender instanceof ListenableDataSender) {
|
||||
ListenableDataSender listenableDataSender = (ListenableDataSender) spanDataSender;
|
||||
|
||||
final TBaseRecorder tBaseRecord = new TBaseRecorder();
|
||||
|
||||
listenableDataSender.setListener(new ListenableDataSender.Listener() {
|
||||
@Override
|
||||
public boolean handleSend(TBase<?, ?> data) {
|
||||
return tBaseRecord.add(data);
|
||||
}
|
||||
});
|
||||
setTBaseRecorder(tBaseRecord);
|
||||
}
|
||||
|
||||
ServerMetaDataHolder serverMetaDataHolder = mockAgent.getTraceContext().getServerMetaDataHolder();
|
||||
if (serverMetaDataHolder instanceof ResettableServerMetaDataHolder) {
|
||||
ResettableServerMetaDataHolder resettableServerMetaDataHolder = (ResettableServerMetaDataHolder) serverMetaDataHolder;
|
||||
this.setServerMetaDataHolder(resettableServerMetaDataHolder);
|
||||
}
|
||||
this.serverMetaDataHolder.addListener(this.listener);
|
||||
}
|
||||
}
|
||||
+183
-186
@@ -1,187 +1,184 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test.junit4;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
|
||||
|
||||
import org.junit.internal.runners.model.EachTestNotifier;
|
||||
import org.junit.runner.notification.RunNotifier;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.junit.runners.model.TestClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.SpanRecorder;
|
||||
import com.navercorp.pinpoint.bootstrap.context.Trace;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
|
||||
/**
|
||||
* @author hyungil.jeong
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class PinpointJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PinpointJUnit4ClassRunner.class);
|
||||
|
||||
private static TestContext testContext;
|
||||
|
||||
public PinpointJUnit4ClassRunner(Class<?> clazz) throws InitializationError {
|
||||
super(clazz);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("PinpointJUnit4ClassRunner constructor called with [{}].", clazz);
|
||||
}
|
||||
}
|
||||
|
||||
private void beforeTestClass() {
|
||||
try {
|
||||
// TODO fix static TestContext
|
||||
if (testContext == null) {
|
||||
logger.debug("traceContext is null");
|
||||
this.testContext = new TestContext();
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
throw new RuntimeException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected TestClass createTestClass(Class<?> testClass) {
|
||||
logger.debug("createTestClass {}", testClass);
|
||||
beforeTestClass();
|
||||
return testContext.createTestClass(testClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
|
||||
beginTracing(method);
|
||||
final Thread thread = Thread.currentThread();
|
||||
ClassLoader originalClassLoader = thread.getContextClassLoader();
|
||||
try {
|
||||
thread.setContextClassLoader(this.testContext.getClassLoader());
|
||||
super.runChild(method, notifier);
|
||||
} finally {
|
||||
thread.setContextClassLoader(originalClassLoader);
|
||||
endTracing(method, notifier);
|
||||
}
|
||||
}
|
||||
|
||||
private void beginTracing(FrameworkMethod method) {
|
||||
if (shouldCreateNewTraceObject(method)) {
|
||||
TraceContext traceContext = this.testContext.getMockAgent().getTraceContext();
|
||||
Trace trace = traceContext.newTraceObject();
|
||||
SpanRecorder recorder = trace.getSpanRecorder();
|
||||
recorder.recordServiceType(ServiceType.TEST);
|
||||
}
|
||||
}
|
||||
|
||||
private void endTracing(FrameworkMethod method, RunNotifier notifier) {
|
||||
if (shouldCreateNewTraceObject(method)) {
|
||||
TraceContext traceContext = this.testContext.getMockAgent().getTraceContext();
|
||||
try {
|
||||
Trace trace = traceContext.currentRawTraceObject();
|
||||
if (trace == null) {
|
||||
// Trace is already detached from the ThreadLocal storage.
|
||||
// Happens when root trace method is tested without @IsRootSpan.
|
||||
EachTestNotifier testMethodNotifier = new EachTestNotifier(notifier, super.describeChild(method));
|
||||
String traceObjectAlreadyDetachedMessage = "Trace object already detached. If you're testing a trace root, please add @IsRootSpan to the test method";
|
||||
testMethodNotifier.addFailure(new IllegalStateException(traceObjectAlreadyDetachedMessage));
|
||||
} else {
|
||||
trace.close();
|
||||
}
|
||||
} finally {
|
||||
traceContext.removeTraceObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldCreateNewTraceObject(FrameworkMethod method) {
|
||||
IsRootSpan isRootSpan = method.getAnnotation(IsRootSpan.class);
|
||||
if (isRootSpan == null || !isRootSpan.value()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement methodInvoker(FrameworkMethod method, Object test) {
|
||||
return super.methodInvoker(method, test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withBefores(FrameworkMethod method, final Object target, Statement statement) {
|
||||
Statement before = super.withBefores(method, target, statement);
|
||||
BeforeCallbackStatement callbackStatement = new BeforeCallbackStatement(before, new Statement() {
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
setupBaseTest(target);
|
||||
}
|
||||
});
|
||||
return callbackStatement;
|
||||
}
|
||||
|
||||
private void setupBaseTest(Object test) {
|
||||
logger.debug("setupBaseTest");
|
||||
// It's safe to cast
|
||||
final Class<?> baseTestClass = this.testContext.getBaseTestClass();
|
||||
if (baseTestClass.isInstance(test)) {
|
||||
try {
|
||||
Method reset = baseTestClass.getDeclaredMethod("setup", TestContext.class);
|
||||
reset.invoke(test, this.testContext);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("setCurrentHolder Error. Caused by:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withBeforeClasses(Statement statement) {
|
||||
final Statement beforeClasses = super.withBeforeClasses(statement);
|
||||
return new BeforeCallbackStatement(beforeClasses, new Statement() {
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
beforeClass();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void beforeClass() throws Throwable {
|
||||
logger.debug("beforeClass");
|
||||
// TODO MockAgent.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withAfterClasses(Statement statement) {
|
||||
final Statement afterClasses = super.withAfterClasses(statement);
|
||||
return new AfterCallbackStatement(afterClasses, new Statement() {
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
afterClass();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void afterClass() throws Throwable {
|
||||
logger.debug("afterClass");
|
||||
// TODO MockAgent.close()
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test.junit4;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
|
||||
|
||||
import org.junit.internal.runners.model.EachTestNotifier;
|
||||
import org.junit.runner.notification.RunNotifier;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.junit.runners.model.TestClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.SpanRecorder;
|
||||
import com.navercorp.pinpoint.bootstrap.context.Trace;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
|
||||
/**
|
||||
* @author hyungil.jeong
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class PinpointJUnit4ClassRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PinpointJUnit4ClassRunner.class);
|
||||
|
||||
private static TestContext testContext;
|
||||
|
||||
public PinpointJUnit4ClassRunner(Class<?> clazz) throws InitializationError {
|
||||
super(clazz);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("PinpointJUnit4ClassRunner constructor called with [{}].", clazz);
|
||||
}
|
||||
}
|
||||
|
||||
private void beforeTestClass() {
|
||||
try {
|
||||
// TODO fix static TestContext
|
||||
if (testContext == null) {
|
||||
logger.debug("traceContext is null");
|
||||
testContext = new TestContext();
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
throw new RuntimeException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected TestClass createTestClass(Class<?> testClass) {
|
||||
logger.debug("createTestClass {}", testClass);
|
||||
beforeTestClass();
|
||||
return testContext.createTestClass(testClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
|
||||
beginTracing(method);
|
||||
final Thread thread = Thread.currentThread();
|
||||
ClassLoader originalClassLoader = thread.getContextClassLoader();
|
||||
try {
|
||||
thread.setContextClassLoader(testContext.getClassLoader());
|
||||
super.runChild(method, notifier);
|
||||
} finally {
|
||||
thread.setContextClassLoader(originalClassLoader);
|
||||
endTracing(method, notifier);
|
||||
}
|
||||
}
|
||||
|
||||
private void beginTracing(FrameworkMethod method) {
|
||||
if (shouldCreateNewTraceObject(method)) {
|
||||
TraceContext traceContext = testContext.getMockAgent().getTraceContext();
|
||||
Trace trace = traceContext.newTraceObject();
|
||||
SpanRecorder recorder = trace.getSpanRecorder();
|
||||
recorder.recordServiceType(ServiceType.TEST);
|
||||
}
|
||||
}
|
||||
|
||||
private void endTracing(FrameworkMethod method, RunNotifier notifier) {
|
||||
if (shouldCreateNewTraceObject(method)) {
|
||||
TraceContext traceContext = testContext.getMockAgent().getTraceContext();
|
||||
try {
|
||||
Trace trace = traceContext.currentRawTraceObject();
|
||||
if (trace == null) {
|
||||
// Trace is already detached from the ThreadLocal storage.
|
||||
// Happens when root trace method is tested without @IsRootSpan.
|
||||
EachTestNotifier testMethodNotifier = new EachTestNotifier(notifier, super.describeChild(method));
|
||||
String traceObjectAlreadyDetachedMessage = "Trace object already detached. If you're testing a trace root, please add @IsRootSpan to the test method";
|
||||
testMethodNotifier.addFailure(new IllegalStateException(traceObjectAlreadyDetachedMessage));
|
||||
} else {
|
||||
trace.close();
|
||||
}
|
||||
} finally {
|
||||
traceContext.removeTraceObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldCreateNewTraceObject(FrameworkMethod method) {
|
||||
IsRootSpan isRootSpan = method.getAnnotation(IsRootSpan.class);
|
||||
return isRootSpan == null || !isRootSpan.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement methodInvoker(FrameworkMethod method, Object test) {
|
||||
return super.methodInvoker(method, test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withBefores(FrameworkMethod method, final Object target, Statement statement) {
|
||||
Statement before = super.withBefores(method, target, statement);
|
||||
BeforeCallbackStatement callbackStatement = new BeforeCallbackStatement(before, new Statement() {
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
setupBaseTest(target);
|
||||
}
|
||||
});
|
||||
return callbackStatement;
|
||||
}
|
||||
|
||||
private void setupBaseTest(Object test) {
|
||||
logger.debug("setupBaseTest");
|
||||
// It's safe to cast
|
||||
final Class<?> baseTestClass = testContext.getBaseTestClass();
|
||||
if (baseTestClass.isInstance(test)) {
|
||||
try {
|
||||
Method reset = baseTestClass.getDeclaredMethod("setup", TestContext.class);
|
||||
reset.invoke(test, testContext);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("setCurrentHolder Error. Caused by:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withBeforeClasses(Statement statement) {
|
||||
final Statement beforeClasses = super.withBeforeClasses(statement);
|
||||
return new BeforeCallbackStatement(beforeClasses, new Statement() {
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
beforeClass();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void beforeClass() throws Throwable {
|
||||
logger.debug("beforeClass");
|
||||
// TODO MockAgent.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withAfterClasses(Statement statement) {
|
||||
final Statement afterClasses = super.withAfterClasses(statement);
|
||||
return new AfterCallbackStatement(afterClasses, new Statement() {
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
afterClass();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void afterClass() throws Throwable {
|
||||
logger.debug("afterClass");
|
||||
// TODO MockAgent.close()
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -19,6 +19,8 @@ package com.navercorp.pinpoint.test.junit4;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.navercorp.pinpoint.test.classloader.TestClassLoader;
|
||||
import com.navercorp.pinpoint.test.classloader.TestClassLoaderFactory;
|
||||
import org.junit.runners.model.TestClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -27,8 +29,6 @@ import com.navercorp.pinpoint.bootstrap.logging.PLoggerBinder;
|
||||
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.navercorp.pinpoint.profiler.logging.Slf4jLoggerBinder;
|
||||
import com.navercorp.pinpoint.test.MockAgent;
|
||||
import com.navercorp.pinpoint.test.classloader.TestClassLoader;
|
||||
import com.navercorp.pinpoint.test.classloader.TestClassLoaderFactory;
|
||||
|
||||
/**
|
||||
* @author hyungil.jeong
|
||||
+1
-1
@@ -122,7 +122,7 @@ public final class BytecodeUtils {
|
||||
}
|
||||
} finally {
|
||||
if (close) {
|
||||
is.close();
|
||||
close(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-5
@@ -38,11 +38,7 @@ public final class LoaderUtils {
|
||||
}
|
||||
Loader loader;
|
||||
if (SECURITY_MANAGER != null) {
|
||||
loader = AccessController.doPrivileged(new PrivilegedAction<Loader>() {
|
||||
public Loader run() {
|
||||
return new Loader(classPool);
|
||||
}
|
||||
});
|
||||
loader = AccessController.doPrivileged(new LoaderCreateAction(classPool));
|
||||
} else {
|
||||
loader = new Loader(classPool);
|
||||
}
|
||||
@@ -50,4 +46,20 @@ public final class LoaderUtils {
|
||||
return loader;
|
||||
}
|
||||
|
||||
static class LoaderCreateAction implements PrivilegedAction<Loader> {
|
||||
private final ClassPool classPool;
|
||||
|
||||
public LoaderCreateAction(final ClassPool classPool) {
|
||||
if (classPool == null) {
|
||||
throw new NullPointerException("classPool must not be null");
|
||||
}
|
||||
this.classPool = classPool;
|
||||
}
|
||||
|
||||
public Loader run() {
|
||||
return new Loader(classPool);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+172
-172
@@ -1,172 +1,172 @@
|
||||
/*
|
||||
* Copyright 2015 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.thrift.TBase;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class OrderedSpanRecorderTest {
|
||||
|
||||
private static final int UNSET_ASYNC_ID = 0;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final OrderedSpanRecorder recorder = new OrderedSpanRecorder();
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
this.recorder.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderingWithSameEventTime() {
|
||||
// given
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final long spanId = 1L;
|
||||
Span span = createSpan(startTime, spanId);
|
||||
SpanEvent event = createSpanEvent(span, 0, (short)0);
|
||||
SpanEvent event1 = createSpanEvent(span, 0, (short)1);
|
||||
SpanEvent event2 = createSpanEvent(span, 0, (short)2);
|
||||
SpanEvent asyncEvent1 = createAsyncSpanEvent(span, 0, (short)0, 1);
|
||||
SpanEvent asyncEvent1_1 = createAsyncSpanEvent(span, 0, (short)1, 1);
|
||||
SpanEvent asyncEvent2 = createAsyncSpanEvent(span, 0, (short)0, 2);
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<? extends TBase<?,?>> expectedOrder = Arrays.asList(
|
||||
span,
|
||||
event,
|
||||
event1,
|
||||
event2,
|
||||
asyncEvent1,
|
||||
asyncEvent1_1,
|
||||
asyncEvent2
|
||||
);
|
||||
// when
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<? extends TBase<?,?>> listToBeHandled = Arrays.asList(
|
||||
span, event, event1, event2, asyncEvent1, asyncEvent1_1, asyncEvent2
|
||||
);
|
||||
Collections.shuffle(listToBeHandled);
|
||||
for (TBase<?,?> base : listToBeHandled) {
|
||||
this.recorder.handleSend(base);
|
||||
}
|
||||
// then
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
this.recorder.print(new PrintStream(baos));
|
||||
this.logger.info(baos.toString());
|
||||
for (TBase<?,?> expectedBase : expectedOrder) {
|
||||
TBase<?,?> actualBase = this.recorder.pop();
|
||||
assertSame(expectedBase, actualBase);
|
||||
}
|
||||
assertNull(this.recorder.pop());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSpanOrdering() {
|
||||
// given
|
||||
final long startTime1 = System.currentTimeMillis();
|
||||
final long spanId1 = 1L;
|
||||
final long startTime2 = startTime1 + 10L;
|
||||
final long spanId2 = 2L;
|
||||
Span span1 = createSpan(startTime1, spanId1);
|
||||
SpanEvent event1_0 = createSpanEvent(span1, 1, (short)0);
|
||||
SpanEvent event1_1 = createSpanEvent(span1, 2, (short)1);
|
||||
SpanEvent asyncEvent1_0 = createAsyncSpanEvent(span1, 1, (short)0, 1);
|
||||
SpanEvent asyncEvent1_1 = createAsyncSpanEvent(span1, 2, (short)1, 1);
|
||||
Span span2 = createSpan(startTime2, spanId2);
|
||||
SpanEvent event2_0 = createSpanEvent(span2, 0, (short)0);
|
||||
SpanEvent event2_1 = createSpanEvent(span2, 1, (short)1);
|
||||
SpanEvent asyncEvent2_0 = createAsyncSpanEvent(span2, 0, (short)0, 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<? extends TBase<?,?>> expectedOrder = Arrays.asList(
|
||||
span1,
|
||||
event1_0,
|
||||
event1_1,
|
||||
span2,
|
||||
event2_0,
|
||||
event2_1,
|
||||
asyncEvent1_0,
|
||||
asyncEvent1_1,
|
||||
asyncEvent2_0
|
||||
);
|
||||
// when
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<? extends TBase<?,?>> listToBeHandled = Arrays.asList(
|
||||
span1, event1_0, event1_1, span2, event2_0, event2_1, asyncEvent1_0, asyncEvent1_1, asyncEvent2_0
|
||||
);
|
||||
Collections.shuffle(listToBeHandled);
|
||||
for (TBase<?,?> base : listToBeHandled) {
|
||||
this.recorder.handleSend(base);
|
||||
}
|
||||
// then
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
this.recorder.print(new PrintStream(baos));
|
||||
this.logger.info(baos.toString());
|
||||
for (TBase<?,?> expectedBase : expectedOrder) {
|
||||
TBase<?,?> actualBase = this.recorder.pop();
|
||||
assertSame(expectedBase, actualBase);
|
||||
}
|
||||
assertNull(this.recorder.pop());
|
||||
}
|
||||
|
||||
private SpanEvent createSpanEvent(Span associatedSpan, int startElapsed, short sequence) {
|
||||
return createAsyncSpanEvent(associatedSpan, startElapsed, sequence, UNSET_ASYNC_ID);
|
||||
}
|
||||
|
||||
private SpanEvent createAsyncSpanEvent(Span associatedSpan, int startElapsed, short sequence, int asyncId) {
|
||||
if (startElapsed < 0) {
|
||||
throw new IllegalArgumentException("startElapsed cannot be less than 0");
|
||||
}
|
||||
if (sequence < 0) {
|
||||
throw new IllegalArgumentException("sequence cannot be less than 0");
|
||||
}
|
||||
if (asyncId < 0) {
|
||||
throw new IllegalArgumentException("asyncId cannot be less than 0");
|
||||
}
|
||||
SpanEvent event = new SpanEvent(associatedSpan);
|
||||
event.setStartElapsed(startElapsed);
|
||||
event.setSequence(sequence);
|
||||
if (asyncId != UNSET_ASYNC_ID) {
|
||||
event.setAsyncId(asyncId);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
private Span createSpan(long startTime, long spanId) {
|
||||
Span span = new Span();
|
||||
span.setStartTime(startTime);
|
||||
span.setSpanId(spanId);
|
||||
return span;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2015 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.thrift.TBase;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.Span;
|
||||
import com.navercorp.pinpoint.profiler.context.SpanEvent;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class OrderedSpanRecorderTest {
|
||||
|
||||
private static final int UNSET_ASYNC_ID = 0;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final OrderedSpanRecorder recorder = new OrderedSpanRecorder();
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
this.recorder.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderingWithSameEventTime() {
|
||||
// given
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final long spanId = 1L;
|
||||
Span span = createSpan(startTime, spanId);
|
||||
SpanEvent event = createSpanEvent(span, 0, (short)0);
|
||||
SpanEvent event1 = createSpanEvent(span, 0, (short)1);
|
||||
SpanEvent event2 = createSpanEvent(span, 0, (short)2);
|
||||
SpanEvent asyncEvent1 = createAsyncSpanEvent(span, 0, (short)0, 1);
|
||||
SpanEvent asyncEvent1_1 = createAsyncSpanEvent(span, 0, (short)1, 1);
|
||||
SpanEvent asyncEvent2 = createAsyncSpanEvent(span, 0, (short)0, 2);
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<? extends TBase<?,?>> expectedOrder = Arrays.asList(
|
||||
span,
|
||||
event,
|
||||
event1,
|
||||
event2,
|
||||
asyncEvent1,
|
||||
asyncEvent1_1,
|
||||
asyncEvent2
|
||||
);
|
||||
// when
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<? extends TBase<?,?>> listToBeHandled = Arrays.asList(
|
||||
span, event, event1, event2, asyncEvent1, asyncEvent1_1, asyncEvent2
|
||||
);
|
||||
Collections.shuffle(listToBeHandled);
|
||||
for (TBase<?,?> base : listToBeHandled) {
|
||||
this.recorder.handleSend(base);
|
||||
}
|
||||
// then
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
this.recorder.print(new PrintStream(baos));
|
||||
this.logger.debug(baos.toString());
|
||||
for (TBase<?,?> expectedBase : expectedOrder) {
|
||||
TBase<?,?> actualBase = this.recorder.pop();
|
||||
assertSame(expectedBase, actualBase);
|
||||
}
|
||||
assertNull(this.recorder.pop());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSpanOrdering() {
|
||||
// given
|
||||
final long startTime1 = System.currentTimeMillis();
|
||||
final long spanId1 = 1L;
|
||||
final long startTime2 = startTime1 + 10L;
|
||||
final long spanId2 = 2L;
|
||||
Span span1 = createSpan(startTime1, spanId1);
|
||||
SpanEvent event1_0 = createSpanEvent(span1, 1, (short)0);
|
||||
SpanEvent event1_1 = createSpanEvent(span1, 2, (short)1);
|
||||
SpanEvent asyncEvent1_0 = createAsyncSpanEvent(span1, 1, (short)0, 1);
|
||||
SpanEvent asyncEvent1_1 = createAsyncSpanEvent(span1, 2, (short)1, 1);
|
||||
Span span2 = createSpan(startTime2, spanId2);
|
||||
SpanEvent event2_0 = createSpanEvent(span2, 0, (short)0);
|
||||
SpanEvent event2_1 = createSpanEvent(span2, 1, (short)1);
|
||||
SpanEvent asyncEvent2_0 = createAsyncSpanEvent(span2, 0, (short)0, 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<? extends TBase<?,?>> expectedOrder = Arrays.asList(
|
||||
span1,
|
||||
event1_0,
|
||||
event1_1,
|
||||
span2,
|
||||
event2_0,
|
||||
event2_1,
|
||||
asyncEvent1_0,
|
||||
asyncEvent1_1,
|
||||
asyncEvent2_0
|
||||
);
|
||||
// when
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<? extends TBase<?,?>> listToBeHandled = Arrays.asList(
|
||||
span1, event1_0, event1_1, span2, event2_0, event2_1, asyncEvent1_0, asyncEvent1_1, asyncEvent2_0
|
||||
);
|
||||
Collections.shuffle(listToBeHandled);
|
||||
for (TBase<?,?> base : listToBeHandled) {
|
||||
this.recorder.handleSend(base);
|
||||
}
|
||||
// then
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
this.recorder.print(new PrintStream(baos));
|
||||
this.logger.debug(baos.toString());
|
||||
for (TBase<?,?> expectedBase : expectedOrder) {
|
||||
TBase<?,?> actualBase = this.recorder.pop();
|
||||
assertSame(expectedBase, actualBase);
|
||||
}
|
||||
assertNull(this.recorder.pop());
|
||||
}
|
||||
|
||||
private SpanEvent createSpanEvent(Span associatedSpan, int startElapsed, short sequence) {
|
||||
return createAsyncSpanEvent(associatedSpan, startElapsed, sequence, UNSET_ASYNC_ID);
|
||||
}
|
||||
|
||||
private SpanEvent createAsyncSpanEvent(Span associatedSpan, int startElapsed, short sequence, int asyncId) {
|
||||
if (startElapsed < 0) {
|
||||
throw new IllegalArgumentException("startElapsed cannot be less than 0");
|
||||
}
|
||||
if (sequence < 0) {
|
||||
throw new IllegalArgumentException("sequence cannot be less than 0");
|
||||
}
|
||||
if (asyncId < 0) {
|
||||
throw new IllegalArgumentException("asyncId cannot be less than 0");
|
||||
}
|
||||
SpanEvent event = new SpanEvent(associatedSpan);
|
||||
event.setStartElapsed(startElapsed);
|
||||
event.setSequence(sequence);
|
||||
if (asyncId != UNSET_ASYNC_ID) {
|
||||
event.setAsyncId(asyncId);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
private Span createSpan(long startTime, long spanId) {
|
||||
Span span = new Span();
|
||||
span.setStartTime(startTime);
|
||||
span.setSpanId(spanId);
|
||||
return span;
|
||||
}
|
||||
|
||||
}
|
||||
+11
-9
@@ -14,14 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit;
|
||||
|
||||
|
||||
import com.navercorp.pinpoint.test.util.LoaderUtils;
|
||||
|
||||
import javassist.*;
|
||||
import javassist.expr.ExprEditor;
|
||||
import javassist.expr.MethodCall;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -31,7 +32,8 @@ import java.lang.reflect.InvocationTargetException;
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class JavaAssistTest {
|
||||
@Deprecated
|
||||
public class JavaAssistInterceptorTest {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
|
||||
@@ -40,7 +42,7 @@ public class JavaAssistTest {
|
||||
ClassPool pool = new ClassPool(true);
|
||||
Loader loader = getLoader(pool);
|
||||
|
||||
CtClass ctClass = pool.get("com.navercorp.pinpoint.profiler.interceptor.bci.TestObject");
|
||||
CtClass ctClass = pool.get("com.navercorp.pinpoint.test.javasssit.mock.TestObject");
|
||||
CtClass object = pool.get("java.lang.String");
|
||||
|
||||
logger.debug("target:{}", ctClass);
|
||||
@@ -83,7 +85,7 @@ public class JavaAssistTest {
|
||||
public void afterCatch2() throws NotFoundException, CannotCompileException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException, ClassNotFoundException {
|
||||
ClassPool pool = new ClassPool(true);
|
||||
Loader loader = getLoader(pool);
|
||||
CtClass ctClass = pool.get("com.navercorp.pinpoint.profiler.interceptor.bci.TestObject");
|
||||
CtClass ctClass = pool.get("com.navercorp.pinpoint.test.javasssit.mock.TestObject");
|
||||
CtClass object = pool.get("java.lang.String");
|
||||
logger.debug("target:{}", ctClass);
|
||||
|
||||
@@ -109,7 +111,7 @@ public class JavaAssistTest {
|
||||
Loader loader = getLoader(pool);
|
||||
|
||||
|
||||
CtClass ctClass = pool.get("com.navercorp.pinpoint.profiler.interceptor.bci.TestObject");
|
||||
CtClass ctClass = pool.get("com.navercorp.pinpoint.test.javasssit.mock.TestObject");
|
||||
CtClass object = pool.get("java.lang.String");
|
||||
logger.debug("target:{}", ctClass);
|
||||
|
||||
@@ -118,9 +120,9 @@ public class JavaAssistTest {
|
||||
callA.addLocalVariable("__test", object);
|
||||
String inti = "__test = \"abc\";";
|
||||
// callA.insertBefore("__test = \"abc\";);
|
||||
callA.insertBefore("{com.navercorp.pinpoint.profiler.interceptor.bci.TestObject.before();}");
|
||||
callA.insertAfter("{com.navercorp.pinpoint.profiler.interceptor.bci.TestObject.after();}");
|
||||
callA.addCatch("{ com.navercorp.pinpoint.profiler.interceptor.bci.TestObject.callCatch(); throw $e; }", pool.get("java.lang.Throwable"));
|
||||
callA.insertBefore("{com.navercorp.pinpoint.test.javasssit.mock.TestObject.before();}");
|
||||
callA.insertAfter("{com.navercorp.pinpoint.test.javasssit.mock.TestObject.after();}");
|
||||
callA.addCatch("{ com.navercorp.pinpoint.test.javasssit.mock.TestObject.callCatch(); throw $e; }", pool.get("java.lang.Throwable"));
|
||||
|
||||
Class aClass = loader.loadClass(ctClass.getName());
|
||||
java.lang.reflect.Method callA1 = aClass.getMethod("callA");
|
||||
+25
-29
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.javaassist;
|
||||
package com.navercorp.pinpoint.test.javasssit;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
@@ -32,6 +32,7 @@ import java.util.Arrays;
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Deprecated
|
||||
public class JavaAssistTest {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@@ -44,16 +45,11 @@ public class JavaAssistTest {
|
||||
pool.appendSystemPath();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newClass() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssist() throws NotFoundException, NoSuchMethodException {
|
||||
|
||||
CtClass ctClass = pool.get(String.class.getName());
|
||||
logger.info(ctClass.toString());
|
||||
logger.debug(ctClass.toString());
|
||||
String s = "";
|
||||
// ctClass.getMethod("valueOf", "(D)");
|
||||
|
||||
@@ -63,15 +59,15 @@ public class JavaAssistTest {
|
||||
// }
|
||||
|
||||
CtMethod endsWith = ctClass.getMethod("endsWith", "(Ljava/lang/String;)Z");
|
||||
logger.info(endsWith.getMethodInfo().toString());
|
||||
logger.info(endsWith.getSignature());
|
||||
logger.info(endsWith.getLongName());
|
||||
logger.info(endsWith.toString());
|
||||
logger.info(endsWith.getName());
|
||||
logger.info(endsWith.getMethodInfo().getName());
|
||||
logger.info(endsWith.getMethodInfo().getDescriptor());
|
||||
logger.debug(endsWith.getMethodInfo().toString());
|
||||
logger.debug(endsWith.getSignature());
|
||||
logger.debug(endsWith.getLongName());
|
||||
logger.debug(endsWith.toString());
|
||||
logger.debug(endsWith.getName());
|
||||
logger.debug(endsWith.getMethodInfo().getName());
|
||||
logger.debug(endsWith.getMethodInfo().getDescriptor());
|
||||
|
||||
Method endsWith1 = String.class.getMethod("endsWith", new Class[]{String.class});
|
||||
Method endsWith1 = String.class.getMethod("endsWith", String.class);
|
||||
logger.debug(endsWith1.toString());
|
||||
|
||||
}
|
||||
@@ -85,29 +81,29 @@ public class JavaAssistTest {
|
||||
|
||||
private void sout(String str) {
|
||||
URL resource = this.getClass().getClassLoader().getResource(str);
|
||||
logger.info("{}", resource);
|
||||
logger.debug("{}", resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void genericTest() throws NotFoundException {
|
||||
CtClass testClass = pool.get("com.navercorp.pinpoint.profiler.javaassist.TestClass");
|
||||
CtClass testClass = pool.get("com.navercorp.pinpoint.test.javasssit.TestClass");
|
||||
// CtMethod setb = testClass.getMethod("setb");
|
||||
CtMethod[] declaredMethods = testClass.getDeclaredMethods();
|
||||
for (CtMethod declaredMethod : declaredMethods) {
|
||||
logger.info(declaredMethod.toString());
|
||||
logger.info(declaredMethod.getGenericSignature());
|
||||
logger.info(declaredMethod.getSignature());
|
||||
logger.info("paramTypes:{}", Arrays.toString(declaredMethod.getParameterTypes()));
|
||||
logger.info(declaredMethod.getMethodInfo2().getDescriptor());
|
||||
logger.info(declaredMethod.getMethodInfo().getDescriptor());
|
||||
// logger.info(declaredMethod.());
|
||||
logger.debug(declaredMethod.toString());
|
||||
logger.debug(declaredMethod.getGenericSignature());
|
||||
logger.debug(declaredMethod.getSignature());
|
||||
logger.debug("paramTypes:{}", Arrays.toString(declaredMethod.getParameterTypes()));
|
||||
logger.debug(declaredMethod.getMethodInfo2().getDescriptor());
|
||||
logger.debug(declaredMethod.getMethodInfo().getDescriptor());
|
||||
// logger.debug(declaredMethod.());
|
||||
}
|
||||
|
||||
|
||||
CtMethod setb = testClass.getDeclaredMethod("setA", new CtClass[]{pool.get("int")});
|
||||
logger.info(setb.toString());
|
||||
logger.debug(setb.toString());
|
||||
CtMethod setStringArray = testClass.getDeclaredMethod("setStringArray", new CtClass[]{pool.get("java.lang.String[]")});
|
||||
logger.info(setStringArray.toString());
|
||||
logger.debug(setStringArray.toString());
|
||||
|
||||
|
||||
|
||||
@@ -115,17 +111,17 @@ public class JavaAssistTest {
|
||||
|
||||
@Test
|
||||
public void innerClass() throws NotFoundException {
|
||||
CtClass testClass = pool.get("com.navercorp.pinpoint.profiler.javaassist.TestClass");
|
||||
CtClass testClass = pool.get("com.navercorp.pinpoint.test.javasssit.TestClass");
|
||||
logger.debug(testClass.toString());
|
||||
CtClass[] nestedClasses = testClass.getNestedClasses();
|
||||
for(CtClass nested : nestedClasses) {
|
||||
logger.debug("nestedClass:{}", nested);
|
||||
}
|
||||
|
||||
CtClass innerClass = pool.get("com.navercorp.pinpoint.profiler.javaassist.TestClass$InnerClass");
|
||||
CtClass innerClass = pool.get("com.navercorp.pinpoint.test.javasssit.TestClass$InnerClass");
|
||||
logger.debug("{}", innerClass);
|
||||
|
||||
CtClass class1 = pool.get("com.navercorp.pinpoint.profiler.javaassist.TestClass$1");
|
||||
CtClass class1 = pool.get("com.navercorp.pinpoint.test.javasssit.TestClass$1");
|
||||
logger.debug("{}", class1);
|
||||
}
|
||||
}
|
||||
+43
-231
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,28 +12,12 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.ProtectionDomain;
|
||||
package com.navercorp.pinpoint.test.javasssit;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
import javassist.bytecode.Descriptor;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.DatabaseInfo;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.ClassFilters;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
@@ -51,10 +35,39 @@ import com.navercorp.pinpoint.profiler.interceptor.registry.GlobalInterceptorReg
|
||||
import com.navercorp.pinpoint.profiler.logging.Slf4jLoggerBinder;
|
||||
import com.navercorp.pinpoint.test.MockAgent;
|
||||
import com.navercorp.pinpoint.test.classloader.TestClassLoader;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.BindValueTraceValue;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.DatabaseInfoTraceValue;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.IntArrayGetter;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.IntArraySetter;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.IntArrayTraceValue;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.IntGetter;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.IntSetter;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.IntTraceValue;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.IntegerArrayGetter;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.IntegerArraySetter;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.IntegerArrayTraceValue;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.ObjectTraceValue;
|
||||
import com.navercorp.pinpoint.test.javasssit.accessor.StringGetter;
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
import javassist.bytecode.Descriptor;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Deprecated
|
||||
public class JavassistClassTest {
|
||||
private Logger logger = LoggerFactory.getLogger(JavassistClassTest.class.getName());
|
||||
|
||||
@@ -72,7 +85,7 @@ public class JavassistClassTest {
|
||||
public void testClassHierarchy() throws InstrumentException {
|
||||
JavassistClassPool pool = new JavassistClassPool(new GlobalInterceptorRegistryBinder(), null);
|
||||
|
||||
String testObjectName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObject";
|
||||
String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
|
||||
|
||||
byte[] testObjectByteCode = readByteCode(testObjectName);
|
||||
InstrumentClass testObject = pool.getClass(null, null, testObjectName, testObjectByteCode);
|
||||
@@ -85,7 +98,7 @@ public class JavassistClassTest {
|
||||
String[] testObjectSuperClassInterfaces = testObject.getInterfaces();
|
||||
Assert.assertEquals(testObjectSuperClassInterfaces.length, 0);
|
||||
|
||||
final String classHierarchyTestMockName = "com.navercorp.pinpoint.profiler.interceptor.bci.ClassHierarchyTestMock";
|
||||
final String classHierarchyTestMockName = "com.navercorp.pinpoint.test.javasssit.mock.ClassHierarchyTestMock";
|
||||
byte[] classHierarchyTestMockByteCode = readByteCode(classHierarchyTestMockName);
|
||||
InstrumentClass classHierarchyObject = pool.getClass(null, null, classHierarchyTestMockName, classHierarchyTestMockByteCode);
|
||||
String hierarchySuperClass = classHierarchyObject.getSuperClass();
|
||||
@@ -102,7 +115,7 @@ public class JavassistClassTest {
|
||||
|
||||
JavassistClassPool pool = new JavassistClassPool(new GlobalInterceptorRegistryBinder(), null);
|
||||
|
||||
String testObjectName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObject";
|
||||
String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
|
||||
byte[] testObjectByteCode = readByteCode(testObjectName);
|
||||
InstrumentClass testObject = pool.getClass(null, null, testObjectName, testObjectByteCode);
|
||||
|
||||
@@ -118,7 +131,7 @@ public class JavassistClassTest {
|
||||
|
||||
JavassistClassPool pool = new JavassistClassPool(new GlobalInterceptorRegistryBinder(), null);
|
||||
|
||||
String testObjectName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObject";
|
||||
String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
|
||||
byte[] testObjectByteCode = readByteCode(testObjectName);
|
||||
InstrumentClass testObject = pool.getClass(null, null, testObjectName, testObjectByteCode);
|
||||
Assert.assertEquals(testObject.getName(), testObjectName);
|
||||
@@ -136,84 +149,10 @@ public class JavassistClassTest {
|
||||
Assert.assertEquals(findMethodCount, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTraceValue() throws Exception {
|
||||
final TestClassLoader loader = getTestClassLoader();
|
||||
final String javassistClassName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObject";
|
||||
|
||||
loader.addTransformer(javassistClassName, new TransformCallback() {
|
||||
|
||||
@Override
|
||||
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
|
||||
try {
|
||||
logger.info("modify cl:{}", loader);
|
||||
|
||||
InstrumentClass aClass = instrumentor.getInstrumentClass(loader, javassistClassName, classfileBuffer);
|
||||
|
||||
aClass.addField(ObjectTraceValue.class.getName());
|
||||
aClass.addField(IntTraceValue.class.getName());
|
||||
aClass.addField(IntArrayTraceValue.class.getName());
|
||||
aClass.addField(IntegerArrayTraceValue.class.getName());
|
||||
aClass.addField(DatabaseInfoTraceValue.class.getName());
|
||||
aClass.addField(BindValueTraceValue.class.getName());
|
||||
|
||||
String methodName = "callA";
|
||||
aClass.getDeclaredMethod(methodName).addInterceptor("com.navercorp.pinpoint.profiler.interceptor.TestBeforeInterceptor");
|
||||
return aClass.toBytecode();
|
||||
} catch (InstrumentException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Class<?> testObjectClazz = loader.loadClass(javassistClassName);
|
||||
final String methodName = "callA";
|
||||
logger.info("class:{}", testObjectClazz.toString());
|
||||
final Object testObject = testObjectClazz.newInstance();
|
||||
Method callA = testObjectClazz.getMethod(methodName);
|
||||
callA.invoke(testObject);
|
||||
|
||||
Class<?> objectTraceValue = loader.loadClass(ObjectTraceValue.class.getName());
|
||||
Assert.assertTrue("ObjectTraceValue implements fail", objectTraceValue.isInstance(testObject));
|
||||
objectTraceValue.getMethod("_$PINPOINT$_setTraceObject", Object.class).invoke(testObject, "a");
|
||||
Object get = objectTraceValue.getMethod("_$PINPOINT$_getTraceObject").invoke(testObject);
|
||||
Assert.assertEquals("a", get);
|
||||
|
||||
Class<?> intTraceValue = loader.loadClass(IntTraceValue.class.getName());
|
||||
Assert.assertTrue("IntTraceValue implements fail", intTraceValue.isInstance(testObject));
|
||||
intTraceValue.getMethod("_$PINPOINT$_setTraceInt", int.class).invoke(testObject, 1);
|
||||
int a = (Integer) intTraceValue.getMethod("_$PINPOINT$_getTraceInt").invoke(testObject);
|
||||
Assert.assertEquals(1, a);
|
||||
|
||||
Class<?> intArrayTraceValue = loader.loadClass(IntArrayTraceValue.class.getName());
|
||||
Assert.assertTrue("IntArrayTraceValue implements fail", intArrayTraceValue.isInstance(testObject));
|
||||
int[] expectedInts = {1, 2, 3};
|
||||
intArrayTraceValue.getMethod("_$PINPOINT$_setTraceIntArray", int[].class).invoke(testObject, expectedInts);
|
||||
int[] ints = (int[]) intArrayTraceValue.getMethod("_$PINPOINT$_getTraceIntArray").invoke(testObject);
|
||||
Assert.assertEquals(expectedInts, ints);
|
||||
|
||||
Class<?> integerArrayTraceValue = loader.loadClass(IntegerArrayTraceValue.class.getName());
|
||||
Assert.assertTrue("IntegerArrayTraceValue implements fail", integerArrayTraceValue.isInstance(testObject));
|
||||
Integer[] expectedIntegers = {1, 2};
|
||||
// wrap due to vararg expansion
|
||||
Object[] wrappedExpectedIntegers = new Object[]{expectedIntegers};
|
||||
integerArrayTraceValue.getMethod("_$PINPOINT$_setTraceIntegerArray", Integer[].class).invoke(testObject, wrappedExpectedIntegers);
|
||||
Integer[] integers = (Integer[]) integerArrayTraceValue.getMethod("_$PINPOINT$_getTraceIntegerArray").invoke(testObject);
|
||||
Assert.assertArrayEquals(expectedIntegers, integers);
|
||||
|
||||
Class<?> databaseTraceValue = loader.loadClass(DatabaseInfoTraceValue.class.getName());
|
||||
Assert.assertTrue("DatabaseInfoTraceValue implements fail", databaseTraceValue.isInstance(testObject));
|
||||
databaseTraceValue.getMethod("_$PINPOINT$_setTraceDatabaseInfo", DatabaseInfo.class).invoke(testObject, UnKnownDatabaseInfo.INSTANCE);
|
||||
Object databaseInfo = databaseTraceValue.getMethod("_$PINPOINT$_getTraceDatabaseInfo").invoke(testObject);
|
||||
Assert.assertSame(UnKnownDatabaseInfo.INSTANCE, databaseInfo);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testBeforeAddInterceptor() throws Exception {
|
||||
final TestClassLoader loader = getTestClassLoader();
|
||||
final String javassistClassName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObject";
|
||||
final String javassistClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
|
||||
|
||||
loader.addTransformer(javassistClassName, new TransformCallback() {
|
||||
|
||||
@@ -225,7 +164,7 @@ public class JavassistClassTest {
|
||||
InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, javassistClassName, classfileBuffer);
|
||||
|
||||
String methodName = "callA";
|
||||
aClass.getDeclaredMethod(methodName).addInterceptor("com.navercorp.pinpoint.profiler.interceptor.TestBeforeInterceptor");
|
||||
aClass.getDeclaredMethod(methodName).addInterceptor("com.navercorp.pinpoint.test.javasssit.TestBeforeInterceptor");
|
||||
|
||||
return aClass.toBytecode();
|
||||
} catch (InstrumentException e) {
|
||||
@@ -243,7 +182,7 @@ public class JavassistClassTest {
|
||||
callA.invoke(testObject);
|
||||
Interceptor interceptor = getInterceptor(loader, 0);
|
||||
assertEqualsIntField(interceptor, "call", 1);
|
||||
assertEqualsObjectField(interceptor, "className", "com.navercorp.pinpoint.profiler.interceptor.bci.TestObject");
|
||||
assertEqualsObjectField(interceptor, "className", "com.navercorp.pinpoint.test.javasssit.mock.TestObject");
|
||||
assertEqualsObjectField(interceptor, "methodName", methodName);
|
||||
assertEqualsObjectField(interceptor, "args", null);
|
||||
|
||||
@@ -251,7 +190,7 @@ public class JavassistClassTest {
|
||||
}
|
||||
|
||||
private Interceptor getInterceptor(final TestClassLoader loader, int index) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
|
||||
Interceptor interceptor = (Interceptor) loader.loadClass("com.navercorp.pinpoint.profiler.interceptor.bci.TestInterceptors").getMethod("get", int.class).invoke(null, index);
|
||||
Interceptor interceptor = (Interceptor) loader.loadClass("com.navercorp.pinpoint.test.javasssit.TestInterceptors").getMethod("get", int.class).invoke(null, index);
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
@@ -284,7 +223,7 @@ public class JavassistClassTest {
|
||||
public void testAddAfterInterceptor() throws Exception {
|
||||
|
||||
final TestClassLoader loader = getTestClassLoader();
|
||||
final String testClassObject = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObject2";
|
||||
final String testClassObject = "com.navercorp.pinpoint.test.javasssit.mock.TestObject2";
|
||||
|
||||
loader.addTransformer(testClassObject, new TransformCallback() {
|
||||
|
||||
@@ -345,139 +284,12 @@ public class JavassistClassTest {
|
||||
logger.info("Descript null:{}", nullDescriptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddGetter() throws Exception {
|
||||
final TestClassLoader loader = getTestClassLoader();
|
||||
final String targetClassName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObject3";
|
||||
|
||||
|
||||
loader.addTransformer(targetClassName, new TransformCallback() {
|
||||
|
||||
@Override
|
||||
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
|
||||
try {
|
||||
logger.info("modify cl:{}", classLoader);
|
||||
InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
|
||||
|
||||
aClass.addGetter(StringGetter.class.getName(), "value");
|
||||
aClass.addGetter(IntGetter.class.getName(), "intValue");
|
||||
aClass.addGetter(IntArrayGetter.class.getName(), "intValues");
|
||||
aClass.addGetter(IntegerArrayGetter.class.getName(), "integerValues");
|
||||
|
||||
return aClass.toBytecode();
|
||||
} catch (InstrumentException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Object testObject = loader.loadClass(targetClassName).newInstance();
|
||||
|
||||
Class<?> stringGetter = loader.loadClass(StringGetter.class.getName());
|
||||
Class<?> intGetter = loader.loadClass(IntGetter.class.getName());
|
||||
Class<?> intsGetter = loader.loadClass(IntArrayGetter.class.getName());
|
||||
Class<?> integersGetter = loader.loadClass(IntegerArrayGetter.class.getName());
|
||||
|
||||
Assert.assertTrue(stringGetter.isInstance(testObject));
|
||||
Assert.assertTrue(intGetter.isInstance(testObject));
|
||||
Assert.assertTrue(intsGetter.isInstance(testObject));
|
||||
Assert.assertTrue(integersGetter.isInstance(testObject));
|
||||
|
||||
String value = "hehe";
|
||||
int intValue = 99;
|
||||
int[] intValues = {99, 100};
|
||||
Integer[] integerValues = {99, 100};
|
||||
|
||||
Method method = testObject.getClass().getMethod("setValue", String.class);
|
||||
method.invoke(testObject, value);
|
||||
|
||||
Method getString = stringGetter.getMethod("_$PINPOINT$_getString");
|
||||
Assert.assertEquals(value, getString.invoke(testObject));
|
||||
|
||||
Method setIntValue = testObject.getClass().getMethod("setIntValue", int.class);
|
||||
setIntValue.invoke(testObject, intValue);
|
||||
|
||||
Method getInt = intGetter.getMethod("_$PINPOINT$_getInt");
|
||||
Assert.assertEquals(intValue, getInt.invoke(testObject));
|
||||
|
||||
Method setIntValues = testObject.getClass().getMethod("setIntValues", int[].class);
|
||||
setIntValues.invoke(testObject, intValues);
|
||||
|
||||
Method getIntValues = intsGetter.getMethod("_$PINPOINT$_getIntArray");
|
||||
Assert.assertEquals(intValues, getIntValues.invoke(testObject));
|
||||
|
||||
Method setIntegerValues = testObject.getClass().getMethod("setIntegerValues", Integer[].class);
|
||||
// wrap due to vararg expansion
|
||||
Object[] wrappedIntegerValues = new Object[]{integerValues};
|
||||
setIntegerValues.invoke(testObject, wrappedIntegerValues);
|
||||
|
||||
Method getIntegerValues = integersGetter.getMethod("_$PINPOINT$_getIntegerArray");
|
||||
Assert.assertEquals(integerValues, getIntegerValues.invoke(testObject));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSetter() throws Exception {
|
||||
final TestClassLoader loader = getTestClassLoader();
|
||||
final String targetClassName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObject4";
|
||||
|
||||
loader.addTransformer(targetClassName, new TransformCallback() {
|
||||
@Override
|
||||
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
|
||||
try {
|
||||
logger.info("modify cl:{}", classLoader);
|
||||
InstrumentClass testClass = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
|
||||
|
||||
testClass.addSetter(IntSetter.class.getName(), "intValue");
|
||||
testClass.addSetter(IntArraySetter.class.getName(), "intValues");
|
||||
testClass.addSetter(IntegerArraySetter.class.getName(), "integerValues");
|
||||
|
||||
return testClass.toBytecode();
|
||||
} catch (InstrumentException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Object testObject = loader.loadClass(targetClassName).newInstance();
|
||||
|
||||
Class<?> intSetter = loader.loadClass(IntSetter.class.getName());
|
||||
Class<?> intsSetter = loader.loadClass(IntArraySetter.class.getName());
|
||||
Class<?> integersSetter = loader.loadClass(IntegerArraySetter.class.getName());
|
||||
|
||||
Assert.assertTrue(intSetter.isInstance(testObject));
|
||||
Assert.assertTrue(intsSetter.isInstance(testObject));
|
||||
Assert.assertTrue(integersSetter.isInstance(testObject));
|
||||
|
||||
int intValue = 99;
|
||||
int[] intValues = {99, 100};
|
||||
Integer[] integerValues = {99, 100};
|
||||
|
||||
Method setInt = intSetter.getMethod("_$PINPOINT$_setInt", int.class);
|
||||
setInt.invoke(testObject, intValue);
|
||||
Method getInt = testObject.getClass().getMethod("getIntValue");
|
||||
Assert.assertEquals(intValue, getInt.invoke(testObject));
|
||||
|
||||
Method setInts = intsSetter.getMethod("_$PINPOINT$_setIntArray", int[].class);
|
||||
setInts.invoke(testObject, intValues);
|
||||
Method getInts = testObject.getClass().getMethod("getIntValues");
|
||||
Assert.assertEquals(intValues, getInts.invoke(testObject));
|
||||
|
||||
Method setIntegers = integersSetter.getMethod("_$PINPOINT$_setIntegerArray", Integer[].class);
|
||||
// wrap due to vararg expansion
|
||||
Object[] wrappedIntegerValues = new Object[]{integerValues};
|
||||
setIntegers.invoke(testObject, wrappedIntegerValues);
|
||||
Method getIntegers = testObject.getClass().getMethod("getIntegerValues");
|
||||
Assert.assertEquals(integerValues, getIntegers.invoke(testObject));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getNestedClasses() throws Exception {
|
||||
JavassistClassPool pool = new JavassistClassPool(new GlobalInterceptorRegistryBinder(), null);
|
||||
String testObjectName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObjectNestedClass";
|
||||
String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObjectNestedClass";
|
||||
|
||||
byte[] testObjectByteCode = readByteCode(testObjectName);
|
||||
InstrumentClass testObject = pool.getClass(null, null, testObjectName, testObjectByteCode);
|
||||
@@ -502,7 +314,7 @@ public class JavassistClassTest {
|
||||
@Test
|
||||
public void hasEnclodingMethod() throws Exception {
|
||||
JavassistClassPool pool = new JavassistClassPool(new GlobalInterceptorRegistryBinder(), null);
|
||||
String testObjectName = "com.navercorp.pinpoint.profiler.interceptor.bci.TestObjectNestedClass";
|
||||
String testObjectName = "com.navercorp.pinpoint.test.javasssit.mock.TestObjectNestedClass";
|
||||
|
||||
byte[] testObjectByteCode = readByteCode(testObjectName);
|
||||
InstrumentClass testObject = pool.getClass(null, null, testObjectName, testObjectByteCode);
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test.javasssit;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.StaticAroundInterceptor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class TestBeforeInterceptor implements StaticAroundInterceptor {
|
||||
static {
|
||||
System.out.println("load TestBeforeInterceptor cl:" + TestBeforeInterceptor.class.getClassLoader());
|
||||
}
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
|
||||
|
||||
public int call = 0;
|
||||
public Object target;
|
||||
public String className;
|
||||
public String methodName;
|
||||
public Object[] args;
|
||||
|
||||
@Override
|
||||
public void before(Object target, String className, String methodName, String parameterDescription, Object[] args) {
|
||||
logger.info("BEFORE target:" + target + " " + className + "." + methodName + parameterDescription + " args:" + Arrays.toString(args));
|
||||
this.target = target;
|
||||
this.className = className;
|
||||
this.methodName = methodName;
|
||||
this.args = args;
|
||||
call++;
|
||||
|
||||
TestInterceptors.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after(Object target, String className, String methodName, String parameterDescription, Object[] args, Object result, Throwable throwable) {
|
||||
|
||||
}
|
||||
}
|
||||
+16
-24
@@ -14,14 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.javaassist;
|
||||
package com.navercorp.pinpoint.test.javasssit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
@@ -31,14 +32,14 @@ import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Deprecated
|
||||
public class TestBootstrapClass {
|
||||
|
||||
private static final String TEST_CLASS_NAME = "com.navercorp.pinpoint.profiler.javaassist.DynamicTest";
|
||||
private static final String TEST_CLASS_NAME = "com.navercorp.pinpoint.profiler.javaassist.DynamicCreateTest";
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@@ -54,44 +55,35 @@ public class TestBootstrapClass {
|
||||
CtClass ctClass = cp.makeClass(TEST_CLASS_NAME);
|
||||
byte[] bytes = ctClass.toBytecode();
|
||||
|
||||
logger.info(classLoader.getClass().getName());
|
||||
logger.debug(classLoader.getClass().getName());
|
||||
Class<?> aClass = BytecodeUtils.defineClass(classLoader, TEST_CLASS_NAME, bytes);
|
||||
|
||||
logger.info("{}", aClass.getName());
|
||||
logger.debug("{}", aClass.getName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testJdkClassClassLoader() throws IOException {
|
||||
URL url = new URL("http://test");
|
||||
|
||||
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||
logger.info(urlConnection.toString());
|
||||
logger.info("{}", urlConnection.getClass().getClassLoader());
|
||||
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
|
||||
ClassLoader parent = systemClassLoader.getParent();
|
||||
logger.info("parent:{}", parent);
|
||||
logger.info("pparent:{}", parent.getParent());
|
||||
|
||||
logger.info("{}", String.class.getClassLoader());
|
||||
logger.info("{}", TestBootstrapClass.class.getClassLoader());
|
||||
|
||||
|
||||
urlConnection.disconnect();
|
||||
logger.debug("parent:{}", parent);
|
||||
logger.debug("pparent:{}", parent.getParent());
|
||||
|
||||
logger.debug("{}", String.class.getClassLoader());
|
||||
logger.debug("{}", TestBootstrapClass.class.getClassLoader());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReflection() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
java.lang.ClassLoader contextClassLoader = java.lang.Thread.currentThread().getContextClassLoader();
|
||||
java.lang.Class<?> interceptorRegistry = contextClassLoader.loadClass("com.navercorp.pinpoint.bootstrap.interceptor.registry.GlobalInterceptorRegistry");
|
||||
java.lang.reflect.Method getInterceptorMethod = interceptorRegistry.getMethod("getInterceptor", new java.lang.Class[]{int.class});
|
||||
java.lang.Object interceptor = getInterceptorMethod.invoke(interceptorRegistry, Integer.valueOf(1));
|
||||
ClassLoader contextClassLoader = java.lang.Thread.currentThread().getContextClassLoader();
|
||||
Class<?> interceptorRegistry = contextClassLoader.loadClass("com.navercorp.pinpoint.bootstrap.interceptor.registry.GlobalInterceptorRegistry");
|
||||
Method getInterceptorMethod = interceptorRegistry.getMethod("getInterceptor", int.class);
|
||||
Object interceptor = getInterceptorMethod.invoke(interceptorRegistry, Integer.valueOf(1));
|
||||
|
||||
java.lang.reflect.Method beforeMethod = interceptor.getClass().getMethod("before", java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object[].class);
|
||||
Method beforeMethod = interceptor.getClass().getMethod("before", java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object[].class);
|
||||
beforeMethod.invoke(interceptor, null, null, null, null, null);
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.javaassist;
|
||||
package com.navercorp.pinpoint.test.javasssit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test.javasssit;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Jongho Moon
|
||||
*
|
||||
*/
|
||||
public class TestInterceptors {
|
||||
|
||||
private static final List<Interceptor> interceptors = Collections.synchronizedList(new ArrayList<Interceptor>());
|
||||
|
||||
public static void clear() {
|
||||
interceptors.clear();
|
||||
}
|
||||
|
||||
public static void add(Interceptor interceptor) {
|
||||
interceptors.add(interceptor);
|
||||
}
|
||||
|
||||
public static Interceptor get(int index) {
|
||||
return interceptors.get(index);
|
||||
}
|
||||
}
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.DatabaseInfo;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentException;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.Instrumentor;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.transformer.TransformCallback;
|
||||
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgent;
|
||||
import com.navercorp.pinpoint.profiler.logging.Slf4jLoggerBinder;
|
||||
import com.navercorp.pinpoint.test.MockAgent;
|
||||
import com.navercorp.pinpoint.test.classloader.TestClassLoader;
|
||||
import com.navercorp.pinpoint.test.javasssit.JavassistClassTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
@Deprecated
|
||||
public class AccessorInjectionTest {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(JavassistClassTest.class.getName());
|
||||
|
||||
private TestClassLoader getTestClassLoader() {
|
||||
PLoggerFactory.initialize(new Slf4jLoggerBinder());
|
||||
|
||||
DefaultProfilerConfig profilerConfig = new DefaultProfilerConfig();
|
||||
profilerConfig.setApplicationServerType(ServiceType.TEST_STAND_ALONE.getName());
|
||||
DefaultAgent agent = MockAgent.of(profilerConfig);
|
||||
|
||||
TestClassLoader testClassLoader = new TestClassLoader(agent);
|
||||
testClassLoader.initialize();
|
||||
return testClassLoader;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addTraceValue() throws Exception {
|
||||
final TestClassLoader loader = getTestClassLoader();
|
||||
final String javassistClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject";
|
||||
|
||||
loader.addTransformer(javassistClassName, new TransformCallback() {
|
||||
|
||||
@Override
|
||||
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
|
||||
try {
|
||||
logger.info("modify cl:{}", loader);
|
||||
|
||||
InstrumentClass aClass = instrumentor.getInstrumentClass(loader, javassistClassName, classfileBuffer);
|
||||
|
||||
aClass.addField(ObjectTraceValue.class.getName());
|
||||
aClass.addField(IntTraceValue.class.getName());
|
||||
aClass.addField(IntArrayTraceValue.class.getName());
|
||||
aClass.addField(IntegerArrayTraceValue.class.getName());
|
||||
aClass.addField(DatabaseInfoTraceValue.class.getName());
|
||||
aClass.addField(BindValueTraceValue.class.getName());
|
||||
|
||||
String methodName = "callA";
|
||||
aClass.getDeclaredMethod(methodName).addInterceptor("com.navercorp.pinpoint.test.javasssit.TestBeforeInterceptor");
|
||||
return aClass.toBytecode();
|
||||
} catch (InstrumentException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Class<?> testObjectClazz = loader.loadClass(javassistClassName);
|
||||
final String methodName = "callA";
|
||||
logger.info("class:{}", testObjectClazz.toString());
|
||||
final Object testObject = testObjectClazz.newInstance();
|
||||
Method callA = testObjectClazz.getMethod(methodName);
|
||||
callA.invoke(testObject);
|
||||
|
||||
Class<?> objectTraceValue = loader.loadClass(ObjectTraceValue.class.getName());
|
||||
Assert.assertTrue("ObjectTraceValue implements fail", objectTraceValue.isInstance(testObject));
|
||||
objectTraceValue.getMethod("_$PINPOINT$_setTraceObject", Object.class).invoke(testObject, "a");
|
||||
Object get = objectTraceValue.getMethod("_$PINPOINT$_getTraceObject").invoke(testObject);
|
||||
Assert.assertEquals("a", get);
|
||||
|
||||
Class<?> intTraceValue = loader.loadClass(IntTraceValue.class.getName());
|
||||
Assert.assertTrue("IntTraceValue implements fail", intTraceValue.isInstance(testObject));
|
||||
intTraceValue.getMethod("_$PINPOINT$_setTraceInt", int.class).invoke(testObject, 1);
|
||||
int a = (Integer) intTraceValue.getMethod("_$PINPOINT$_getTraceInt").invoke(testObject);
|
||||
Assert.assertEquals(1, a);
|
||||
|
||||
Class<?> intArrayTraceValue = loader.loadClass(IntArrayTraceValue.class.getName());
|
||||
Assert.assertTrue("IntArrayTraceValue implements fail", intArrayTraceValue.isInstance(testObject));
|
||||
int[] expectedInts = {1, 2, 3};
|
||||
intArrayTraceValue.getMethod("_$PINPOINT$_setTraceIntArray", int[].class).invoke(testObject, expectedInts);
|
||||
int[] ints = (int[]) intArrayTraceValue.getMethod("_$PINPOINT$_getTraceIntArray").invoke(testObject);
|
||||
Assert.assertEquals(expectedInts, ints);
|
||||
|
||||
Class<?> integerArrayTraceValue = loader.loadClass(IntegerArrayTraceValue.class.getName());
|
||||
Assert.assertTrue("IntegerArrayTraceValue implements fail", integerArrayTraceValue.isInstance(testObject));
|
||||
Integer[] expectedIntegers = {1, 2};
|
||||
// wrap due to vararg expansion
|
||||
Object[] wrappedExpectedIntegers = new Object[]{expectedIntegers};
|
||||
integerArrayTraceValue.getMethod("_$PINPOINT$_setTraceIntegerArray", Integer[].class).invoke(testObject, wrappedExpectedIntegers);
|
||||
Integer[] integers = (Integer[]) integerArrayTraceValue.getMethod("_$PINPOINT$_getTraceIntegerArray").invoke(testObject);
|
||||
Assert.assertArrayEquals(expectedIntegers, integers);
|
||||
|
||||
Class<?> databaseTraceValue = loader.loadClass(DatabaseInfoTraceValue.class.getName());
|
||||
Assert.assertTrue("DatabaseInfoTraceValue implements fail", databaseTraceValue.isInstance(testObject));
|
||||
databaseTraceValue.getMethod("_$PINPOINT$_setTraceDatabaseInfo", DatabaseInfo.class).invoke(testObject, UnKnownDatabaseInfo.INSTANCE);
|
||||
Object databaseInfo = databaseTraceValue.getMethod("_$PINPOINT$_getTraceDatabaseInfo").invoke(testObject);
|
||||
Assert.assertSame(UnKnownDatabaseInfo.INSTANCE, databaseInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddGetter() throws Exception {
|
||||
final TestClassLoader loader = getTestClassLoader();
|
||||
final String targetClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject3";
|
||||
|
||||
|
||||
loader.addTransformer(targetClassName, new TransformCallback() {
|
||||
|
||||
@Override
|
||||
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
|
||||
try {
|
||||
logger.info("modify cl:{}", classLoader);
|
||||
InstrumentClass aClass = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
|
||||
|
||||
aClass.addGetter(StringGetter.class.getName(), "value");
|
||||
aClass.addGetter(IntGetter.class.getName(), "intValue");
|
||||
aClass.addGetter(IntArrayGetter.class.getName(), "intValues");
|
||||
aClass.addGetter(IntegerArrayGetter.class.getName(), "integerValues");
|
||||
|
||||
return aClass.toBytecode();
|
||||
} catch (InstrumentException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Object testObject = loader.loadClass(targetClassName).newInstance();
|
||||
|
||||
Class<?> stringGetter = loader.loadClass(StringGetter.class.getName());
|
||||
Class<?> intGetter = loader.loadClass(IntGetter.class.getName());
|
||||
Class<?> intsGetter = loader.loadClass(IntArrayGetter.class.getName());
|
||||
Class<?> integersGetter = loader.loadClass(IntegerArrayGetter.class.getName());
|
||||
|
||||
Assert.assertTrue(stringGetter.isInstance(testObject));
|
||||
Assert.assertTrue(intGetter.isInstance(testObject));
|
||||
Assert.assertTrue(intsGetter.isInstance(testObject));
|
||||
Assert.assertTrue(integersGetter.isInstance(testObject));
|
||||
|
||||
String value = "hehe";
|
||||
int intValue = 99;
|
||||
int[] intValues = {99, 100};
|
||||
Integer[] integerValues = {99, 100};
|
||||
|
||||
Method method = testObject.getClass().getMethod("setValue", String.class);
|
||||
method.invoke(testObject, value);
|
||||
|
||||
Method getString = stringGetter.getMethod("_$PINPOINT$_getString");
|
||||
Assert.assertEquals(value, getString.invoke(testObject));
|
||||
|
||||
Method setIntValue = testObject.getClass().getMethod("setIntValue", int.class);
|
||||
setIntValue.invoke(testObject, intValue);
|
||||
|
||||
Method getInt = intGetter.getMethod("_$PINPOINT$_getInt");
|
||||
Assert.assertEquals(intValue, getInt.invoke(testObject));
|
||||
|
||||
Method setIntValues = testObject.getClass().getMethod("setIntValues", int[].class);
|
||||
setIntValues.invoke(testObject, intValues);
|
||||
|
||||
Method getIntValues = intsGetter.getMethod("_$PINPOINT$_getIntArray");
|
||||
Assert.assertEquals(intValues, getIntValues.invoke(testObject));
|
||||
|
||||
Method setIntegerValues = testObject.getClass().getMethod("setIntegerValues", Integer[].class);
|
||||
// wrap due to vararg expansion
|
||||
Object[] wrappedIntegerValues = new Object[]{integerValues};
|
||||
setIntegerValues.invoke(testObject, wrappedIntegerValues);
|
||||
|
||||
Method getIntegerValues = integersGetter.getMethod("_$PINPOINT$_getIntegerArray");
|
||||
Assert.assertEquals(integerValues, getIntegerValues.invoke(testObject));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSetter() throws Exception {
|
||||
final TestClassLoader loader = getTestClassLoader();
|
||||
final String targetClassName = "com.navercorp.pinpoint.test.javasssit.mock.TestObject4";
|
||||
|
||||
loader.addTransformer(targetClassName, new TransformCallback() {
|
||||
@Override
|
||||
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
|
||||
try {
|
||||
logger.info("modify cl:{}", classLoader);
|
||||
InstrumentClass testClass = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
|
||||
|
||||
testClass.addSetter(IntSetter.class.getName(), "intValue");
|
||||
testClass.addSetter(IntArraySetter.class.getName(), "intValues");
|
||||
testClass.addSetter(IntegerArraySetter.class.getName(), "integerValues");
|
||||
|
||||
return testClass.toBytecode();
|
||||
} catch (InstrumentException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Object testObject = loader.loadClass(targetClassName).newInstance();
|
||||
|
||||
Class<?> intSetter = loader.loadClass(IntSetter.class.getName());
|
||||
Class<?> intsSetter = loader.loadClass(IntArraySetter.class.getName());
|
||||
Class<?> integersSetter = loader.loadClass(IntegerArraySetter.class.getName());
|
||||
|
||||
Assert.assertTrue(intSetter.isInstance(testObject));
|
||||
Assert.assertTrue(intsSetter.isInstance(testObject));
|
||||
Assert.assertTrue(integersSetter.isInstance(testObject));
|
||||
|
||||
int intValue = 99;
|
||||
int[] intValues = {99, 100};
|
||||
Integer[] integerValues = {99, 100};
|
||||
|
||||
Method setInt = intSetter.getMethod("_$PINPOINT$_setInt", int.class);
|
||||
setInt.invoke(testObject, intValue);
|
||||
Method getInt = testObject.getClass().getMethod("getIntValue");
|
||||
Assert.assertEquals(intValue, getInt.invoke(testObject));
|
||||
|
||||
Method setInts = intsSetter.getMethod("_$PINPOINT$_setIntArray", int[].class);
|
||||
setInts.invoke(testObject, intValues);
|
||||
Method getInts = testObject.getClass().getMethod("getIntValues");
|
||||
Assert.assertEquals(intValues, getInts.invoke(testObject));
|
||||
|
||||
Method setIntegers = integersSetter.getMethod("_$PINPOINT$_setIntegerArray", Integer[].class);
|
||||
// wrap due to vararg expansion
|
||||
Object[] wrappedIntegerValues = new Object[]{integerValues};
|
||||
setIntegers.invoke(testObject, wrappedIntegerValues);
|
||||
Method getIntegers = testObject.getClass().getMethod("getIntegerValues");
|
||||
Assert.assertEquals(integerValues, getIntegers.invoke(testObject));
|
||||
}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface BindValueTraceValue {
|
||||
void _$PINPOINT$_setTraceBindValue(Map<Integer, String> value);
|
||||
Map<Integer, String> _$PINPOINT$_getTraceBindValue();
|
||||
}
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.DatabaseInfo;
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 Naver Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 Naver Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 Naver Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
+7
-5
@@ -1,18 +1,20 @@
|
||||
/**
|
||||
* Copyright 2014 NAVER Corp.
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
/**
|
||||
* @author Jongho Moon
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 Naver Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
|
||||
/**
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 Naver Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 Naver Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 Naver Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
|
||||
/**
|
||||
+7
-5
@@ -1,18 +1,20 @@
|
||||
/**
|
||||
* Copyright 2014 NAVER Corp.
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.accessor;
|
||||
|
||||
/**
|
||||
* @author Jongho Moon
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.mock;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.mock;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.mock;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
+4
-4
@@ -1,18 +1,18 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.mock;
|
||||
|
||||
/**
|
||||
* @author Jongho Moon
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.mock;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
+4
-4
@@ -1,18 +1,18 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
package com.navercorp.pinpoint.test.javasssit.mock;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
+6
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,13 +12,13 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.monitor;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
package com.navercorp.pinpoint.test.monitor;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.AgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.profiler.sender.DataSender;
|
||||
import com.navercorp.pinpoint.test.ListenableDataSender;
|
||||
@@ -26,13 +26,14 @@ import com.navercorp.pinpoint.test.MockTraceContextFactory;
|
||||
import com.navercorp.pinpoint.test.TBaseRecorder;
|
||||
import com.navercorp.pinpoint.test.TBaseRecorderAdaptor;
|
||||
import com.navercorp.pinpoint.thrift.dto.TAgentStatBatch;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author hyungil.jeong
|
||||
*/
|
||||
+8
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,14 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.plugin;
|
||||
|
||||
import static com.navercorp.pinpoint.common.util.VarArgs.va;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
package com.navercorp.pinpoint.test.plugin;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
@@ -27,8 +23,13 @@ import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentMethod;
|
||||
import com.navercorp.pinpoint.profiler.DefaultAgent;
|
||||
import com.navercorp.pinpoint.profiler.instrument.JavassistClassPool;
|
||||
import com.navercorp.pinpoint.profiler.plugin.DefaultProfilerPluginContext;
|
||||
import com.navercorp.pinpoint.profiler.util.TypeUtils;
|
||||
import com.navercorp.pinpoint.test.TestProfilerPluginClassLoader;
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.navercorp.pinpoint.common.util.VarArgs.va;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class DefaultClassEditorBuilderTest {
|
||||
public static final String SCOPE_NAME = "test";
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,9 +12,10 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.plugin;
|
||||
package com.navercorp.pinpoint.test.plugin;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor;
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.annotation.Scope;
|
||||
+1
-18
@@ -26,17 +26,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-commons-server</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-commons-hbase</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.navercorp.pinpoint</groupId>
|
||||
<artifactId>pinpoint-thrift</artifactId>
|
||||
@@ -95,12 +84,6 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- [End] Compile Interceptors -->
|
||||
|
||||
@@ -180,7 +163,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>compile</scope>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
-1
@@ -35,7 +35,6 @@ import org.junit.Test;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaData;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder;
|
||||
import com.navercorp.pinpoint.test.TestableServerMetaDataListener;
|
||||
|
||||
/**
|
||||
* @author hyungil.jeong
|
||||
|
||||
-3
@@ -22,14 +22,11 @@ import com.navercorp.pinpoint.bootstrap.sampler.Sampler;
|
||||
import com.navercorp.pinpoint.common.util.TransactionId;
|
||||
import com.navercorp.pinpoint.common.util.TransactionIdUtils;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTraceContext;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTraceId;
|
||||
import com.navercorp.pinpoint.profiler.context.TransactionCounter.SamplingType;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.LogStorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.metadata.LRUCache;
|
||||
import com.navercorp.pinpoint.profiler.sampler.SamplingRateSampler;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
import com.navercorp.pinpoint.test.TestAgentInformation;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -16,12 +16,9 @@
|
||||
|
||||
package com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTrace;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTraceContext;
|
||||
import com.navercorp.pinpoint.profiler.context.storage.SpanStorage;
|
||||
import com.navercorp.pinpoint.profiler.logging.Slf4jLoggerBinderInitializer;
|
||||
import com.navercorp.pinpoint.profiler.sender.LoggingDataSender;
|
||||
import com.navercorp.pinpoint.test.TestAgentInformation;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
|
||||
import com.navercorp.pinpoint.profiler.sender.LoggingDataSender;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public class MockTraceContextFactory {
|
||||
|
||||
private EnhancedDataSender priorityDataSender = new LoggingDataSender();
|
||||
|
||||
public void setPriorityDataSender(EnhancedDataSender priorityDataSender) {
|
||||
if (priorityDataSender == null) {
|
||||
throw new NullPointerException("priorityDataSender must not be null");
|
||||
}
|
||||
this.priorityDataSender = priorityDataSender;
|
||||
}
|
||||
|
||||
public TraceContext create() {
|
||||
DefaultTraceContext traceContext = new DefaultTraceContext(new TestAgentInformation()) ;
|
||||
ProfilerConfig profilerConfig = new DefaultProfilerConfig();
|
||||
traceContext.setProfilerConfig(profilerConfig);
|
||||
|
||||
|
||||
traceContext.setPriorityDataSender(priorityDataSender);
|
||||
|
||||
return traceContext;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.navercorp.pinpoint.common.Version;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.JvmUtils;
|
||||
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
|
||||
import com.navercorp.pinpoint.profiler.AgentInformation;
|
||||
|
||||
/**
|
||||
* TODO duplicate com.navercorp.pinpoint.test.TestAgentInformation
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class TestAgentInformation extends AgentInformation {
|
||||
|
||||
private static final String AGENT_ID = "test-agent";
|
||||
private static final String APPLICATION_NAME = "TEST_APPLICATION";
|
||||
private static final int PID = 10;
|
||||
private static final String MACHINE_NAME = "test-machine";
|
||||
private static final String HOST_IP = "127.0.0.1";
|
||||
private static final ServiceType SERVICE_TYPE = ServiceType.TEST_STAND_ALONE;
|
||||
private static final String JVM_VERSION = JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION);
|
||||
private static final String AGENT_VERSION = Version.VERSION;
|
||||
|
||||
public TestAgentInformation() {
|
||||
super(AGENT_ID, APPLICATION_NAME, System.currentTimeMillis(), PID, MACHINE_NAME, HOST_IP, SERVICE_TYPE, JVM_VERSION, AGENT_VERSION);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Woonduk Kang(emeroad)
|
||||
*/
|
||||
public class TestClass {
|
||||
private int a;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TestClass{" +
|
||||
"a=" + a +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.context;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaData;
|
||||
import com.navercorp.pinpoint.bootstrap.context.ServerMetaDataHolder.ServerMetaDataListener;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
*/
|
||||
public class TestableServerMetaDataListener implements ServerMetaDataListener {
|
||||
|
||||
private volatile ServerMetaData serverMetaData;
|
||||
|
||||
@Override
|
||||
public void publishServerMetaData(ServerMetaData serverMetaData) {
|
||||
this.serverMetaData = serverMetaData;
|
||||
}
|
||||
|
||||
public ServerMetaData getServerMetaData() {
|
||||
return this.serverMetaData;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import com.navercorp.pinpoint.profiler.sender.LoggingDataSender;
|
||||
import com.navercorp.pinpoint.rpc.FutureListener;
|
||||
import com.navercorp.pinpoint.rpc.ResponseMessage;
|
||||
import com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener;
|
||||
import com.navercorp.pinpoint.test.TestAgentInformation;
|
||||
|
||||
import org.apache.thrift.TBase;
|
||||
import org.junit.Test;
|
||||
|
||||
+1
-1
@@ -26,6 +26,7 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.context.TestAgentInformation;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -44,7 +45,6 @@ import com.navercorp.pinpoint.profiler.context.storage.LogStorageFactory;
|
||||
import com.navercorp.pinpoint.profiler.metadata.LRUCache;
|
||||
import com.navercorp.pinpoint.profiler.sampler.SamplingRateSampler;
|
||||
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
|
||||
import com.navercorp.pinpoint.test.TestAgentInformation;
|
||||
|
||||
/**
|
||||
* @author HyunGil Jeong
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@
|
||||
package com.navercorp.pinpoint.profiler.instrument;
|
||||
|
||||
import com.navercorp.pinpoint.common.util.ClassLoaderUtils;
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.util.BytecodeUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ import com.navercorp.pinpoint.profiler.instrument.mock.BasicInterceptor;
|
||||
import com.navercorp.pinpoint.profiler.instrument.mock.ExceptionInterceptor;
|
||||
import com.navercorp.pinpoint.profiler.instrument.mock.StaticInterceptor;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.test.TestInterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
package com.navercorp.pinpoint.profiler.instrument;
|
||||
|
||||
import com.navercorp.pinpoint.common.util.ClassLoaderUtils;
|
||||
import com.navercorp.pinpoint.profiler.util.BytecodeUtils;
|
||||
import com.navercorp.pinpoint.profiler.util.JavaAssistUtils;
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -20,7 +21,7 @@ import static org.mockito.Mockito.times;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BytecodeDumpServiceTest {
|
||||
|
||||
private final String jvmClassName = JavaAssistUtils.javaNameToJvmName("java.lang.String");;
|
||||
private final String jvmClassName = JavaAssistUtils.javaNameToJvmName("java.lang.String");
|
||||
|
||||
@Mock
|
||||
private ASMBytecodeDisassembler disassembler;
|
||||
|
||||
+3
-2
@@ -18,8 +18,9 @@ package com.navercorp.pinpoint.profiler.instrument;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.test.TestInterceptorRegistryBinder;
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.util.BytecodeUtils;
|
||||
import com.navercorp.pinpoint.profiler.util.TestInterceptorRegistryBinder;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtMethod;
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ package com.navercorp.pinpoint.profiler.instrument.classreading;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.navercorp.pinpoint.common.util.ClassLoaderUtils;
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
import com.navercorp.pinpoint.profiler.util.BytecodeUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+5
-62
@@ -19,8 +19,8 @@ package com.navercorp.pinpoint.profiler.interceptor;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.util.LoaderUtils;
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
@@ -31,13 +31,14 @@ import javassist.NotFoundException;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor;
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.registry.DefaultInterceptorRegistryAdaptor;
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.registry.InterceptorRegistry;
|
||||
import com.navercorp.pinpoint.test.util.LoaderUtils;
|
||||
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
@@ -59,27 +60,9 @@ public class InterceptorTest {
|
||||
INTERCEPTOR_REGISTRY_ADAPTOR = null;
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void methodName() throws NoSuchMethodException {
|
||||
Method[] toString = Map.class.getDeclaredMethods();
|
||||
for (Method m : toString) {
|
||||
logger.info("methodObject:{}", m);
|
||||
logger.info("methodObject:{}", m.toGenericString());
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void ctClassName() throws NotFoundException {
|
||||
ClassPool pool = new ClassPool(true);
|
||||
|
||||
CtClass ctClass = pool.get("java.lang.String");
|
||||
logger.info("ctClass:{}", ctClass);
|
||||
logger.info("ctClass:{}", ctClass.getName());
|
||||
logger.info("ctClass:{}", ctClass.getSimpleName());
|
||||
}
|
||||
|
||||
// @Deprecated
|
||||
// @Test
|
||||
@Test
|
||||
public void interceptor() throws NotFoundException, CannotCompileException, IllegalAccessException, InstantiationException, IOException, ClassNotFoundException, NoSuchMethodException {
|
||||
AroundInterceptor aroundInterceptor = new AroundInterceptor() {
|
||||
|
||||
@@ -114,7 +97,7 @@ public class InterceptorTest {
|
||||
|
||||
// hello.insertBefore("{ System.out.println(\"BEFORE\"); }");
|
||||
hello.insertBefore("{" +
|
||||
"interceptor = (" + interceptorClassName + ") " + InterceptorRegistry.class.getName() + ".getSimpleInterceptor(" + interceptorId + ");" +
|
||||
"interceptor = (" + interceptorClassName + ") " + InterceptorRegistry.class.getName() + ".getInterceptor(" + interceptorId + ");" +
|
||||
"interceptor.before(this, $args);" +
|
||||
"}");
|
||||
// hello.addCatch("{" +
|
||||
@@ -179,46 +162,6 @@ public class InterceptorTest {
|
||||
// o.hello();
|
||||
}
|
||||
|
||||
private String generatedAroundInterceptor(String className, String methodName) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
sb.append(" ctx = new InterceptorContext();");
|
||||
sb.append(" ctx.setParameter($args);");
|
||||
sb.append(" ctx.setTarget(this);");
|
||||
sb.append(" ");
|
||||
// sb.append(" ctx.setMethodName(\"" + methodName + "\");");
|
||||
// sb.append(" System.out.println(\"args check : \" + $args );");
|
||||
// sb.append(" System.out.println(\"0 check : \" + $0 );");
|
||||
// sb.append(" System.out.println(\"1 check : \" + $1 );");
|
||||
// sb.append(" System.out.println(\"sig check : \" + $sig );");
|
||||
// sb.append(" System.out.println(\"class check : \" + $class );");
|
||||
// sb.append(" System.out.println(\" r check : \" + $r);");
|
||||
|
||||
sb.append("}");
|
||||
sb.append("{");
|
||||
sb.append(" interceptor = (AroundInterceptor) " + InterceptorRegistry.class.getName() + ".getStaticInterceptor(\"a\");");
|
||||
sb.append(" interceptor.before(ctx);");
|
||||
sb.append(" result = null;");
|
||||
// println(sb, "BEFORE systemout \"ttt\"");
|
||||
sb.append("}");
|
||||
sb.append("try {");
|
||||
sb.append(" $_ = $proceed($$);");
|
||||
sb.append(" result = $_;");
|
||||
sb.append("}");
|
||||
// sb.append("catch(Throwable th) {");
|
||||
// sb.append(" System.out.println(\"test11\" + th);");
|
||||
// sb.append(" ctx.setErrCode(th);");
|
||||
// sb.append(" System.out.println(\"catch\");");
|
||||
// sb.append("}");
|
||||
sb.append("finally {");
|
||||
// sb.append(" System.out.println(\"finally\");");
|
||||
sb.append(" ctx.setReturnValue(result);");
|
||||
sb.append(" interceptor.after(ctx);");
|
||||
sb.append("}");
|
||||
// System.out.println(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void println(StringBuilder sb, String out) {
|
||||
sb.append("System.out.println(\"" + out.replace("\"", "\\\"") + "\");");
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,8 +17,8 @@
|
||||
package com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.instrument.aspect.AspectWeaverClass;
|
||||
import com.navercorp.pinpoint.test.util.LoaderUtils;
|
||||
|
||||
import com.navercorp.pinpoint.profiler.util.LoaderUtils;
|
||||
import javassist.*;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
+7
-5
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.navercorp.pinpoint.profiler.interceptor.bci;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor;
|
||||
@@ -24,16 +25,17 @@ import com.navercorp.pinpoint.bootstrap.interceptor.Interceptor;
|
||||
*
|
||||
*/
|
||||
public class TestInterceptors {
|
||||
private static List<Interceptor> interceptors = new ArrayList<Interceptor>();
|
||||
|
||||
|
||||
private static final List<Interceptor> interceptors = Collections.synchronizedList(new ArrayList<Interceptor>());
|
||||
|
||||
public static void clear() {
|
||||
interceptors.clear();
|
||||
}
|
||||
|
||||
|
||||
public static void add(Interceptor interceptor) {
|
||||
interceptors.add(interceptor);
|
||||
}
|
||||
|
||||
|
||||
public static Interceptor get(int index) {
|
||||
return interceptors.get(index);
|
||||
}
|
||||
|
||||
+2
-1
@@ -19,8 +19,9 @@ package com.navercorp.pinpoint.profiler.monitor.codahale.gc;
|
||||
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
|
||||
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
|
||||
import com.navercorp.pinpoint.profiler.context.MockTraceContextFactory;
|
||||
import com.navercorp.pinpoint.profiler.monitor.codahale.AgentStatCollectorFactory;
|
||||
import com.navercorp.pinpoint.test.MockTraceContextFactory;
|
||||
|
||||
import com.navercorp.pinpoint.thrift.dto.TJvmGc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
+2
-2
@@ -22,8 +22,8 @@ package com.navercorp.pinpoint.profiler.receiver.service;
|
||||
import com.navercorp.pinpoint.profiler.context.ActiveTrace;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTrace;
|
||||
import com.navercorp.pinpoint.profiler.context.DefaultTraceContext;
|
||||
import com.navercorp.pinpoint.profiler.context.TestAgentInformation;
|
||||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceRepository;
|
||||
import com.navercorp.pinpoint.test.TestAgentInformation;
|
||||
import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCount;
|
||||
import com.navercorp.pinpoint.thrift.dto.command.TCmdActiveThreadCountRes;
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @Author Taejin Koo
|
||||
* @author Taejin Koo
|
||||
*/
|
||||
public class ActiveThreadServiceTest {
|
||||
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.util;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* // TODO duplicate BytecodeUtils : com.navercorp.pinpoint.test.util.BytecodeUtils
|
||||
*/
|
||||
public final class BytecodeUtils {
|
||||
|
||||
private static final Method DEFINE_CLASS = getDefineClassMethod();
|
||||
|
||||
private BytecodeUtils() {
|
||||
}
|
||||
|
||||
|
||||
private static Method getDefineClassMethod() {
|
||||
try {
|
||||
final Method method = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
} catch (NoSuchMethodException e) {
|
||||
// link error
|
||||
throw new RuntimeException("defineClass not found. Error:" + e.getMessage(), e);
|
||||
} catch (SecurityException e) {
|
||||
// link error
|
||||
throw new RuntimeException("defineClass error. Error:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> defineClass(ClassLoader classLoader, String className, byte[] classFile) {
|
||||
try {
|
||||
return (Class<?>) DEFINE_CLASS.invoke(classLoader, className, classFile, 0, classFile.length);
|
||||
} catch (Throwable ex) {
|
||||
throw new RuntimeException("defineClass error. Caused:" + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getClassFile(ClassLoader classLoader, String className) {
|
||||
if (classLoader == null) {
|
||||
classLoader = ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
if (className == null) {
|
||||
throw new NullPointerException("className must not be null");
|
||||
}
|
||||
|
||||
final String jvmClassName = JavaAssistUtils.javaNameToJvmName(className);
|
||||
final InputStream is = classLoader.getResourceAsStream(jvmClassName + ".class");
|
||||
if (is == null) {
|
||||
throw new RuntimeException("No such class file: " + className);
|
||||
}
|
||||
|
||||
try {
|
||||
return readClass(is, false);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
close(is);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* COPY ASM method. reference : org.objectweb.asm.ClassReader
|
||||
*
|
||||
* Reads the bytecode of a class.
|
||||
*
|
||||
* @param is
|
||||
* an input stream from which to read the class.
|
||||
* @param close
|
||||
* true to close the input stream after reading.
|
||||
* @return the bytecode read from the given input stream.
|
||||
* @throws IOException
|
||||
* if a problem occurs during reading.
|
||||
*/
|
||||
public static byte[] readClass(final InputStream is, boolean close)
|
||||
throws IOException {
|
||||
if (is == null) {
|
||||
throw new IOException("Class not found");
|
||||
}
|
||||
try {
|
||||
byte[] b = new byte[is.available()];
|
||||
int len = 0;
|
||||
while (true) {
|
||||
int n = is.read(b, len, b.length - len);
|
||||
if (n == -1) {
|
||||
if (len < b.length) {
|
||||
byte[] c = new byte[len];
|
||||
System.arraycopy(b, 0, c, 0, len);
|
||||
b = c;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
len += n;
|
||||
if (len == b.length) {
|
||||
int last = is.read();
|
||||
if (last < 0) {
|
||||
return b;
|
||||
}
|
||||
byte[] c = new byte[b.length + 1000];
|
||||
System.arraycopy(b, 0, c, 0, len);
|
||||
c[len++] = (byte) last;
|
||||
b = c;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (close) {
|
||||
close(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void close(Closeable closeable) {
|
||||
if (closeable != null) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException ignore) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -12,15 +12,16 @@
|
||||
* 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 com.navercorp.pinpoint.profiler.plugin;
|
||||
package com.navercorp.pinpoint.profiler.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.navercorp.pinpoint.test.util.BytecodeUtils;
|
||||
|
||||
|
||||
public class BytecodeUtilsTest {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.util;
|
||||
|
||||
import javassist.ClassPool;
|
||||
import javassist.Loader;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
/**
|
||||
* TODO Duplicate : com.navercorp.pinpoint.test.util.LoaderUtils
|
||||
* @author emeroad
|
||||
*/
|
||||
public final class LoaderUtils {
|
||||
|
||||
private static final SecurityManager SECURITY_MANAGER = System.getSecurityManager();
|
||||
|
||||
private LoaderUtils() {
|
||||
}
|
||||
|
||||
public static Loader createLoader(final ClassPool classPool) {
|
||||
if (classPool == null) {
|
||||
throw new NullPointerException("classPool must not be null");
|
||||
}
|
||||
Loader loader;
|
||||
if (SECURITY_MANAGER != null) {
|
||||
loader = AccessController.doPrivileged(new LoaderCreateAction(classPool));
|
||||
} else {
|
||||
loader = new Loader(classPool);
|
||||
}
|
||||
loader.delegateLoadingOf("org.apache.log4j.");
|
||||
return loader;
|
||||
}
|
||||
|
||||
static class LoaderCreateAction implements PrivilegedAction<Loader> {
|
||||
private final ClassPool classPool;
|
||||
|
||||
public LoaderCreateAction(final ClassPool classPool) {
|
||||
if (classPool == null) {
|
||||
throw new NullPointerException("classPool must not be null");
|
||||
}
|
||||
this.classPool = classPool;
|
||||
}
|
||||
|
||||
public Loader run() {
|
||||
return new Loader(classPool);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2016 NAVER Corp.
|
||||
*
|
||||
* Licensed 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 com.navercorp.pinpoint.profiler.util;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.registry.DefaultInterceptorRegistryAdaptor;
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.registry.InterceptorRegistry;
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.registry.InterceptorRegistryAdaptor;
|
||||
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
|
||||
|
||||
/**
|
||||
* // TODO duplicate class : com.navercorp.pinpoint.test.TestInterceptorRegistryBinder
|
||||
* @author emeroad
|
||||
*/
|
||||
public class TestInterceptorRegistryBinder implements InterceptorRegistryBinder {
|
||||
private static final InterceptorRegistryAdaptor interceptorRegistryAdaptor = new DefaultInterceptorRegistryAdaptor();
|
||||
private static final Object lock = new Object();
|
||||
|
||||
@Override
|
||||
public void bind() {
|
||||
try {
|
||||
InterceptorRegistry.bind(interceptorRegistryAdaptor, lock);
|
||||
} catch (IllegalStateException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind() {
|
||||
try {
|
||||
InterceptorRegistry.unbind(lock);
|
||||
} catch (IllegalStateException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public InterceptorRegistryAdaptor getInterceptorRegistryAdaptor() {
|
||||
return interceptorRegistryAdaptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInterceptorRegistryClassName() {
|
||||
return InterceptorRegistry.class.getName();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user