Search in sources :

Example 1 with PinpointURLClassLoader

use of com.navercorp.pinpoint.bootstrap.PinpointURLClassLoader in project pinpoint by naver.

the class JarProfilerPluginClassInjectorTest method createContextTypeMatchClassLoader.

private ClassLoader createContextTypeMatchClassLoader(URL[] urlArray) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException {
    final ClassLoader classLoader = this.getClass().getClassLoader();
    final Class<ClassLoader> aClass = (Class<ClassLoader>) classLoader.loadClass(CONTEXT_TYPE_MATCH_CLASS_LOADER);
    final Constructor<ClassLoader> constructor = aClass.getConstructor(ClassLoader.class);
    ReflectionUtils.makeAccessible(constructor);
    final LibClass libClassFilter = new LibClass() {

        @Override
        public boolean onLoadClass(String clazzName) {
            if (clazzName.startsWith(LOG4_IMPL)) {
                logger.debug("Loading {}", clazzName);
                return ON_LOAD_CLASS;
            }
            return DELEGATE_PARENT;
        }
    };
    PinpointURLClassLoader testClassLoader = new PinpointURLClassLoader(urlArray, ClassLoader.getSystemClassLoader(), libClassFilter);
    final ClassLoader contextTypeMatchClassLoader = constructor.newInstance(testClassLoader);
    logger.debug("cl:{}", contextTypeMatchClassLoader);
    return contextTypeMatchClassLoader;
}
Also used : LibClass(com.navercorp.pinpoint.bootstrap.LibClass) PinpointURLClassLoader(com.navercorp.pinpoint.bootstrap.PinpointURLClassLoader) PinpointURLClassLoader(com.navercorp.pinpoint.bootstrap.PinpointURLClassLoader) LibClass(com.navercorp.pinpoint.bootstrap.LibClass)

Example 2 with PinpointURLClassLoader

use of com.navercorp.pinpoint.bootstrap.PinpointURLClassLoader in project pinpoint by naver.

the class PinpointURLClassLoaderTest method testOnLoadClass.

@Test
public void testOnLoadClass() throws Exception {
    PinpointURLClassLoader cl = new PinpointURLClassLoader(new URL[] {}, Thread.currentThread().getContextClassLoader());
    try {
        cl.loadClass("test");
        Assert.fail();
    } catch (ClassNotFoundException ignored) {
    }
    //        try {
    //            cl.loadClass("com.navercorp.pinpoint.profiler.DefaultAgent");
    //        } catch (ClassNotFoundException e) {
    //
    //        }
    // should be able to test using the above code, but it is not possible from bootstrap testcase.
    // it could be possible by specifying the full path to the URL classloader, but it would be harder to maintain.
    // for now, just test if DefaultAgent is specified to be loaded
    Assert.assertTrue(cl.onLoadClass("com.navercorp.pinpoint.profiler.DefaultAgent"));
}
Also used : PinpointURLClassLoader(com.navercorp.pinpoint.bootstrap.PinpointURLClassLoader) Test(org.junit.Test)

Aggregations

PinpointURLClassLoader (com.navercorp.pinpoint.bootstrap.PinpointURLClassLoader)2 LibClass (com.navercorp.pinpoint.bootstrap.LibClass)1 Test (org.junit.Test)1