Search in sources :

Example 21 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class GlobalEventHandlerTest method testEvent.

@Test
public void testEvent() {
    Biz biz = new BizModel().setBizName("test-biz").setBizVersion("1.0.0").setBizState(BizState.RESOLVED);
    Plugin plugin = new PluginModel().setPluginName("test-plugin").setVersion("1.0.0");
    eventAdminService.sendEvent(new AfterBizStartupEvent(biz));
    Assert.assertTrue(result.size() == 3);
    Assert.assertTrue(result.contains("AbstractArkEvent->AfterBizStartupEvent"));
    eventAdminService.sendEvent(new BeforePluginStartupEvent(plugin));
    Assert.assertTrue(result.size() == 5);
    // test for ArkEvent.class.isAssignableFrom(event.getClass()
    eventAdminService.sendEvent(new ArkEvent() {

        @Override
        public String getTopic() {
            return "ark-event";
        }
    });
    Assert.assertTrue(result.size() == 7);
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BeforePluginStartupEvent(com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent) Biz(com.alipay.sofa.ark.spi.model.Biz) AfterBizStartupEvent(com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent) BizModel(com.alipay.sofa.ark.container.model.BizModel) ArkEvent(com.alipay.sofa.ark.spi.event.ArkEvent) AbstractArkEvent(com.alipay.sofa.ark.spi.event.AbstractArkEvent) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 22 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class PluginClassLoaderTest method testExportAndImport.

@Test
public void testExportAndImport() throws Exception {
    PluginModel pluginA = new PluginModel();
    pluginA.setPluginName("plugin A").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages(ClassUtils.getPackageName(ITest.class.getName())).setExportClasses("").setExportResources(StringUtils.EMPTY_STRING).setImportResources(StringUtils.EMPTY_STRING).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
    PluginModel pluginB = new PluginModel();
    pluginB.setPluginName("plugin B").setPriority("1").setClassPath(new URL[] { classPathURL }).setImportClasses(ITest.class.getName()).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages("").setExportClasses("").setExportResources(StringUtils.EMPTY_STRING).setImportResources(StringUtils.EMPTY_STRING).setPluginClassLoader(new PluginClassLoader(pluginB.getPluginName(), pluginB.getClassPath()));
    pluginManagerService.registerPlugin(pluginA);
    pluginManagerService.registerPlugin(pluginB);
    classloaderService.prepareExportClassAndResourceCache();
    pluginDeployService.deploy();
    Assert.assertEquals(pluginA.getPluginClassLoader().loadClass(ITest.class.getName()), pluginB.getPluginClassLoader().loadClass(ITest.class.getName()));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) ITest(com.alipay.sofa.ark.container.testdata.ITest) URL(java.net.URL) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest)

Example 23 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class PluginClassLoaderTest method testExportResourceStems.

@Test
public void testExportResourceStems() {
    PluginModel pluginA = new PluginModel();
    pluginA.setPluginName("pluginA").setPriority("100").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages(StringUtils.EMPTY_STRING).setExportClasses(StringUtils.EMPTY_STRING).setImportResources(StringUtils.EMPTY_STRING).setExportResources("export/folderA/*,export/folderB/*").setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
    PluginModel pluginB = new PluginModel();
    pluginB.setPluginName("pluginB").setPriority("1").setClassPath(new URL[0]).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages(StringUtils.EMPTY_STRING).setExportClasses(StringUtils.EMPTY_STRING).setImportResources("export/folderA/*,export/folderB/test3.xml").setExportResources(StringUtils.EMPTY_STRING).setPluginClassLoader(new PluginClassLoader(pluginB.getPluginName(), pluginB.getClassPath()));
    pluginManagerService.registerPlugin(pluginA);
    pluginManagerService.registerPlugin(pluginB);
    classloaderService.prepareExportClassAndResourceCache();
    pluginDeployService.deploy();
    String testResource1 = "export/folderA/test1.xml";
    String testResource2 = "export/folderA/test2.xml";
    String testResource3 = "export/folderB/test3.xml";
    String testResource4 = "export/folderB/test4.xml";
    Assert.assertEquals(pluginA.getPluginClassLoader().getResource(testResource1), pluginB.getPluginClassLoader().getResource(testResource1));
    Assert.assertEquals(pluginA.getPluginClassLoader().getResource(testResource2), pluginB.getPluginClassLoader().getResource(testResource2));
    Assert.assertEquals(pluginA.getPluginClassLoader().getResource(testResource3), pluginB.getPluginClassLoader().getResource(testResource3));
    // export/folderB/test4.xml not import
    Assert.assertNull(pluginB.getPluginClassLoader().getResource(testResource4));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) URL(java.net.URL) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest)

Example 24 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(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages(ITest.class.getCanonicalName()).setPluginClassLoader(new PluginClassLoader(mockPlugin.getPluginName(), mockPlugin.getClassPath()));
    pluginManagerService.registerPlugin(mockPlugin);
    PluginClassLoader pluginClassLoader = (PluginClassLoader) mockPlugin.getPluginClassLoader();
    Assert.assertNotNull(pluginClassLoader.loadClass("SampleClass", false));
    Class clazz = pluginClassLoader.loadClass(ArkClient.class.getCanonicalName());
    Assert.assertTrue(clazz.getClassLoader().equals(classloaderService.getArkClassLoader()));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) ArkClient(com.alipay.sofa.ark.api.ArkClient) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest)

Example 25 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class ExtensionServiceTest method testExtensionServiceLoader.

@Test
public void testExtensionServiceLoader() {
    PluginManagerService pluginManagerService = ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class);
    PluginModel pluginModel = new PluginModel().setPluginClassLoader(this.getClass().getClassLoader()).setPluginName("mock-plugin");
    pluginManagerService.registerPlugin(pluginModel);
    ServiceB impl1 = ArkServiceLoader.loadExtensionFromArkPlugin(ServiceB.class, "type1", "mock-plugin");
    Assert.assertTrue(impl1 instanceof ServiceBImpl3);
    ServiceB impl2 = ArkServiceLoader.loadExtensionFromArkPlugin(ServiceB.class, "type2", "mock-plugin");
    Assert.assertTrue(impl2 instanceof ServiceBImpl4);
    ServiceB impl3 = ArkServiceLoader.loadExtensionFromArkPlugin(ServiceB.class, "type1", "mock-plugin");
    Assert.assertTrue(impl3 instanceof ServiceBImpl3);
    ServiceB impl4 = ArkServiceLoader.loadExtensionFromArkPlugin(ServiceB.class, "type2", "mock-plugin");
    Assert.assertTrue(impl4 instanceof ServiceBImpl4);
    Assert.assertFalse(impl1 == impl3);
    Assert.assertFalse(impl2 == impl4);
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) ServiceBImpl3(com.alipay.sofa.ark.container.service.extension.spi.impl.ServiceBImpl3) PluginModel(com.alipay.sofa.ark.container.model.PluginModel) ServiceBImpl4(com.alipay.sofa.ark.container.service.extension.spi.impl.ServiceBImpl4) ServiceB(com.alipay.sofa.ark.container.service.extension.spi.ServiceB) ArkContainerTest(com.alipay.sofa.ark.container.ArkContainerTest) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

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