Search in sources :

Example 1 with TestObjectA

use of com.alipay.sofa.ark.container.testdata.impl.TestObjectA 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 TestObjectA

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

the class RegistryServiceTest method testPublishDuplicateService.

@Test
public void testPublishDuplicateService() throws Exception {
    registryService.publishService(ITest.class, new TestObjectA());
    registryService.publishService(ITest.class, new TestObjectB());
    // 只有第一个服务发布成功
    Assert.assertEquals(1, registryService.referenceServices(ITest.class).size());
    Assert.assertEquals(TestObjectA.OUTPUT, registryService.referenceService(ITest.class).getService().test());
}
Also used : 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) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 3 with TestObjectA

use of com.alipay.sofa.ark.container.testdata.impl.TestObjectA 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());
}
Also used : TestObjectA(com.alipay.sofa.ark.container.testdata.impl.TestObjectA) 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 TestObjectA

use of com.alipay.sofa.ark.container.testdata.impl.TestObjectA 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());
}
Also used : TestObjectA(com.alipay.sofa.ark.container.testdata.impl.TestObjectA) 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 5 with TestObjectA

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

the class RegistryServiceTest method testContainerServiceNotFoundByPlugin.

@Test
public void testContainerServiceNotFoundByPlugin() {
    registryService.publishService(ITest.class, new TestObjectA());
    Assert.assertNotNull(registryService.referenceService(ITest.class));
    PluginModel pluginA = new PluginModel();
    pluginA.setPluginName("plugin A").setPriority(10).setPluginContext(new PluginContextImpl(pluginA));
    pluginManagerService.registerPlugin(pluginA);
    Assert.assertNull(pluginA.getPluginContext().referenceService(ITest.class));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) PluginContextImpl(com.alipay.sofa.ark.container.model.PluginContextImpl) TestObjectA(com.alipay.sofa.ark.container.testdata.impl.TestObjectA) 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)

Aggregations

TestObjectA (com.alipay.sofa.ark.container.testdata.impl.TestObjectA)15 BaseTest (com.alipay.sofa.ark.container.BaseTest)13 ITest (com.alipay.sofa.ark.container.testdata.ITest)13 Test (org.junit.Test)13 ContainerServiceProvider (com.alipay.sofa.ark.container.registry.ContainerServiceProvider)6 TestObjectB (com.alipay.sofa.ark.container.testdata.impl.TestObjectB)6 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)5 DefaultServiceFilter (com.alipay.sofa.ark.container.registry.DefaultServiceFilter)4 TestObjectC (com.alipay.sofa.ark.container.testdata.impl.TestObjectC)4 PluginContextImpl (com.alipay.sofa.ark.container.model.PluginContextImpl)3 PluginServiceProvider (com.alipay.sofa.ark.container.registry.PluginServiceProvider)3 ArkContainerServiceProvider (com.alipay.sofa.ark.container.registry.ArkContainerServiceProvider)2 PluginClassLoader (com.alipay.sofa.ark.container.service.classloader.PluginClassLoader)2 ServiceFilter (com.alipay.sofa.ark.spi.registry.ServiceFilter)2 ServiceProvider (com.alipay.sofa.ark.spi.registry.ServiceProvider)2 ServiceReference (com.alipay.sofa.ark.spi.registry.ServiceReference)2 PluginNameServiceFilter (com.alipay.sofa.ark.container.registry.PluginNameServiceFilter)1 PluginActivatorA (com.alipay.sofa.ark.container.testdata.Activator.PluginActivatorA)1 PluginActivatorB (com.alipay.sofa.ark.container.testdata.Activator.PluginActivatorB)1 PluginActivatorC (com.alipay.sofa.ark.container.testdata.Activator.PluginActivatorC)1