Search in sources :

Example 16 with ContainerServiceProvider

use of com.alipay.sofa.ark.container.registry.ContainerServiceProvider in project sofa-ark by sofastack.

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);
}
Also used : DefaultServiceFilter(com.alipay.sofa.ark.container.registry.DefaultServiceFilter) TestObjectA(com.alipay.sofa.ark.container.testdata.impl.TestObjectA) ITest(com.alipay.sofa.ark.container.testdata.ITest) ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 17 with ContainerServiceProvider

use of com.alipay.sofa.ark.container.registry.ContainerServiceProvider in project sofa-ark by sofastack.

the class ServiceRegistrationTest method testPublishDuplicateService.

@Test
@SuppressWarnings("unchecked")
public void testPublishDuplicateService() {
    registryService.publishService(ITest.class, new TestObjectA(), new ContainerServiceProvider());
    registryService.publishService(ITest.class, new TestObjectB(), new ContainerServiceProvider());
    // 只有第一个服务发布成功
    Assert.assertEquals(1, registryService.referenceServices(ITest.class).size());
    Assert.assertEquals(TestObjectA.OUTPUT, registryService.referenceService(ITest.class).getService().test());
    registryService.unPublishServices(new DefaultServiceFilter().setServiceInterface(ITest.class));
    Assert.assertEquals(0, registryService.referenceServices(ITest.class).size());
    registryService.publishService(ITest.class, new TestObjectA(), "testA", new ContainerServiceProvider());
    registryService.publishService(ITest.class, new TestObjectB(), "testB", new ContainerServiceProvider());
    Assert.assertEquals(2, registryService.referenceServices(new DefaultServiceFilter().setServiceInterface(ITest.class)).size());
    Assert.assertEquals(TestObjectA.OUTPUT, registryService.referenceService(ITest.class, "testA").getService().test());
    Assert.assertEquals(TestObjectB.OUTPUT, registryService.referenceService(ITest.class, "testB").getService().test());
    int c = registryService.unPublishServices(new DefaultServiceFilter().setUniqueId("testA"));
    Assert.assertTrue(c == 1);
    c = registryService.unPublishServices(new DefaultServiceFilter().setProviderType(ServiceProviderType.ARK_CONTAINER).setServiceInterface(ITest.class));
    Assert.assertTrue(c == 1);
    Assert.assertEquals(0, registryService.referenceServices(ITest.class).size());
}
Also used : DefaultServiceFilter(com.alipay.sofa.ark.container.registry.DefaultServiceFilter) TestObjectA(com.alipay.sofa.ark.container.testdata.impl.TestObjectA) TestObjectB(com.alipay.sofa.ark.container.testdata.impl.TestObjectB) ITest(com.alipay.sofa.ark.container.testdata.ITest) ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 18 with ContainerServiceProvider

use of com.alipay.sofa.ark.container.registry.ContainerServiceProvider in project sofa-ark by sofastack.

the class ServiceRegistrationTest method testFilter.

