use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class BizClassloaderTest method testGetPluginClassResource.
@Test
public void testGetPluginClassResource() throws Exception {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setClassPath(new URL[] { classPathURL }).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(new HashSet<>(Collections.singletonList(ITest.class.getName()))).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
pluginManagerService.registerPlugin(pluginA);
pluginDeployService.deploy();
classloaderService.prepareExportClassCache();
BizModel bizModel = new BizModel();
bizModel.setBizName("biz A").setClassPath(new URL[] { classPathURL }).setClassLoader(new BizClassLoader(bizModel.getBizName(), bizModel.getClassPath()));
bizManagerService.registerBiz(bizModel);
Assert.assertNotNull(bizModel.getBizClassLoader().getResource(ITest.class.getName().replace(".", "/") + ".class"));
}
use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class BizClassloaderTest method testImport.
@Test
public void testImport() throws Exception {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setClassPath(new URL[] { classPathURL }).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(new HashSet<>(Collections.singletonList(ITest.class.getName()))).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
pluginManagerService.registerPlugin(pluginA);
pluginDeployService.deploy();
classloaderService.prepareExportClassCache();
BizModel bizModel = new BizModel();
bizModel.setBizName("biz A").setClassPath(new URL[] { classPathURL }).setClassLoader(new BizClassLoader(bizModel.getBizName(), bizModel.getClassPath()));
bizManagerService.registerBiz(bizModel);
Assert.assertEquals(pluginA.getPluginClassLoader().loadClass(ITest.class.getName()), bizModel.getBizClassLoader().loadClass(ITest.class.getName()));
}
use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class PluginClassloaderTest method testExportAndNotImport.
@Test
public void testExportAndNotImport() throws Exception {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setClassPath(new URL[] { classPathURL }).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(new HashSet<>(Collections.singletonList(ITest.class.getName()))).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
PluginModel pluginB = new PluginModel();
pluginB.setPluginName("plugin B").setPriority(1).setClassPath(new URL[] { classPathURL }).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(Collections.<String>emptySet()).setPluginClassLoader(new PluginClassLoader(pluginB.getPluginName(), pluginB.getClassPath()));
pluginManagerService.registerPlugin(pluginA);
pluginManagerService.registerPlugin(pluginB);
classloaderService.prepareExportClassCache();
pluginDeployService.deploy();
Assert.assertNotEquals(pluginA.getPluginClassLoader().loadClass(ITest.class.getName()), pluginB.getPluginClassLoader().loadClass(ITest.class.getName()));
}
use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class PluginClassloaderTest method testExportResource.
@Test
public void testExportResource() {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("pluginA").setClassPath(new URL[] { classPathURL }).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(new HashSet<>(Collections.singletonList(ITest.class.getName()))).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
PluginModel pluginB = new PluginModel();
pluginB.setPluginName("pluginB").setPriority(1).setClassPath(new URL[0]).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(Collections.<String>emptySet()).setPluginClassLoader(new PluginClassLoader(pluginB.getPluginName(), pluginB.getClassPath()));
pluginManagerService.registerPlugin(pluginA);
pluginManagerService.registerPlugin(pluginB);
classloaderService.prepareExportClassCache();
pluginDeployService.deploy();
Assert.assertNotNull(pluginB.getPluginClassLoader().getResource("pluginA_sofa_ark_export_resource_test1.xml"));
Assert.assertNull(pluginB.getPluginClassLoader().getResource("test2.xml"));
}
use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class PluginClassloaderTest method testLoadClassFromAgentClassLoader.
@Test
public void testLoadClassFromAgentClassLoader() throws ClassNotFoundException {
PluginModel mockPlugin = new PluginModel();
mockPlugin.setPluginName("Mock Plugin").setClassPath(new URL[] {}).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(new HashSet<>(Collections.singletonList(ITest.class.getName()))).setPluginClassLoader(new PluginClassLoader(mockPlugin.getPluginName(), mockPlugin.getClassPath()));
pluginManagerService.registerPlugin(mockPlugin);
PluginClassLoader pluginClassLoader = (PluginClassLoader) mockPlugin.getPluginClassLoader();
Assert.assertNotNull(pluginClassLoader.loadClass("SampleClass", false));
}
Aggregations