use of com.alipay.sofa.ark.spi.service.plugin.PluginManagerService in project sofa-ark by alipay.
the class PluginClassloaderTest method before.
@Before
public void before() {
ArkServiceContainer arkServiceContainer = new ArkServiceContainer();
arkServiceContainer.start();
pluginManagerService = ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class);
pluginDeployService = ArkServiceContainerHolder.getContainer().getService(PluginDeployService.class);
classloaderService = ArkServiceContainerHolder.getContainer().getService(ClassloaderService.class);
}
use of com.alipay.sofa.ark.spi.service.plugin.PluginManagerService in project sofa-ark by alipay.
the class BaseTest method registerMockPlugin.
protected void registerMockPlugin() {
if (arkContainer == null) {
String[] args = new String[] { "-Ajar=" + jarURL.toExternalForm() };
arkContainer = (ArkContainer) ArkContainer.main(args);
}
PluginManagerService pluginManagerService = ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class);
Plugin plugin = new PluginModel().setPluginName("mock").setPluginClassLoader(this.getClass().getClassLoader()).setImportClasses("").setImportPackages("").setImportResources("");
pluginManagerService.registerPlugin(plugin);
}
use of com.alipay.sofa.ark.spi.service.plugin.PluginManagerService 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);
}
use of com.alipay.sofa.ark.spi.service.plugin.PluginManagerService in project sofa-ark by alipay.
the class ExtensionServiceTest method testExtensionServiceNotInstance.
@Test
public void testExtensionServiceNotInstance() {
PluginManagerService pluginManagerService = ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class);
PluginModel pluginModel = new PluginModel().setPluginClassLoader(this.getClass().getClassLoader()).setPluginName("mock-plugin");
pluginManagerService.registerPlugin(pluginModel);
try {
ArkServiceLoader.loadExtensionFromArkPlugin(ServiceA.class, "", "mock-plugin");
} catch (ArkRuntimeException ex) {
Assert.assertTrue(ex.getMessage().contains("not type of"));
}
}
use of com.alipay.sofa.ark.spi.service.plugin.PluginManagerService in project sofa-ark by alipay.
the class ExtensionServiceTest method testNoExtensionAnnotation.
@Test
public void testNoExtensionAnnotation() {
PluginManagerService pluginManagerService = ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class);
PluginModel pluginModel = new PluginModel().setPluginClassLoader(this.getClass().getClassLoader()).setPluginName("mock-plugin");
pluginManagerService.registerPlugin(pluginModel);
try {
ArkServiceLoader.loadExtensionFromArkPlugin(ServiceD.class, "", "mock-plugin");
} catch (ArkRuntimeException ex) {
Assert.assertTrue(ex.getMessage().contains(String.format("is not annotated by %s.", Extension.class)));
}
}
Aggregations