use of com.navercorp.pinpoint.test.plugin.ForkedPinpointPluginTestRunner in project pinpoint by naver.
the class SharedPinpointPluginTest method execute.
private void execute(final TestInfo testInfo, final Properties properties) {
try {
final ClassLoader testClassLoader = createTestClassLoader(testInfo);
Runnable runnable = new Runnable() {
@Override
public void run() {
final Class<?> testClazz = loadClass();
logger.debug("testClazz:{} cl:{}", testClazz.getName(), testClazz.getClassLoader());
try {
MethodUtils.invokeSetMethod(testClazz, properties);
} catch (Exception e) {
logger.warn(e, "invoker setter method failed. testClazz:{} testId:{}", testClazzName, testInfo.getTestId());
}
try {
JUnitCore junit = new JUnitCore();
junit.addListener(new PrintListener());
Runner runner = new ForkedPinpointPluginTestRunner(testClazz, testInfo.getTestId());
junit.run(runner);
} catch (InitializationError error) {
logger.error(error, "test run fail testClazz:{} testId:{}", testClazzName, testInfo.getTestId());
List<Throwable> causes = error.getCauses();
for (Throwable cause : causes) {
logger.error(cause, "junit error Caused By:{}", cause.getMessage());
}
}
}
private Class<?> loadClass() {
try {
return testClassLoader.loadClass(testClazzName);
} catch (ClassNotFoundException e) {
logger.error(e, "testClazz:{} not found", testClazzName, testInfo.getTestId());
throw new RuntimeException(e);
}
}
};
String threadName = testClazzName + " " + testInfo.getTestId() + " Thread";
Thread testThread = newThread(runnable, threadName, testClassLoader);
testThread.start();
testThread.join(TimeUnit.MINUTES.toMillis(5));
checkTerminatedState(testThread, testClazzName + " " + testInfo.getTestId());
} catch (Exception e) {
logger.error(e, "{}:{} execute failed:{}", testClazzName, testInfo.getTestId(), e.getMessage());
} finally {
ReflectPluginTestVerifier.getInstance().cleanUp(true);
}
}
Aggregations