@Test
@SuppressWarnings("unchecked")
public void testFilter() {
    final PluginModel pluginA = new PluginModel();
    pluginA.setPluginName("plugin A").setPriority("10");
    PluginModel pluginB = new PluginModel();
    pluginB.setPluginName("plugin B").setPriority("1");
    pluginManagerService.registerPlugin(pluginA);
    pluginManagerService.registerPlugin(pluginB);
    registryService.publishService(ITest.class, new TestObjectA(), new PluginServiceProvider(pluginA));
    registryService.publishService(ITest.class, new TestObjectB(), new PluginServiceProvider(pluginB));
    registryService.publishService(ITest.class, new TestObjectC(), new ContainerServiceProvider());
    List<ServiceReference> references = registryService.referenceServices(new DefaultServiceFilter().setServiceInterface(ITest.class).setProviderType(ServiceProviderType.ARK_PLUGIN));
    Assert.assertTrue(2 == references.size());
    PluginServiceProvider provider = (PluginServiceProvider) references.get(0).getServiceMetadata().getServiceProvider();
    Assert.assertEquals(pluginB.getPluginName(), provider.getPluginName());
    references = registryService.referenceServices(new ServiceFilter() {

        @Override
        public boolean match(ServiceReference serviceReference) {
            ServiceProvider serviceProvider = serviceReference.getServiceMetadata().getServiceProvider();
            if (serviceProvider instanceof PluginServiceProvider) {
                if (((PluginServiceProvider) serviceProvider).getPluginName().equals(pluginA.getPluginName())) {
                    return true;
                }
            }
            return false;
        }
    });
    Assert.assertTrue(1 == references.size());
    provider = (PluginServiceProvider) references.get(0).getServiceMetadata().getServiceProvider();
    Assert.assertEquals(pluginA.getPluginName(), provider.getPluginName());
    references = registryService.referenceServices(new DefaultServiceFilter().setServiceInterface(ITest.class));
    Assert.assertTrue(3 == references.size());
    references = registryService.referenceServices(new DefaultServiceFilter().setProviderType(ServiceProviderType.ARK_CONTAINER).setServiceInterface(ITest.class));
    Assert.assertTrue(1 == references.size());
    Assert.assertEquals("TestObject C", ((TestObjectC) references.get(0).getService()).test());
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) DefaultServiceFilter(com.alipay.sofa.ark.container.registry.DefaultServiceFilter) ServiceFilter(com.alipay.sofa.ark.spi.registry.ServiceFilter) TestObjectC(com.alipay.sofa.ark.container.testdata.impl.TestObjectC) DefaultServiceFilter(com.alipay.sofa.ark.container.registry.DefaultServiceFilter) TestObjectA(com.alipay.sofa.ark.container.testdata.impl.TestObjectA) TestObjectB(com.alipay.sofa.ark.container.testdata.impl.TestObjectB) ServiceProvider(com.alipay.sofa.ark.spi.registry.ServiceProvider) ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) PluginServiceProvider(com.alipay.sofa.ark.container.registry.PluginServiceProvider) ContainerServiceProvider(com.alipay.sofa.ark.container.registry.ContainerServiceProvider) PluginServiceProvider(com.alipay.sofa.ark.container.registry.PluginServiceProvider) ServiceReference(com.alipay.sofa.ark.spi.registry.ServiceReference) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Aggregations

ContainerServiceProvider (com.alipay.sofa.ark.container.registry.ContainerServiceProvider)18 BaseTest (com.alipay.sofa.ark.container.BaseTest)16 Test (org.junit.Test)16 ITest (com.alipay.sofa.ark.container.testdata.ITest)12 TestObjectA (com.alipay.sofa.ark.container.testdata.impl.TestObjectA)12 DefaultServiceFilter (com.alipay.sofa.ark.container.registry.DefaultServiceFilter)8 TestObjectB (com.alipay.sofa.ark.container.testdata.impl.TestObjectB)6 RegistryService (com.alipay.sofa.ark.spi.service.registry.RegistryService)6 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)4 PluginServiceProvider (com.alipay.sofa.ark.container.registry.PluginServiceProvider)4 TestObjectC (com.alipay.sofa.ark.container.testdata.impl.TestObjectC)4 ServiceReference (com.alipay.sofa.ark.spi.registry.ServiceReference)4 PluginContextImpl (com.alipay.sofa.ark.container.model.PluginContextImpl)2 BizCommandProvider (com.alipay.sofa.ark.container.service.biz.BizCommandProvider)2 DefaultBizDeployer (com.alipay.sofa.ark.container.service.biz.DefaultBizDeployer)2 PluginClassLoader (com.alipay.sofa.ark.container.service.classloader.PluginClassLoader)2 PluginCommandProvider (com.alipay.sofa.ark.container.service.plugin.PluginCommandProvider)2 ArkCommandHandler (com.alipay.sofa.ark.container.session.handler.ArkCommandHandler)2 PluginActivatorA (com.alipay.sofa.ark.container.testdata.activator.PluginActivatorA)2 PluginActivatorB (com.alipay.sofa.ark.container.testdata.activator.PluginActivatorB)2