use of java.lang.instrument.Instrumentation in project pinpoint by naver.
the class JavassistClassTest method newJavassistEngine.
private InstrumentEngine newJavassistEngine() {
Instrumentation instrumentation = mock(Instrumentation.class);
ObjectBinderFactory objectBinderFactory = mock(ObjectBinderFactory.class);
Provider<ApiMetaDataService> apiMetaDataService = Providers.of(mock(ApiMetaDataService.class));
return new JavassistEngine(instrumentation, objectBinderFactory, new GlobalInterceptorRegistryBinder(), apiMetaDataService, null);
}
use of java.lang.instrument.Instrumentation in project pinpoint by naver.
the class JavassistEngineTest method newJavassistEngine.
private InstrumentEngine newJavassistEngine() {
Instrumentation instrumentation = mock(Instrumentation.class);
ObjectBinderFactory objectBinderFactory = mock(ObjectBinderFactory.class);
Provider<ApiMetaDataService> apiMetaDataService = Providers.of(mock(ApiMetaDataService.class));
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
return new JavassistEngine(instrumentation, objectBinderFactory, binder, apiMetaDataService, null);
}
use of java.lang.instrument.Instrumentation in project pinpoint by naver.
the class DependencyGraph method newApplicationContext.
private DefaultApplicationContext newApplicationContext() {
ProfilerConfig profilerConfig = new DefaultProfilerConfig();
InterceptorRegistryBinder binder = new TestInterceptorRegistryBinder();
Instrumentation instrumentation = mock(Instrumentation.class);
AgentOption agentOption = new DefaultAgentOption(instrumentation, "mockAgent", "mockApplicationName", profilerConfig, new URL[0], null, new DefaultServiceTypeRegistryService(), new DefaultAnnotationKeyRegistryService());
return new DefaultApplicationContext(agentOption, binder);
}
use of java.lang.instrument.Instrumentation in project jdk8u_jdk by JetBrains.
the class PrematureLoadTest method main.
public static void main(String[] args) throws IOException {
try {
new BootSupport();
throw new RuntimeException("Test configuration error - BootSupport loaded unexpectedly!");
} catch (NoClassDefFoundError x) {
}
try {
new AgentSupport();
throw new RuntimeException("Test configuration error - AgentSupport loaded unexpectedly!");
} catch (NoClassDefFoundError x) {
}
JarFile bootclasses = new JarFile("BootSupport.jar");
JarFile agentclasses = new JarFile("AgentSupport.jar");
Instrumentation ins = Agent.getInstrumentation();
ins.appendToBootstrapClassLoaderSearch(bootclasses);
try {
new BootSupport();
System.out.println("FAIL: BootSupport resolved");
failures++;
} catch (NoClassDefFoundError x) {
System.out.println("PASS: BootSupport failed to resolve");
}
try {
ins.appendToSystemClassLoaderSearch(agentclasses);
try {
new AgentSupport();
System.out.println("FAIL: AgentSupport resolved");
failures++;
} catch (NoClassDefFoundError x) {
System.out.println("PASS: AgentSupport failed to resolve");
}
} catch (UnsupportedOperationException x) {
System.out.println("System class loader does not support adding to class path");
}
if (failures > 0) {
throw new RuntimeException(failures + " test(s) failed.");
}
}
use of java.lang.instrument.Instrumentation in project tomee by apache.
the class UnenhancedTest method runTest.
private void runTest(final String methodName, final PersistenceUnitTransactionType transactionType, final boolean enhance) throws Exception {
this.enhance = enhance;
final ClassLoader loader = new FilteredChildFirstClassLoader(getClass().getClassLoader(), "org.apache.openejb.core.cmp.jpa");
final PersistenceClassLoaderHandler persistenceClassLoaderHandler = new PersistenceClassLoaderHandler() {
public void addTransformer(final String unitId, final ClassLoader classLoader, final ClassFileTransformer classFileTransformer) {
final Instrumentation instrumentation = Agent.getInstrumentation();
if (instrumentation != null) {
instrumentation.addTransformer(new ControllableTransformer(classFileTransformer));
}
}
public void destroy(final String unitId) {
}
public ClassLoader getNewTempClassLoader(final ClassLoader classLoader) {
return new TempClassLoader(classLoader);
}
};
final PersistenceUnitInfoImpl unitInfo = new PersistenceUnitInfoImpl(persistenceClassLoaderHandler);
unitInfo.setPersistenceUnitName("CMP");
unitInfo.setPersistenceProviderClassName(PERSISTENCE_PROVIDER);
unitInfo.setClassLoader(loader);
unitInfo.setExcludeUnlistedClasses(false);
unitInfo.setJtaDataSource(jtaDs);
unitInfo.setNonJtaDataSource(nonJtaDs);
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ComplexSuperclass");
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ComplexSubclass");
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ComplexStandalone");
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.GeneratedStandalone");
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.GeneratedSuperclass");
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.GeneratedSubclass");
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.OneStandalone");
unitInfo.addManagedClassName("org.apache.openejb.core.cmp.jpa.ManyStandalone");
// Handle Properties
final Properties properties = new Properties();
properties.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(SchemaAction='add,deleteTableContents',ForeignKeys=true)");
properties.setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
properties.setProperty("openjpa.Log", "DefaultLevel=INFO");
unitInfo.setProperties(properties);
unitInfo.setTransactionType(transactionType);
unitInfo.getManagedClassNames().add("org.apache.openejb.core.cmp.jpa.Employee");
final PersistenceProvider persistenceProvider = (PersistenceProvider) getClass().getClassLoader().loadClass(PERSISTENCE_PROVIDER).newInstance();
entityManagerFactory = persistenceProvider.createContainerEntityManagerFactory(unitInfo, new HashMap());
// create the test object (via reflection)
final Object testObject = loader.loadClass("org.apache.openejb.core.cmp.jpa.UnenhancedUnits").newInstance();
set(testObject, "TransactionManager", TransactionManager.class, transactionManager);
set(testObject, "EntityManagerFactory", EntityManagerFactory.class, entityManagerFactory);
// invoke the test (via reflection)
Thread.currentThread().setContextClassLoader(loader);
invoke(testObject, "setUp");
try {
invoke(testObject, methodName);
} finally {
invoke(testObject, "tearDown");
}
}
Aggregations