Search in sources :

Example 1 with PluginModel

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"));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest)

Example 2 with PluginModel

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()));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest)

Example 3 with PluginModel

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()));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest)

Example 4 with PluginModel

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"));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest)

Example 5 with PluginModel

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));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest)

Aggregations

PluginModel (com.alipay.sofa.ark.container.model.PluginModel)47 Test (org.junit.Test)42 BaseTest (com.alipay.sofa.ark.container.BaseTest)34 ITest (com.alipay.sofa.ark.container.testdata.ITest)25 URL (java.net.URL)16 PluginContextImpl (com.alipay.sofa.ark.container.model.PluginContextImpl)9 HashSet (java.util.HashSet)9 BizModel (com.alipay.sofa.ark.container.model.BizModel)8 PluginClassLoader (com.alipay.sofa.ark.container.service.classloader.PluginClassLoader)7 Plugin (com.alipay.sofa.ark.spi.model.Plugin)7 TestObjectA (com.alipay.sofa.ark.container.testdata.impl.TestObjectA)5 PluginManagerService (com.alipay.sofa.ark.spi.service.plugin.PluginManagerService)5 ArkContainerTest (com.alipay.sofa.ark.container.ArkContainerTest)4 HandleArchiveStage (com.alipay.sofa.ark.container.pipeline.HandleArchiveStage)4 URLClassLoader (java.net.URLClassLoader)4 Attributes (java.util.jar.Attributes)4 DefaultServiceFilter (com.alipay.sofa.ark.container.registry.DefaultServiceFilter)3 PluginServiceProvider (com.alipay.sofa.ark.container.registry.PluginServiceProvider)3 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)3 ContainerServiceProvider (com.alipay.sofa.ark.container.registry.ContainerServiceProvider)2