Bump upstreams
[netconf.git] / netconf / netconf-topology-singleton / src / test / java / org / opendaylight / netconf / topology / singleton / impl / MountPointEndToEndTest.java
index ba474efedafd16156165fd5c116d6235f36ccb35..7528e06079792cac026dab8c6538dcf363b17cc0 100644 (file)
@@ -82,6 +82,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
 import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener;
 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
@@ -91,6 +92,7 @@ import org.opendaylight.mdsal.dom.api.DOMService;
 import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
 import org.opendaylight.mdsal.dom.broker.DOMRpcRouter;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
@@ -98,6 +100,8 @@ import org.opendaylight.mdsal.singleton.dom.impl.DOMClusterSingletonServiceProvi
 import org.opendaylight.netconf.client.NetconfClientDispatcher;
 import org.opendaylight.netconf.nettyutil.ReconnectFuture;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
 import org.opendaylight.netconf.sal.connect.api.SchemaResourceManager;
 import org.opendaylight.netconf.sal.connect.impl.DefaultSchemaResourceManager;
 import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema;
@@ -133,6 +137,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
 import org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
@@ -195,12 +200,14 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
     @Mock private ActorSystemProvider mockMasterActorSystemProvider;
     @Mock private DOMMountPointListener masterMountPointListener;
     private final DOMMountPointService masterMountPointService = new DOMMountPointServiceImpl();
-    private final DOMRpcRouter deviceRpcService = new DOMRpcRouter();
+    private Rpcs.Normalized deviceRpcService;
+
     private DOMClusterSingletonServiceProviderImpl masterClusterSingletonServiceProvider;
     private DataBroker masterDataBroker;
     private DOMDataBroker deviceDOMDataBroker;
     private ActorSystem masterSystem;
     private NetconfTopologyManager masterNetconfTopologyManager;
+
     private volatile SettableFuture<MasterSalFacade> masterSalFacadeFuture = SettableFuture.create();
 
     @Mock private ActorSystemProvider mockSlaveActorSystemProvider;
@@ -238,14 +245,28 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
 
         deviceSchemaContext = BindingRuntimeHelpers.createEffectiveModel(Top.class);
 
-        deviceRpcService.onModelContextUpdated(deviceSchemaContext);
+        final var router = new DOMRpcRouter(FixedDOMSchemaService.of(deviceSchemaContext));
 
         putTopRpcSchemaPath = findRpcDefinition("put-top").getQName();
         getTopRpcSchemaPath = findRpcDefinition("get-top").getQName();
 
-        deviceRpcService.getRpcProviderService().registerRpcImplementation(topRpcImplementation,
+        router.getRpcProviderService().registerRpcImplementation(topRpcImplementation,
                 DOMRpcIdentifier.create(putTopRpcSchemaPath), DOMRpcIdentifier.create(getTopRpcSchemaPath));
 
+        final var rpcService = router.getRpcService();
+        deviceRpcService = new Rpcs.Normalized() {
+            @Override
+            public ListenableFuture<? extends DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
+                return rpcService.invokeRpc(type, input);
+            }
+
+            @Override
+            public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(
+                    final T listener) {
+                return rpcService.registerRpcListener(listener);
+            }
+        };
+
         setupMaster();
 
         setupSlave();
@@ -389,7 +410,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
             new EmptyMountPointContext(deviceSchemaContext)),
             NetconfSessionPreferences.fromStrings(
                 List.of(NetconfMessageTransformUtil.NETCONF_CANDIDATE_URI.toString())),
-            deviceRpcService.getRpcService());
+            new RemoteDeviceServices(deviceRpcService, null));
 
         final var masterMountPoint = awaitMountPoint(masterMountPointService);
 
@@ -465,7 +486,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         masterSalFacade.onDeviceConnected(new NetconfDeviceSchema(NetconfDeviceCapabilities.empty(),
             new EmptyMountPointContext(deviceSchemaContext)), NetconfSessionPreferences.fromStrings(List.of(
                     NetconfMessageTransformUtil.NETCONF_CANDIDATE_URI.toString())),
-                deviceRpcService.getRpcService());
+                new RemoteDeviceServices(deviceRpcService, null));
 
         verify(masterMountPointListener, timeout(5000)).onMountPointCreated(yangNodeInstanceId);
 
