use of com.alipay.sofa.ark.container.testdata.ITest in project sofa-ark by alipay.
the class RegistryServiceTest method testPublishService.
@Test
public void testPublishService() throws Exception {
ServiceReference<ITest> iTestServiceReference = registryService.publishService(ITest.class, new TestObjectA());
Assert.assertNotNull(iTestServiceReference);
Assert.assertEquals(TestObjectA.OUTPUT, iTestServiceReference.getService().test());
}
use of com.alipay.sofa.ark.container.testdata.ITest in project sofa-ark by alipay.
the class RegistryServiceTest method testReferenceService.
@Test
public void testReferenceService() throws Exception {
registryService.publishService(ITest.class, new TestObjectA());
ServiceReference<ITest> iTestServiceReference = registryService.referenceService(ITest.class);
Assert.assertNotNull(iTestServiceReference);
Assert.assertEquals(TestObjectA.OUTPUT, iTestServiceReference.getService().test());
}
use of com.alipay.sofa.ark.container.testdata.ITest in project sofa-ark by alipay.
the class ServiceRegistrationTest method testPublishService.
@Test
@SuppressWarnings("unchecked")
public void testPublishService() {
ServiceReference<ITest> iTestServiceReference = registryService.publishService(ITest.class, new TestObjectA(), new ContainerServiceProvider());
Assert.assertNotNull(iTestServiceReference);
Assert.assertEquals(TestObjectA.OUTPUT, iTestServiceReference.getService().test());
int c = registryService.unPublishServices(new DefaultServiceFilter().setServiceInterface(ITest.class).setProviderType(ServiceProviderType.ARK_CONTAINER));
Assert.assertTrue(c == 1);
iTestServiceReference = registryService.referenceService(ITest.class);
Assert.assertNull(iTestServiceReference);
}
use of com.alipay.sofa.ark.container.testdata.ITest in project sofa-ark by alipay.
the class ServiceRegistrationTest method testMultipleService.
@Test
@SuppressWarnings("unchecked")
public void testMultipleService() throws Exception {
// 非插件发布的服务,优先级别最低
registryService.publishService(ITest.class, new TestObjectA(), new ContainerServiceProvider());
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setPriority("10").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages(ClassUtils.getPackageName(INTERFACE_CLASS)).setExportClasses("").setImportResources(StringUtils.EMPTY_STRING).setExportResources(StringUtils.EMPTY_STRING).setPluginActivator(PluginActivatorA.class.getName()).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath())).setPluginContext(new PluginContextImpl(pluginA));
PluginModel pluginB = new PluginModel();
pluginB.setPluginName("plugin B").setPriority("1").setClassPath(new URL[] { classPathURL }).setImportClasses(INTERFACE_CLASS).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages("").setExportClasses("").setImportResources(StringUtils.EMPTY_STRING).setExportResources(StringUtils.EMPTY_STRING).setPluginActivator(PluginActivatorB.class.getName()).setPluginClassLoader(new PluginClassLoader(pluginB.getPluginName(), pluginB.getClassPath())).setPluginContext(new PluginContextImpl(pluginB));
PluginModel pluginC = new PluginModel();
pluginC.setPluginName("plugin C").setPriority("100").setClassPath(new URL[] { classPathURL }).setImportClasses(INTERFACE_CLASS).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages("").setExportClasses("").setImportResources(StringUtils.EMPTY_STRING).setExportResources(StringUtils.EMPTY_STRING).setPluginActivator(PluginActivatorC.class.getName()).setPluginClassLoader(new PluginClassLoader(pluginC.getPluginName(), pluginC.getClassPath())).setPluginContext(new PluginContextImpl(pluginC));
pluginManagerService.registerPlugin(pluginA);
pluginManagerService.registerPlugin(pluginB);
pluginManagerService.registerPlugin(pluginC);
classloaderService.prepareExportClassAndResourceCache();
pluginDeployService.deploy();
Class iTest = pluginA.getPluginClassLoader().loadClass(ITest.class.getCanonicalName());
Assert.assertEquals(3, pluginA.getPluginContext().referenceServices(new DefaultServiceFilter().setServiceInterface(iTest)).size());
// 应该获取到优先级别比较高的服务
ServiceReference reference = pluginC.getPluginContext().referenceService(iTest);
PluginServiceProvider provider = (PluginServiceProvider) reference.getServiceMetadata().getServiceProvider();
Assert.assertEquals(pluginB.getPluginName(), provider.getPluginName());
List<ServiceReference> references = pluginC.getPluginContext().referenceServices(new DefaultServiceFilter().setServiceInterface(iTest));
provider = (PluginServiceProvider) references.get(0).getServiceMetadata().getServiceProvider();
Assert.assertEquals(pluginB.getPluginName(), provider.getPluginName());
}
use of com.alipay.sofa.ark.container.testdata.ITest in project sofa-ark by alipay.
the class ServiceRegistrationTest method testReferenceService.
@Test
public void testReferenceService() {
registryService.publishService(ITest.class, new TestObjectA(), new ContainerServiceProvider());
ServiceReference<ITest> iTestServiceReference = registryService.referenceService(ITest.class);
Assert.assertNotNull(iTestServiceReference);
Assert.assertEquals(TestObjectA.OUTPUT, iTestServiceReference.getService().test());
}
Aggregations