use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class RegistryServiceTest method testPublishDuplicateServiceInPlugin.
@Test
public void testPublishDuplicateServiceInPlugin() throws Exception {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setPriority(10).setClassPath(new URL[] { classPathURL }).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(new HashSet<>(Collections.singletonList(INTERFACE_CLASS))).setPluginActivator(PluginActivatorADup.class.getName()).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath())).setPluginContext(new PluginContextImpl(pluginA));
pluginManagerService.registerPlugin(pluginA);
classloaderService.prepareExportClassCache();
pluginDeployService.deploy();
Assert.assertEquals(1, registryService.referenceServices(ITest.class).size());
}
use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class RegistryServiceTest method testFilter.
@Test
public void testFilter() {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setPriority(10);
PluginModel pluginB = new PluginModel();
pluginB.setPluginName("plugin B").setPriority(1);
pluginManagerService.registerPlugin(pluginA);
pluginManagerService.registerPlugin(pluginB);
registryService.publishService(ITest.class, new TestObjectA(), new PluginServiceProvider(pluginA));
registryService.publishService(ITest.class, new TestObjectB(), new PluginServiceProvider(pluginB));
registryService.publishService(ITest.class, new TestObjectC());
Assert.assertEquals(pluginB.getPluginName(), registryService.referenceService(ITest.class).getServiceMetadata().getServiceProvider().getServiceProviderName());
Assert.assertEquals(pluginA.getPluginName(), registryService.referenceService(ITest.class, new PluginNameServiceFilter(pluginA.getPluginName())).getServiceMetadata().getServiceProvider().getServiceProviderName());
Assert.assertNull(registryService.referenceService(ITest.class, new PluginNameServiceFilter("not exist")));
Assert.assertEquals("ArkContainer", registryService.referenceService(ITest.class, new ServiceFilter() {
@Override
public boolean match(ServiceProvider serviceProvider) {
return ServiceProviderType.ARK_CONTAINER.equals(serviceProvider.getServiceProviderType());
}
}).getServiceMetadata().getServiceProvider().getServiceProviderName());
}
use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class RegistryServiceTest method testContainerServiceNotFoundByPlugin.
@Test
public void testContainerServiceNotFoundByPlugin() {
registryService.publishService(ITest.class, new TestObjectA());
Assert.assertNotNull(registryService.referenceService(ITest.class));
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setPriority(10).setPluginContext(new PluginContextImpl(pluginA));
pluginManagerService.registerPlugin(pluginA);
Assert.assertNull(pluginA.getPluginContext().referenceService(ITest.class));
}
use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class HandleArchiveStage method transformPluginArchive.
private Plugin transformPluginArchive(PluginArchive pluginArchive) throws Exception {
PluginModel plugin = new PluginModel();
Attributes manifestMainAttributes = pluginArchive.getManifest().getMainAttributes();
return plugin.setPluginName(manifestMainAttributes.getValue(PLUGIN_NAME_ATTRIBUTE)).setGroupId(manifestMainAttributes.getValue(GROUP_ID_ATTRIBUTE)).setArtifactId(manifestMainAttributes.getValue(ARTIFACT_ID_ATTRIBUTE)).setVersion(manifestMainAttributes.getValue(PLUGIN_VERSION_ATTRIBUTE)).setPriority(Integer.valueOf(manifestMainAttributes.getValue(PRIORITY_ATTRIBUTE))).setPluginActivator(manifestMainAttributes.getValue(ACTIVATOR_ATTRIBUTE)).setClassPath(pluginArchive.getUrls()).setExportClasses(new HashSet<>(Arrays.asList(filterEmptyString(manifestMainAttributes.getValue(EXPORT_CLASSES_ATTRIBUTE))))).setExportPackages(new HashSet<>(Arrays.asList(filterEmptyString(manifestMainAttributes.getValue(EXPORT_PACKAGES_ATTRIBUTE))))).setImportClasses(new HashSet<>(Arrays.asList(filterEmptyString(manifestMainAttributes.getValue(IMPORT_CLASSES_ATTRIBUTE))))).setImportPackages(new HashSet<>(Arrays.asList(filterEmptyString(manifestMainAttributes.getValue(IMPORT_PACKAGES_ATTRIBUTE))))).setExportIndex(pluginArchive.getExportIndex()).setPluginClassLoader(new PluginClassLoader(plugin.getPluginName(), plugin.getClassPath())).setPluginContext(new PluginContextImpl(plugin));
}
use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.
the class PluginCommandProviderTest method testPluginCommandProcess.
@Test
public void testPluginCommandProcess(@Mocked final PluginManagerService pluginManagerService) {
URL[] urls = ((URLClassLoader) this.getClass().getClassLoader()).getURLs();
final Plugin pluginA = new PluginModel().setPluginName("pluginA").setImportClasses("com.google.common.io.AppendableWriter").setImportPackages(" com.google.common.cache, com.google.common.base ").setImportResources(" import_resource1").setExportPackages("com.alipay.sofa.*").setExportResources(" export_resource1, export_resource2").setPluginActivator("com.alipay.sofa.pluginA.Activator").setClassPath(urls).setGroupId("com.alipay.sofa").setArtifactId("ark-mock-pluginA").setVersion("1.0.0");
final Plugin pluginB = new PluginModel().setPluginName("pluginB").setImportClasses("com.google.common.io.AppendableWriter").setImportPackages(" com.google.common.cache, com.google.common.base ").setImportResources(" import_resource1").setExportPackages("com.alipay.sofa.*").setExportResources(" export_resource1, export_resource2").setPluginActivator("com.alipay.sofa.pluginA.Activator").setClassPath(urls).setGroupId("com.alipay.sofa").setArtifactId("ark-mock-pluginB").setVersion("1.0.0");
final Set<String> set = new HashSet<>();
set.add("pluginA");
set.add("pluginB");
new Expectations() {
{
pluginManagerService.getAllPluginNames();
result = set;
minTimes = 0;
pluginManagerService.getPluginByName("pluginA");
result = pluginA;
minTimes = 0;
pluginManagerService.getPluginByName("pluginB");
result = pluginB;
minTimes = 0;
}
};
PluginCommandProvider pluginCommandProvider = new PluginCommandProvider();
try {
Field field = PluginCommandProvider.class.getDeclaredField("pluginManagerService");
field.setAccessible(true);
field.set(pluginCommandProvider, pluginManagerService);
} catch (Throwable throwable) {
// ignore
}
String errorMessage = "Error command format. Pls type 'plugin -h' to get help message\n";
Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plu")));
Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plugin -h pluginA")));
Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plugin -b pluginA")));
Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plu")));
Assert.assertTrue(pluginCommandProvider.getHelp().equals(pluginCommandProvider.handleCommand("plugin -h")));
Assert.assertTrue(errorMessage.equals(pluginCommandProvider.handleCommand("plugin ")));
String details = pluginCommandProvider.handleCommand("plugin -m -d -s pluginA");
Assert.assertTrue(details.contains("Activator"));
Assert.assertTrue(details.contains("GroupId"));
details = pluginCommandProvider.handleCommand("plugin -d pluginB");
Assert.assertTrue(details.contains("GroupId"));
Assert.assertFalse(details.contains("Activator"));
details = pluginCommandProvider.handleCommand("plugin -m plugin.");
Assert.assertTrue(details.contains("pluginA"));
Assert.assertTrue(details.contains("pluginB"));
details = pluginCommandProvider.handleCommand("plugin -m pluginC");
Assert.assertTrue(details.contains("no matched plugin candidates."));
}
Aggregations