@@ -504,7 +525,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
 
     private void testDOMRpcService(final DOMRpcService domRpcService)
             throws InterruptedException, ExecutionException, TimeoutException {
-        testPutTopRpc(domRpcService, new DefaultDOMRpcResult((NormalizedNode)null));
+        testPutTopRpc(domRpcService, new DefaultDOMRpcResult((ContainerNode)null));
         testPutTopRpc(domRpcService, null);
         testPutTopRpc(domRpcService, new DefaultDOMRpcResult(ImmutableList.of(
                 RpcResultBuilder.newError(ErrorType.APPLICATION, new ErrorTag("tag1"), "error1"),
@@ -533,7 +554,7 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         testRpc(domRpcService, getTopRpcSchemaPath, getTopInput, result);
     }
 
-    private void testRpc(final DOMRpcService domRpcService, final QName qname, final NormalizedNode input,
+    private void testRpc(final DOMRpcService domRpcService, final QName qname, final ContainerNode input,
             final DOMRpcResult result) throws InterruptedException, ExecutionException, TimeoutException {
         final FluentFuture<DOMRpcResult> future = result == null ? FluentFutures.immediateNullFluentFuture()
                 : FluentFutures.immediateFluentFuture(result);
@@ -544,11 +565,11 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         }
 
         assertNotNull(actual);
-        assertEquals(result.getResult(), actual.getResult());
+        assertEquals(result.value(), actual.value());
 
-        assertEquals(result.getErrors().size(), actual.getErrors().size());
-        Iterator<? extends RpcError> iter1 = result.getErrors().iterator();
-        Iterator<? extends RpcError> iter2 = actual.getErrors().iterator();
+        assertEquals(result.errors().size(), actual.errors().size());
+        Iterator<? extends RpcError> iter1 = result.errors().iterator();
+        Iterator<? extends RpcError> iter2 = actual.errors().iterator();
         while (iter1.hasNext() && iter2.hasNext()) {
             RpcError err1 = iter1.next();
             RpcError err2 = iter2.next();
@@ -561,11 +582,10 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         }
     }
 
-    private void testFailedRpc(final DOMRpcService domRpcService, final QName qname, final NormalizedNode input)
+    private void testFailedRpc(final DOMRpcService domRpcService, final QName qname, final ContainerNode input)
             throws InterruptedException, TimeoutException {
         try {
-            invokeRpc(domRpcService, qname, input, FluentFutures.immediateFailedFluentFuture(
-                    new ClusteringRpcException("mock")));
+            invokeRpc(domRpcService, qname, input, Futures.immediateFailedFuture(new ClusteringRpcException("mock")));
             fail("Expected exception");
         } catch (ExecutionException e) {
             assertTrue(e.getCause() instanceof ClusteringRpcException);
@@ -573,8 +593,8 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
         }
     }
 
-    private DOMRpcResult invokeRpc(final DOMRpcService domRpcService, final QName qname, final NormalizedNode input,
-            final FluentFuture<DOMRpcResult> returnFuture)
+    private DOMRpcResult invokeRpc(final DOMRpcService domRpcService, final QName qname, final ContainerNode input,
+            final ListenableFuture<DOMRpcResult> returnFuture)
                 throws InterruptedException, ExecutionException, TimeoutException {
         topRpcImplementation.init(returnFuture);
         final ListenableFuture<? extends DOMRpcResult> resultFuture = domRpcService.invokeRpc(qname, input);
@@ -728,15 +748,15 @@ public class MountPointEndToEndTest extends AbstractBaseSchemasTest {
 
     private static class TopDOMRpcImplementation implements DOMRpcImplementation {
         private volatile SettableFuture<Entry<DOMRpcIdentifier, NormalizedNode>> rpcInvokedFuture;
-        private volatile FluentFuture<DOMRpcResult> returnFuture;
+        private volatile ListenableFuture<DOMRpcResult> returnFuture;
 
         @Override
-        public FluentFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final NormalizedNode input) {
+        public ListenableFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc, final ContainerNode input) {
             rpcInvokedFuture.set(Map.entry(rpc, input));
             return returnFuture;
         }
 
-        void init(final FluentFuture<DOMRpcResult> retFuture) {
+        void init(final ListenableFuture<DOMRpcResult> retFuture) {
             returnFuture = retFuture;
             rpcInvokedFuture = SettableFuture.create();
         }