X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2Ftest%2FRpcProviderRegistryTest.java;h=de5f3ca46fd3d07545bc5bf3ee1920f826bbdb86;hp=110e5b4dce3f02e7f32aad00d0c8915ea188bb47;hb=e631dc96f0461b2270377dc072b9f969a875667a;hpb=6500c7a216b78417e65cdf882d2b78de27736a97 diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/RpcProviderRegistryTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/RpcProviderRegistryTest.java index 110e5b4dce..de5f3ca46f 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/RpcProviderRegistryTest.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/RpcProviderRegistryTest.java @@ -1,136 +1,106 @@ package org.opendaylight.controller.md.sal.binding.impl.test; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_BAR_KEY; import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY; import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.junit.Before; +import com.google.common.base.Throwables; +import java.util.Arrays; +import javassist.ClassPool; +import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; -import org.opendaylight.controller.md.sal.binding.test.AssertCollections; -import org.opendaylight.controller.md.sal.common.api.routing.RouteChange; -import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; +import org.opendaylight.controller.md.sal.binding.compat.HeliumRpcProviderRegistry; +import org.opendaylight.controller.md.sal.binding.impl.BindingDOMRpcProviderServiceAdapter; +import org.opendaylight.controller.md.sal.binding.impl.BindingDOMRpcServiceAdapter; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.md.sal.binding.test.AbstractSchemaAwareTest; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMRpcRouter; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; +import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier; -import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter; -import org.opendaylight.controller.sal.binding.impl.RpcProviderRegistryImpl; +import org.opendaylight.controller.sal.binding.codegen.RpcIsNotRoutedException; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.TestContext; +import org.opendaylight.yangtools.binding.data.codec.gen.impl.DataObjectSerializerGenerator; +import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator; +import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry; +import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy; +import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; - -import com.google.common.util.concurrent.SettableFuture; +import org.opendaylight.yangtools.yang.binding.YangModuleInfo; +import org.opendaylight.yangtools.yang.binding.util.BindingReflections; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; -public class RpcProviderRegistryTest { +public class RpcProviderRegistryTest extends AbstractSchemaAwareTest { private static InstanceIdentifier FOO_PATH = path(TOP_FOO_KEY); private static InstanceIdentifier BAR_PATH = path(TOP_BAR_KEY); private static RpcContextIdentifier ROUTING_CONTEXT = RpcContextIdentifier.contextFor(OpendaylightTestRoutedRpcService.class, TestContext.class); - private RpcProviderRegistryImpl rpcRegistry; + private RpcProviderRegistry rpcRegistry; - @Before - public void setup() { - rpcRegistry = new RpcProviderRegistryImpl("test"); - } - private static class TestListener implements RouteChangeListener> { - - final SettableFuture>> event = SettableFuture.create(); - @Override - public void onRouteChange( - final RouteChange> change) { - event.set(change); + @Override + protected Iterable getModuleInfos() { + try { + return Arrays.asList( + BindingReflections.getModuleInfo(TopLevelList.class), + BindingReflections.getModuleInfo(OpendaylightTestRoutedRpcService.class), + BindingReflections.getModuleInfo(OpendaylightTestRpcServiceService.class)); + } catch (final Exception e) { + throw Throwables.propagate(e); } } + @Override + protected void setupWithSchema(final SchemaContext context) { + final DataObjectSerializerGenerator generator = StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault())); + final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(generator); + final GeneratedClassLoadingStrategy classLoadingStrategy = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(); + final BindingToNormalizedNodeCodec codec = new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry); + final DOMRpcRouter domRpcRegistry = new DOMRpcRouter(); + domRpcRegistry.onGlobalContextUpdated(context); + codec.onGlobalContextUpdated(context); + final RpcConsumerRegistry consumer = new BindingDOMRpcServiceAdapter(domRpcRegistry, codec); + final BindingDOMRpcProviderServiceAdapter provider = new BindingDOMRpcProviderServiceAdapter( domRpcRegistry,codec); + rpcRegistry = new HeliumRpcProviderRegistry(consumer,provider); + } + @Test public void testGlobalRpcRegistrations() throws Exception { - OpendaylightTestRpcServiceService one = Mockito.mock(OpendaylightTestRpcServiceService.class); - OpendaylightTestRpcServiceService two = Mockito.mock(OpendaylightTestRpcServiceService.class); + final OpendaylightTestRpcServiceService one = Mockito.mock(OpendaylightTestRpcServiceService.class); + final OpendaylightTestRpcServiceService two = Mockito.mock(OpendaylightTestRpcServiceService.class); - RpcRegistration regOne = rpcRegistry.addRpcImplementation(OpendaylightTestRpcServiceService.class, one); + final RpcRegistration regOne = rpcRegistry.addRpcImplementation(OpendaylightTestRpcServiceService.class, one); assertNotNull(regOne); - - try { - rpcRegistry.addRpcImplementation(OpendaylightTestRpcServiceService.class, two); - fail("Second call for registration of same RPC must throw IllegalStateException"); - } catch (IllegalStateException e) { - assertNotNull(e.getMessage()); - } - + rpcRegistry.addRpcImplementation(OpendaylightTestRpcServiceService.class, two); regOne.close(); - - RpcRegistration regTwo = rpcRegistry.addRpcImplementation(OpendaylightTestRpcServiceService.class, two); + final RpcRegistration regTwo = rpcRegistry.addRpcImplementation(OpendaylightTestRpcServiceService.class, two); assertNotNull(regTwo); } - @Test - public void testRpcRouterInstance() throws Exception { - OpendaylightTestRoutedRpcService def = Mockito.mock(OpendaylightTestRoutedRpcService.class); - - RpcRouter router = rpcRegistry.getRpcRouter(OpendaylightTestRoutedRpcService.class); - - assertEquals(OpendaylightTestRoutedRpcService.class, router.getServiceType()); - assertNotNull(router.getInvocationProxy()); - assertNull(router.getDefaultService()); - - AssertCollections.assertContains(router.getContexts(), TestContext.class); - - RpcRegistration regDef = router.registerDefaultService(def); - assertNotNull(regDef); - assertEquals(OpendaylightTestRoutedRpcService.class,regDef.getServiceType()); - assertEquals(def,regDef.getInstance()); - assertEquals(def, router.getDefaultService()); - - regDef.close(); - assertNull("Default instance should be null after closing registration", router.getDefaultService()); - } @Test - public void testRoutedRpcPathChangeEvents() throws InterruptedException, TimeoutException, ExecutionException { - OpendaylightTestRoutedRpcService one = Mockito.mock(OpendaylightTestRoutedRpcService.class); - OpendaylightTestRoutedRpcService two = Mockito.mock(OpendaylightTestRoutedRpcService.class); - RoutedRpcRegistration regOne = rpcRegistry.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, one); - RoutedRpcRegistration regTwo = rpcRegistry.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, two); - assertNotNull(regOne); - assertNotNull(regTwo); - - final TestListener addListener = new TestListener(); - rpcRegistry.registerRouteChangeListener(addListener); - regOne.registerPath(TestContext.class, FOO_PATH); - - RouteChange> fooAddEvent = addListener.event.get(500, TimeUnit.MILLISECONDS); - Set> announce = fooAddEvent.getAnnouncements().get(ROUTING_CONTEXT); - assertNotNull(announce); - AssertCollections.assertContains(announce, FOO_PATH); - AssertCollections.assertNotContains(announce, BAR_PATH); - - - - final TestListener removeListener = new TestListener(); - rpcRegistry.registerRouteChangeListener(removeListener); - - regOne.unregisterPath(TestContext.class, FOO_PATH); - - RouteChange> fooRemoveEvent = removeListener.event.get(500, TimeUnit.MILLISECONDS); - Set> removal = fooRemoveEvent.getRemovals().get(ROUTING_CONTEXT); - assertNotNull(removal); - AssertCollections.assertContains(removal, FOO_PATH); - AssertCollections.assertNotContains(removal, BAR_PATH); - + @Ignore + public void nonRoutedRegisteredAsRouted() { + final OpendaylightTestRpcServiceService one = Mockito.mock(OpendaylightTestRpcServiceService.class); + try { + final RoutedRpcRegistration reg = rpcRegistry.addRoutedRpcImplementation(OpendaylightTestRpcServiceService.class, one); + reg.registerPath(null, BAR_PATH); + fail("RpcIsNotRoutedException should be thrown"); + } catch (final RpcIsNotRoutedException e) { + assertNotNull(e.getMessage()); + } catch (final Exception e) { + fail("RpcIsNotRoutedException should be thrown"); + } }