use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by sofastack.
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.spi.model.Plugin in project sofa-ark by sofastack.
the class ClassLoaderServiceTest method testFindExportResources.
@Test
public void testFindExportResources() {
PluginClassLoader pluginClassLoader = new PluginClassLoader("mockPlugin", new URL[] {});
String exportResources = "spring-beans.xsd,*.xsd,com/alipay/sofa/*,xml-test.xml";
Plugin plugin = new PluginModel().setPluginName("mockPlugin").setExportPackages("").setExportClasses("").setPluginClassLoader(pluginClassLoader).setExportResources(exportResources);
pluginManagerService.registerPlugin(plugin);
classloaderService.prepareExportClassAndResourceCache();
Set<String> exportPrefixResourceStems = plugin.getExportPrefixResourceStems();
Assert.assertTrue(exportPrefixResourceStems.contains("com/alipay/sofa/"));
Set<String> exportSuffixResourceStems = plugin.getExportSuffixResourceStems();
Assert.assertTrue(exportSuffixResourceStems.contains(".xsd"));
Set<String> resources = plugin.getExportResources();
Assert.assertTrue(resources.contains("xml-test.xml"));
Assert.assertTrue(resources.contains("spring-beans.xsd"));
plugin.getExportPrefixResourceStems().clear();
plugin.getExportSuffixResourceStems().clear();
plugin.getExportResources().clear();
pluginManagerService.getPluginsInOrder().remove(plugin);
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by sofastack.
the class PluginDeployServiceImpl method unDeploy.
@Override
public void unDeploy() throws ArkRuntimeException {
List<Plugin> pluginsInOrder = pluginManagerService.getPluginsInOrder();
Collections.reverse(pluginsInOrder);
for (Plugin plugin : pluginsInOrder) {
try {
unDeployPlugin(plugin);
} catch (ArkRuntimeException e) {
LOGGER.error(String.format("UnDeploy plugin: %s meet error", plugin.getPluginName()), e);
throw e;
}
}
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by sofastack.
the class BizFactoryServiceTest method testPackageInfo.
@Test
public void testPackageInfo() throws Throwable {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL samplePlugin = cl.getResource("sample-ark-plugin.jar");
Plugin plugin = pluginFactoryService.createPlugin(new File(samplePlugin.getFile()));
ClassLoader pluginClassLoader = plugin.getPluginClassLoader();
pluginManagerService.registerPlugin(plugin);
Class mdc = pluginClassLoader.loadClass("org.slf4j.MDC");
Assert.assertTrue(mdc.getClassLoader().equals(pluginClassLoader));
Assert.assertNotNull(mdc.getPackage().getImplementationVersion());
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by sofastack.
the class ClassLoaderServiceImpl method isResourceInImport.
@Override
public boolean isResourceInImport(String pluginName, String resourceName) {
Plugin plugin = pluginManagerService.getPluginByName(pluginName);
AssertUtils.assertNotNull(plugin, "plugin: " + pluginName + " is null");
for (String importResource : plugin.getImportResources()) {
if (importResource.equals(resourceName)) {
return true;
}
}
for (String importResource : plugin.getImportPrefixResourceStems()) {
if (resourceName.startsWith(importResource)) {
return true;
}
}
for (String importResource : plugin.getImportSuffixResourceStems()) {
if (resourceName.endsWith(importResource)) {
return true;
}
}
return false;
}
Aggregations