use of com.alipay.sofa.ark.container.registry.PluginNameServiceFilter 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());
}
Aggregations