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);
}
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()));
}
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));
}
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()));
}
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);
}
Aggregations