Skip to content

Commit

Permalink
[#5118] Change method of create process in IT
Browse files Browse the repository at this point in the history
  • Loading branch information
koo-taejin authored and Xylus committed Jan 10, 2019
1 parent 9e10346 commit a96b133
Show file tree
Hide file tree
Showing 25 changed files with 1,398 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public void hystrixObservableCommand_toObservable_timeout() throws Exception {
fallbackCauseAnnotation, exceptionAnnotation));
verifier.verifyTrace(event("HYSTRIX_COMMAND_INTERNAL", "com.netflix.hystrix.HystrixObservableCommand.getFallbackObservable()"));

verifier.awaitTraceCount(2, 10, 3000);

// execution
verifier.verifyTrace(event(ServiceType.ASYNC.getName(), "Asynchronous Invocation"));
Method helloMethod = HelloRepository.class.getDeclaredMethod("hello", String.class, long.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.Enumeration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -64,6 +66,8 @@ public static void setUpBeforeClass() throws Exception {
TEST_DATABASE.start();
TEST_DATABASE.createDB("test");
TEST_DATABASE.source("jdbc/mariadb/init.sql");

DriverManager.registerDriver(new org.mariadb.jdbc.Driver());
}

protected final void executeStatement() throws Exception {
Expand Down Expand Up @@ -197,5 +201,12 @@ private void closeStatement(Statement statement) throws SQLException {
@AfterClass
public static void tearDownAfterClass() throws Exception {
TEST_DATABASE.stop();

Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
DriverManager.deregisterDriver(driver);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.ActiveMQClientITHelper;
import com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.TestBroker;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.JvmVersion;
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointConfig;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
Expand All @@ -35,6 +36,7 @@
@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent(AgentPath.PATH)
@PinpointConfig("activemq/client/pinpoint-activemq-client.config")
@JvmVersion(8)
// 5.4.1 bug creates activemq-data directory even if persistence is set to false - skip it
// 5.5.x activemq-all missing slf4j binder - just skip instead of supplying one
@Dependency({"org.apache.activemq:activemq-all:[5.15.0,)"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.navercorp.pinpoint.plugin.AgentPath;
import com.navercorp.pinpoint.test.plugin.Dependency;
import com.navercorp.pinpoint.test.plugin.JvmVersion;
import com.navercorp.pinpoint.test.plugin.PinpointAgent;
import com.navercorp.pinpoint.test.plugin.PinpointPluginTestSuite;
import org.junit.runner.RunWith;
Expand All @@ -27,6 +28,7 @@
*/
@RunWith(PinpointPluginTestSuite.class)
@PinpointAgent(AgentPath.PATH)
@JvmVersion(8)
@Dependency({
"com.datastax.cassandra:cassandra-driver-core:[3.0.0,)",
"org.scassandra:java-client:1.1.2"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public void call(Throwable throwable) {
// Instead, we can verify them indirectly by checking if user methods have been traced.
verifier.ignoreServiceType("RX_JAVA_INTERNAL");

verifier.awaitTrace(event(ServiceType.ASYNC.getName(), "Asynchronous Invocation"), 20, 500);

Method subscribeMethod = Completable.class.getDeclaredMethod("subscribe");
verifier.verifyTrace(event("RX_JAVA", subscribeMethod));
// event - RX_JAVA_INTERNAL some form of Worker.schedule(Action0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2018 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.MethodDescriptor;
import com.navercorp.pinpoint.profiler.metadata.ApiMetaData;
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
import com.navercorp.pinpoint.profiler.metadata.Result;
import com.navercorp.pinpoint.profiler.metadata.SimpleCache;
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;

/**
* @author Taejin Koo
*/
public class MockApiMetaDataService implements ApiMetaDataService {

private final SimpleCache<String> apiCache = new SimpleCache<String>();

private final EnhancedDataSender<Object> enhancedDataSender;

public MockApiMetaDataService(EnhancedDataSender<Object> enhancedDataSender) {
if (enhancedDataSender == null) {
throw new NullPointerException("enhancedDataSender must not be null");
}
this.enhancedDataSender = enhancedDataSender;
}

@Override
public int cacheApi(final MethodDescriptor methodDescriptor) {
final String fullName = methodDescriptor.getFullName();
final Result result = this.apiCache.put(fullName);

methodDescriptor.setApiId(result.getId());

final ApiMetaData apiMetadata = new ApiMetaData(result.getId(), methodDescriptor.getApiDescriptor());
apiMetadata.setLine(methodDescriptor.getLineNumber());
apiMetadata.setType(methodDescriptor.getType());

this.enhancedDataSender.request(apiMetadata);

return result.getId();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2018 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.google.inject.Inject;
import com.google.inject.Provider;
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;

/**
* @author Taejin Koo
*/
public class MockApiMetaDataServiceProvider implements Provider<ApiMetaDataService> {

private final Provider<EnhancedDataSender<Object>> enhancedDataSenderProvider;

@Inject
public MockApiMetaDataServiceProvider(Provider<EnhancedDataSender<Object>> enhancedDataSenderProvider) {
if (enhancedDataSenderProvider == null) {
throw new NullPointerException("enhancedDataSenderProvider must not be null");
}
this.enhancedDataSenderProvider = enhancedDataSenderProvider;
}

@Override
public ApiMetaDataService get() {
final EnhancedDataSender<Object> enhancedDataSender = this.enhancedDataSenderProvider.get();
return new MockApiMetaDataService(enhancedDataSender);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.navercorp.pinpoint.test;

import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.util.Providers;
import com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataRegistryService;
Expand All @@ -25,6 +26,7 @@
import com.navercorp.pinpoint.profiler.context.module.SpanDataSender;
import com.navercorp.pinpoint.profiler.context.module.StatDataSender;
import com.navercorp.pinpoint.profiler.context.storage.StorageFactory;
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
import com.navercorp.pinpoint.profiler.sender.DataSender;
import com.navercorp.pinpoint.profiler.sender.EnhancedDataSender;
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
Expand Down Expand Up @@ -68,6 +70,7 @@ protected void configure() {

ServerMetaDataRegistryService serverMetaDataRegistryService = newServerMetaDataRegistryService();
bind(ServerMetaDataRegistryService.class).toInstance(serverMetaDataRegistryService);
bind(ApiMetaDataService.class).toProvider(MockApiMetaDataServiceProvider.class).in(Scopes.SINGLETON);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private <K, V> BiMap<K, V> newSynchronizedBiMap() {
return Maps.synchronizedBiMap(hashBiMap);
}


@Override
public boolean send(Object data) {
addData(data);
Expand All @@ -75,22 +74,21 @@ private void addData(Object data) {
ApiMetaData md = (ApiMetaData)data;

final String javaMethodDescriptor = toJavaMethodDescriptor(md);
apiIdMap.put(md.getApiId(), javaMethodDescriptor);

apiIdMap.forcePut(md.getApiId(), javaMethodDescriptor);
} else if (data instanceof SqlMetaData) {
SqlMetaData md = (SqlMetaData)data;

int id = md.getSqlId();
String sql = md.getSql();

sqlIdMap.put(id, sql);
sqlIdMap.forcePut(id, sql);
} else if (data instanceof StringMetaData) {
StringMetaData md = (StringMetaData)data;

int id = md.getStringId();
String string = md.getStringValue();

stringIdMap.put(id, string);
stringIdMap.forcePut(id, string);
}

datas.add(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@

package com.navercorp.pinpoint.test.plugin;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.navercorp.pinpoint.common.Version;
import com.navercorp.pinpoint.common.util.SystemProperty;
import com.navercorp.pinpoint.exception.PinpointException;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.DependencyResolutionException;
import org.junit.internal.runners.statements.RunAfters;
Expand All @@ -34,21 +29,38 @@
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;

import com.navercorp.pinpoint.common.Version;
import com.navercorp.pinpoint.common.util.SystemProperty;
import com.navercorp.pinpoint.exception.PinpointException;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public abstract class AbstractPinpointPluginTestSuite extends Suite {
private static final int NO_JVM_VERSION = -1;

private static final String[] REQUIRED_CLASS_PATHS = new String[] {
"junit", // JUnit
"hamcrest-core", // for JUnit
"pinpoint-test", // pinpoint-test-{VERSION}.jar
"/test/target/classes" // pinpoint-test build output directory

private static final String[] REQUIRED_CLASS_PATHS = new String[]{
"junit", // JUnit
"hamcrest-core", // for JUnit
"pinpoint-test", // pinpoint-test-{VERSION}.jar
"/test/target/classes" // pinpoint-test build output directory
};

private static final String[] MAVEN_DEPENDENCY_CLASS_PATHS = new String[]{
"aether",
"apache/maven",
"guava",
"plexus",
"pinpoint-test",
"/test/target/classes" // pinpoint-test build output directory
};

private final List<String> requiredLibraries;
private final List<String> mavenDependencyLibraries;
private final String testClassLocation;

private final String agentJar;
Expand All @@ -72,7 +84,8 @@ public AbstractPinpointPluginTestSuite(Class<?> testClass) throws Initialization
JvmVersion jvmVersion = testClass.getAnnotation(JvmVersion.class);
this.jvmVersions = jvmVersion == null ? new int[] { NO_JVM_VERSION } : jvmVersion.value();

this.requiredLibraries = resolveRequiredLibraries();
this.requiredLibraries = getClassPathList(REQUIRED_CLASS_PATHS);
this.mavenDependencyLibraries = getClassPathList(MAVEN_DEPENDENCY_CLASS_PATHS);
this.testClassLocation = resolveTestClassLocation(testClass);
this.debug = isDebugMode();
}
Expand Down Expand Up @@ -113,15 +126,15 @@ private String resolveTestClassLocation(Class<?> testClass) {
return toPathString(testClassLocation);
}

private List<String> resolveRequiredLibraries() {
private List<String> getClassPathList(String[] classPathCandidates) {
List<String> result = new ArrayList<String>();

ClassLoader cl = getClass().getClassLoader();

while (true) {
if (cl instanceof URLClassLoader) {
URLClassLoader ucl = ((URLClassLoader) cl);
List<String> requiredLibraries = findRequiredLibraries(ucl.getURLs());
Collection<String> requiredLibraries = findLibraries(ucl.getURLs(), classPathCandidates);
result.addAll(requiredLibraries);
}

Expand All @@ -135,12 +148,11 @@ private List<String> resolveRequiredLibraries() {
return result;
}


private List<String> findRequiredLibraries(URL[] urls) {
final List<String> result = new ArrayList<String>();
private Collection<String> findLibraries(URL[] urls, String[] paths) {
final Set<String> result = new HashSet<String>();
outer:
for (URL url : urls) {
for (String required : REQUIRED_CLASS_PATHS) {
for (String required : paths) {
if (url.getFile().contains(required)) {
result.add(toPathString(url));

Expand Down Expand Up @@ -210,7 +222,7 @@ protected Statement withAfterClasses(Statement statement) {
@Override
protected List<Runner> getChildren() {
List<Runner> runners = new ArrayList<Runner>();

try {
for (int ver : jvmVersions) {
String javaExe = getJavaExecutable(ver);
Expand All @@ -221,8 +233,8 @@ protected List<Runner> getChildren() {
System.out.println("Cannot find Java version " + ver + ". Skip test with Java " + ver);
continue;
}
PinpointPluginTestContext context = new PinpointPluginTestContext(agentJar, configFile, requiredLibraries, getTestClass().getJavaClass(), testClassLocation, jvmArguments, debug, ver, javaExe);

PinpointPluginTestContext context = new PinpointPluginTestContext(agentJar, configFile, requiredLibraries, mavenDependencyLibraries, getTestClass().getJavaClass(), testClassLocation, jvmArguments, debug, ver, javaExe);

List<PinpointPluginTestInstance> cases = createTestCases(context);

Expand All @@ -238,7 +250,7 @@ protected List<Runner> getChildren() {
if (runners.isEmpty()) {
throw new RuntimeException("No test");
}

return runners;
}

Expand Down
Loading

0 comments on commit a96b133

Please sign in to comment.