Search in sources :

Example 26 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel 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 27 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel 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)

Example 28 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class HandleArchiveTest method testIncludePlugin.

@Test
public void testIncludePlugin() {
    try {
        HandleArchiveStage handleArchiveStage = new HandleArchiveStage();
        System.setProperty(PLUGIN_ACTIVE_INCLUDE, "pluginA");
        PluginModel pluginModel = new PluginModel();
        pluginModel.setPluginName("pluginA");
        Assert.assertFalse(handleArchiveStage.isPluginExcluded(pluginModel));
        pluginModel.setPluginName("pluginB");
        Assert.assertTrue(handleArchiveStage.isPluginExcluded(pluginModel));
        pluginModel.setPluginName("pluginC");
        Assert.assertTrue(handleArchiveStage.isPluginExcluded(pluginModel));
    } finally {
        System.clearProperty(PLUGIN_ACTIVE_INCLUDE);
    }
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) HandleArchiveStage(com.alipay.sofa.ark.container.pipeline.HandleArchiveStage) Test(org.junit.Test)

Example 29 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class HandleArchiveTest method testIncludeExcludePlugin.

@Test
public void testIncludeExcludePlugin() {
    try {
        HandleArchiveStage handleArchiveStage = new HandleArchiveStage();
        System.setProperty(PLUGIN_ACTIVE_INCLUDE, "pluginA");
        System.setProperty(PLUGIN_ACTIVE_EXCLUDE, "pluginA,pluginB");
        PluginModel pluginModel = new PluginModel();
        pluginModel.setPluginName("pluginA");
        Assert.assertFalse(handleArchiveStage.isPluginExcluded(pluginModel));
        pluginModel.setPluginName("pluginB");
        Assert.assertTrue(handleArchiveStage.isPluginExcluded(pluginModel));
        pluginModel.setPluginName("pluginC");
        Assert.assertTrue(handleArchiveStage.isPluginExcluded(pluginModel));
    } finally {
        System.clearProperty(PLUGIN_ACTIVE_EXCLUDE);
        System.clearProperty(PLUGIN_ACTIVE_INCLUDE);
    }
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) HandleArchiveStage(com.alipay.sofa.ark.container.pipeline.HandleArchiveStage) Test(org.junit.Test)

Example 30 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class HandleArchiveTest method testNoIncludeExcludeBiz.

@Test
public void testNoIncludeExcludeBiz() {
    HandleArchiveStage handleArchiveStage = new HandleArchiveStage();
    PluginModel pluginModel = new PluginModel();
    pluginModel.setPluginName("pluginA");
    Assert.assertFalse(handleArchiveStage.isPluginExcluded(pluginModel));
    pluginModel.setPluginName("pluginB");
    Assert.assertFalse(handleArchiveStage.isPluginExcluded(pluginModel));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) HandleArchiveStage(com.alipay.sofa.ark.container.pipeline.HandleArchiveStage) Test(org.junit.Test)

Aggregations

PluginModel (com.alipay.sofa.ark.container.model.PluginModel)47 Test (org.junit.Test)42 BaseTest (com.alipay.sofa.ark.container.BaseTest)34 ITest (com.alipay.sofa.ark.container.testdata.ITest)25 URL (java.net.URL)16 PluginContextImpl (com.alipay.sofa.ark.container.model.PluginContextImpl)9 HashSet (java.util.HashSet)9 BizModel (com.alipay.sofa.ark.container.model.BizModel)8 PluginClassLoader (com.alipay.sofa.ark.container.service.classloader.PluginClassLoader)7 Plugin (com.alipay.sofa.ark.spi.model.Plugin)7 TestObjectA (com.alipay.sofa.ark.container.testdata.impl.TestObjectA)5 PluginManagerService (com.alipay.sofa.ark.spi.service.plugin.PluginManagerService)5 ArkContainerTest (com.alipay.sofa.ark.container.ArkContainerTest)4 HandleArchiveStage (com.alipay.sofa.ark.container.pipeline.HandleArchiveStage)4 URLClassLoader (java.net.URLClassLoader)4 Attributes (java.util.jar.Attributes)4 DefaultServiceFilter (com.alipay.sofa.ark.container.registry.DefaultServiceFilter)3 PluginServiceProvider (com.alipay.sofa.ark.container.registry.PluginServiceProvider)3 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)3 ContainerServiceProvider (com.alipay.sofa.ark.container.registry.ContainerServiceProvider)2