Search in sources :

Example 1 with TestObjectC

use of com.alipay.sofa.ark.container.testdata.impl.TestObjectC in project sofa-ark by alipay.

the class RegistryServiceTest method testFilter.

@Test
public void testFilter() {
    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());
    Assert.assertEquals(pluginB.getPluginName(), registryService.referenceService(ITest.class).getServiceMetadata().getServiceProvider().getServiceProviderName());
    Assert.assertEquals(pluginA.getPluginName(), registryService.referenceService(ITest.class, new PluginNameServiceFilter(pluginA.getPluginName())).getServiceMetadata().getServiceProvider().getServiceProviderName());
    Assert.assertNull(registryService.referenceService(ITest.class, new PluginNameServiceFilter("not exist")));
    Assert.assertEquals("ArkContainer", registryService.referenceService(ITest.class, new ServiceFilter() {

        @Override
        public boolean match(ServiceProvider serviceProvider) {
            return ServiceProviderType.ARK_CONTAINER.equals(serviceProvider.getServiceProviderType());
        }
    }).getServiceMetadata().getServiceProvider().getServiceProviderName());
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) PluginNameServiceFilter(com.alipay.sofa.ark.container.registry.PluginNameServiceFilter) ServiceFilter(com.alipay.sofa.ark.spi.registry.ServiceFilter) TestObjectC(com.alipay.sofa.ark.container.testdata.impl.TestObjectC) 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) ServiceProvider(com.alipay.sofa.ark.spi.registry.ServiceProvider) PluginServiceProvider(com.alipay.sofa.ark.container.registry.PluginServiceProvider) ArkContainerServiceProvider(com.alipay.sofa.ark.container.registry.ArkContainerServiceProvider) PluginServiceProvider(com.alipay.sofa.ark.container.registry.PluginServiceProvider) PluginNameServiceFilter(com.alipay.sofa.ark.container.registry.PluginNameServiceFilter) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 2 with TestObjectC

use of com.alipay.sofa.ark.container.testdata.impl.TestObjectC in project sofa-ark by alipay.

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)

Example 3 with TestObjectC

use of com.alipay.sofa.ark.container.testdata.impl.TestObjectC in project sofa-ark by alipay.

the class RegistryServiceTest method testContainerService.

@Test
public void testContainerService() {
    registryService.publishService(ITest.class, new TestObjectA(), new ArkContainerServiceProvider("test1", 20000));
    registryService.publishService(ITest.class, new TestObjectB(), new ArkContainerServiceProvider("test2", 100));
    registryService.publishService(ITest.class, new TestObjectC());
    Assert.assertEquals(TestObjectB.OUTPUT, registryService.referenceService(ITest.class).getService().test());
    Assert.assertEquals(3, registryService.referenceServices(ITest.class).size());
}
Also used : TestObjectC(com.alipay.sofa.ark.container.testdata.impl.TestObjectC) TestObjectA(com.alipay.sofa.ark.container.testdata.impl.TestObjectA) ArkContainerServiceProvider(com.alipay.sofa.ark.container.registry.ArkContainerServiceProvider) TestObjectB(com.alipay.sofa.ark.container.testdata.impl.TestObjectB) ITest(com.alipay.sofa.ark.container.testdata.ITest) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 4 with TestObjectC

use of com.alipay.sofa.ark.container.testdata.impl.TestObjectC in project sofa-ark by alipay.

the class ServiceRegistrationTest method testContainerService.

@Test
public void testContainerService() {
    registryService.publishService(ITest.class, new TestObjectA(), new ContainerServiceProvider(20000));
    registryService.publishService(ITest.class, new TestObjectB(), new ContainerServiceProvider(100));
    registryService.publishService(ITest.class, new TestObjectC(), new ContainerServiceProvider(200));
    Assert.assertEquals(TestObjectB.OUTPUT, registryService.referenceService(ITest.class).getService().test());
    Assert.assertEquals(3, registryService.referenceServices(ITest.class).size());
}
Also used : TestObjectC(com.alipay.sofa.ark.container.testdata.impl.TestObjectC) 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)

Aggregations

BaseTest (com.alipay.sofa.ark.container.BaseTest)4 ITest (com.alipay.sofa.ark.container.testdata.ITest)4 TestObjectA (com.alipay.sofa.ark.container.testdata.impl.TestObjectA)4 TestObjectB (com.alipay.sofa.ark.container.testdata.impl.TestObjectB)4 TestObjectC (com.alipay.sofa.ark.container.testdata.impl.TestObjectC)4 Test (org.junit.Test)4 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)2 ArkContainerServiceProvider (com.alipay.sofa.ark.container.registry.ArkContainerServiceProvider)2 ContainerServiceProvider (com.alipay.sofa.ark.container.registry.ContainerServiceProvider)2 PluginServiceProvider (com.alipay.sofa.ark.container.registry.PluginServiceProvider)2 ServiceFilter (com.alipay.sofa.ark.spi.registry.ServiceFilter)2 ServiceProvider (com.alipay.sofa.ark.spi.registry.ServiceProvider)2 DefaultServiceFilter (com.alipay.sofa.ark.container.registry.DefaultServiceFilter)1 PluginNameServiceFilter (com.alipay.sofa.ark.container.registry.PluginNameServiceFilter)1 ServiceReference (com.alipay.sofa.ark.spi.registry.ServiceReference)1