Search in sources :

Example 1 with PluginManagerService

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);
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) PluginDeployService(com.alipay.sofa.ark.spi.service.plugin.PluginDeployService) ClassloaderService(com.alipay.sofa.ark.spi.service.classloader.ClassloaderService) ArkServiceContainer(com.alipay.sofa.ark.container.service.ArkServiceContainer) Before(org.junit.Before)

Example 2 with PluginManagerService

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);
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) PluginModel(com.alipay.sofa.ark.container.model.PluginModel) Plugin(com.alipay.sofa.ark.spi.model.Plugin)

Example 3 with PluginManagerService

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

Example 4 with PluginManagerService

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"));
    }
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) PluginModel(com.alipay.sofa.ark.container.model.PluginModel) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) ArkContainerTest(com.alipay.sofa.ark.container.ArkContainerTest) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 5 with PluginManagerService

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)));
    }
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) Extension(com.alipay.sofa.ark.spi.service.extension.Extension) PluginModel(com.alipay.sofa.ark.container.model.PluginModel) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException) ArkContainerTest(com.alipay.sofa.ark.container.ArkContainerTest) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Aggregations

PluginManagerService (com.alipay.sofa.ark.spi.service.plugin.PluginManagerService)8 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)5 ArkContainerTest (com.alipay.sofa.ark.container.ArkContainerTest)4 BaseTest (com.alipay.sofa.ark.container.BaseTest)4 Test (org.junit.Test)4 ArkServiceContainer (com.alipay.sofa.ark.container.service.ArkServiceContainer)3 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)3 ClassloaderService (com.alipay.sofa.ark.spi.service.classloader.ClassloaderService)3 PluginDeployService (com.alipay.sofa.ark.spi.service.plugin.PluginDeployService)3 Before (org.junit.Before)3 ServiceB (com.alipay.sofa.ark.container.service.extension.spi.ServiceB)1 ServiceBImpl3 (com.alipay.sofa.ark.container.service.extension.spi.impl.ServiceBImpl3)1 ServiceBImpl4 (com.alipay.sofa.ark.container.service.extension.spi.impl.ServiceBImpl4)1 Plugin (com.alipay.sofa.ark.spi.model.Plugin)1 BizManagerService (com.alipay.sofa.ark.spi.service.biz.BizManagerService)1 Extensible (com.alipay.sofa.ark.spi.service.extension.Extensible)1 Extension (com.alipay.sofa.ark.spi.service.extension.Extension)1 RegistryService (com.alipay.sofa.ark.spi.service.registry.RegistryService)1