Search in sources :

Example 1 with ForkedPinpointPluginTestRunner

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);
    }
}
Also used : ForkedPinpointPluginTestRunner(com.navercorp.pinpoint.test.plugin.ForkedPinpointPluginTestRunner) Runner(org.junit.runner.Runner) JUnitCore(org.junit.runner.JUnitCore) InitializationError(org.junit.runners.model.InitializationError) ForkedPinpointPluginTestRunner(com.navercorp.pinpoint.test.plugin.ForkedPinpointPluginTestRunner) ChildFirstClassLoader(com.navercorp.pinpoint.test.plugin.util.ChildFirstClassLoader) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ForkedPinpointPluginTestRunner (com.navercorp.pinpoint.test.plugin.ForkedPinpointPluginTestRunner)1 ChildFirstClassLoader (com.navercorp.pinpoint.test.plugin.util.ChildFirstClassLoader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JUnitCore (org.junit.runner.JUnitCore)1 Runner (org.junit.runner.Runner)1 InitializationError (org.junit.runners.model.InitializationError)1