Search in sources :

Example 1 with ServiceB

use of com.alipay.sofa.ark.container.service.extension.spi.ServiceB 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 2 with ServiceB

use of com.alipay.sofa.ark.container.service.extension.spi.ServiceB in project sofa-ark by sofastack.

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)

Aggregations

ArkContainerTest (com.alipay.sofa.ark.container.ArkContainerTest)2 BaseTest (com.alipay.sofa.ark.container.BaseTest)2 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)2 ServiceB (com.alipay.sofa.ark.container.service.extension.spi.ServiceB)2 ServiceBImpl3 (com.alipay.sofa.ark.container.service.extension.spi.impl.ServiceBImpl3)2 ServiceBImpl4 (com.alipay.sofa.ark.container.service.extension.spi.impl.ServiceBImpl4)2 PluginManagerService (com.alipay.sofa.ark.spi.service.plugin.PluginManagerService)2 Test (org.junit.Test)2