X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-topology-singleton%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Ftopology%2Fsingleton%2Fimpl%2FMountPointEndToEndTest.java;h=be2e580ff1602a523135f46a0e00abf2e890ab1d;hb=52caea7f0226b11307aee7983b721124d2e8d25f;hp=45cfd3090e1d5ea7b6dcdc1e3fcae6fb1565df9c;hpb=50728314406a58d5b6958339f09b86160c06e674;p=netconf.git diff --git a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/MountPointEndToEndTest.java b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/MountPointEndToEndTest.java index 45cfd3090e..be2e580ff1 100644 --- a/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/MountPointEndToEndTest.java +++ b/netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/MountPointEndToEndTest.java @@ -14,7 +14,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; @@ -26,10 +26,9 @@ import static org.mockito.MockitoAnnotations.initMocks; import akka.actor.ActorSystem; import akka.testkit.javadsl.TestKit; import akka.util.Timeout; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; @@ -44,6 +43,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.Map.Entry; +import java.util.Optional; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -56,43 +57,45 @@ import org.opendaylight.aaa.encrypt.AAAEncryptionService; import org.opendaylight.controller.cluster.ActorSystemProvider; import org.opendaylight.controller.config.threadpool.ScheduledThreadPool; import org.opendaylight.controller.config.threadpool.ThreadPool; -import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; -import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionChain; -import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; -import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; -import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcException; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; -import org.opendaylight.controller.md.sal.dom.api.DOMService; -import org.opendaylight.controller.md.sal.dom.broker.impl.DOMRpcRouter; -import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl; -import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.DataObjectModification; +import org.opendaylight.mdsal.binding.api.DataTreeIdentifier; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.binding.api.Transaction; +import org.opendaylight.mdsal.binding.api.TransactionChain; +import org.opendaylight.mdsal.binding.api.TransactionChainListener; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.api.DOMActionProviderService; +import org.opendaylight.mdsal.dom.api.DOMActionService; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.mdsal.dom.api.DOMDataTreeReadOperations; +import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction; +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.DOMRpcIdentifier; +import org.opendaylight.mdsal.dom.api.DOMRpcImplementation; +import org.opendaylight.mdsal.dom.api.DOMRpcProviderService; +import org.opendaylight.mdsal.dom.api.DOMRpcResult; +import org.opendaylight.mdsal.dom.api.DOMRpcService; +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.eos.dom.simple.SimpleDOMEntityOwnershipService; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier; import org.opendaylight.mdsal.singleton.dom.impl.DOMClusterSingletonServiceProviderImpl; import org.opendaylight.netconf.client.NetconfClientDispatcher; +import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory; import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences; import org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException; import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup; @@ -121,9 +124,9 @@ 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.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; -import org.opendaylight.yangtools.yang.binding.util.BindingReflections; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcError.ErrorType; @@ -151,7 +154,7 @@ import org.slf4j.LoggerFactory; * @author Thomas Pantelis */ public class MountPointEndToEndTest { - private static Logger LOG = LoggerFactory.getLogger(MountPointEndToEndTest.class); + private static final Logger LOG = LoggerFactory.getLogger(MountPointEndToEndTest.class); private static final String TOP_MODULE_NAME = "opendaylight-mdsal-list-test"; private static final String ACTOR_SYSTEM_NAME = "test"; @@ -160,11 +163,13 @@ public class MountPointEndToEndTest { private static final InstanceIdentifier NODE_INSTANCE_ID = NetconfTopologyUtils.createTopologyNodeListPath( new NodeKey(NODE_ID), TOPOLOGY_ID); - @Mock private RpcProviderRegistry mockRpcProviderRegistry; + @Mock private DOMRpcProviderService mockRpcProviderRegistry; + @Mock private DOMActionProviderService mockActionProviderRegistry; @Mock private NetconfClientDispatcher mockClientDispatcher; @Mock private AAAEncryptionService mockEncryptionService; @Mock private ThreadPool mockThreadPool; @Mock private ScheduledThreadPool mockKeepaliveExecutor; + @Mock private DeviceActionFactory deviceActionFactory; @Mock private ActorSystemProvider mockMasterActorSystemProvider; @Mock private DOMMountPointListener masterMountPointListener; @@ -186,7 +191,7 @@ public class MountPointEndToEndTest { private ActorSystem slaveSystem; private NetconfTopologyManager slaveNetconfTopologyManager; private final SettableFuture slaveNetconfTopologyContextFuture = SettableFuture.create(); - private BindingTransactionChain slaveTxChain; + private TransactionChain slaveTxChain; private final EventExecutor eventExecutor = GlobalEventExecutor.INSTANCE; private final Config config = new ConfigBuilder().setWriteTransactionIdleTimeout(0).build(); @@ -216,7 +221,7 @@ public class MountPointEndToEndTest { putTopRpcSchemaPath = findRpcDefinition("put-top").getPath(); getTopRpcSchemaPath = findRpcDefinition("get-top").getPath(); - deviceRpcService.registerRpcImplementation(topRpcImplementation, + deviceRpcService.getRpcProviderService().registerRpcImplementation(topRpcImplementation, DOMRpcIdentifier.create(putTopRpcSchemaPath), DOMRpcIdentifier.create(getTopRpcSchemaPath)); setupMaster(); @@ -265,14 +270,16 @@ public class MountPointEndToEndTest { topModuleInfo.getName().getRevision()), YangTextSchemaSource.class, 1)); masterNetconfTopologyManager = new NetconfTopologyManager(masterDataBroker, mockRpcProviderRegistry, - masterClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool, + mockActionProviderRegistry, masterClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool, mockMasterActorSystemProvider, eventExecutor, mockClientDispatcher, TOPOLOGY_ID, config, - masterMountPointService, mockEncryptionService) { + masterMountPointService, mockEncryptionService, deviceActionFactory) { @Override protected NetconfTopologyContext newNetconfTopologyContext(final NetconfTopologySetup setup, - final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime) { + final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime, + final DeviceActionFactory deviceActionFact) { NetconfTopologyContext context = - super.newNetconfTopologyContext(setup, serviceGroupIdent, actorResponseWaitTime); + super.newNetconfTopologyContext(setup, serviceGroupIdent, actorResponseWaitTime, deviceActionFact); + NetconfTopologyContext spiedContext = spy(context); doAnswer(invocation -> { final MasterSalFacade spiedFacade = (MasterSalFacade) spy(invocation.callRealMethod()); @@ -302,14 +309,16 @@ public class MountPointEndToEndTest { .registerClusterSingletonService(any()); slaveNetconfTopologyManager = new NetconfTopologyManager(slaveDataBroker, mockRpcProviderRegistry, - mockSlaveClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool, + mockActionProviderRegistry, mockSlaveClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool, mockSlaveActorSystemProvider, eventExecutor, mockClientDispatcher, TOPOLOGY_ID, config, - slaveMountPointService, mockEncryptionService) { + slaveMountPointService, mockEncryptionService, deviceActionFactory) { @Override protected NetconfTopologyContext newNetconfTopologyContext(final NetconfTopologySetup setup, - final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime) { - NetconfTopologyContext spiedContext = - spy(super.newNetconfTopologyContext(setup, serviceGroupIdent, actorResponseWaitTime)); + final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime, + final DeviceActionFactory actionFactory) { + NetconfTopologyContext spiedContext = spy(super.newNetconfTopologyContext(setup, serviceGroupIdent, + actorResponseWaitTime, actionFactory)); + slaveNetconfTopologyContextFuture.set(spiedContext); return spiedContext; } @@ -321,12 +330,12 @@ public class MountPointEndToEndTest { slaveTxChain = slaveDataBroker.createTransactionChain(new TransactionChainListener() { @Override - public void onTransactionChainSuccessful(final TransactionChain chain) { + public void onTransactionChainSuccessful(final TransactionChain chain) { } @Override - public void onTransactionChainFailed(final TransactionChain chain, - final AsyncTransaction transaction, final Throwable cause) { + public void onTransactionChainFailed(final TransactionChain chain, final Transaction transaction, + final Throwable cause) { LOG.error("Slave transaction chain failed", cause); } }); @@ -353,7 +362,7 @@ public class MountPointEndToEndTest { final MasterSalFacade masterSalFacade = masterSalFacadeFuture.get(5, TimeUnit.SECONDS); masterSalFacade.onDeviceConnected(deviceSchemaContext, - NetconfSessionPreferences.fromStrings(Collections.emptyList()), deviceRpcService); + NetconfSessionPreferences.fromStrings(Collections.emptyList()), deviceRpcService.getRpcService()); DOMMountPoint masterMountPoint = awaitMountPoint(masterMountPointService); @@ -378,7 +387,7 @@ public class MountPointEndToEndTest { // This is essentially what happens in a clustered environment but we'll use a DTCL here. masterDataBroker.registerDataTreeChangeListener( - new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, NODE_INSTANCE_ID), changes -> { + DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, NODE_INSTANCE_ID), changes -> { final WriteTransaction slaveTx = slaveTxChain.newWriteOnlyTransaction(); for (DataTreeModification dataTreeModification : changes) { DataObjectModification rootNode = dataTreeModification.getRootNode(); @@ -428,7 +437,7 @@ public class MountPointEndToEndTest { MasterSalFacade masterSalFacade = masterSalFacadeFuture.get(5, TimeUnit.SECONDS); masterSalFacade.onDeviceConnected(deviceSchemaContext, - NetconfSessionPreferences.fromStrings(Collections.emptyList()), deviceRpcService); + NetconfSessionPreferences.fromStrings(Collections.emptyList()), deviceRpcService.getRpcService()); verify(masterMountPointListener, timeout(5000)).onMountPointCreated(yangNodeInstanceId); @@ -447,7 +456,7 @@ public class MountPointEndToEndTest { awaitMountPointNotPresent(masterMountPointService); await().atMost(5, TimeUnit.SECONDS).until(() -> { - try (ReadOnlyTransaction readTx = masterDataBroker.newReadOnlyTransaction()) { + try (ReadTransaction readTx = masterDataBroker.newReadOnlyTransaction()) { Optional node = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_INSTANCE_ID).get(5, TimeUnit.SECONDS); assertTrue(node.isPresent()); @@ -497,7 +506,9 @@ public class MountPointEndToEndTest { private void testRpc(final DOMRpcService domRpcService, final SchemaPath schemaPath, final NormalizedNode input, final DOMRpcResult result) throws InterruptedException, ExecutionException, TimeoutException { - final DOMRpcResult actual = invokeRpc(domRpcService, schemaPath, input, Futures.immediateCheckedFuture(result)); + final FluentFuture future = result == null ? FluentFutures.immediateNullFluentFuture() + : FluentFutures.immediateFluentFuture(result); + final DOMRpcResult actual = invokeRpc(domRpcService, schemaPath, input, future); if (result == null) { assertNull(actual); return; @@ -507,8 +518,8 @@ public class MountPointEndToEndTest { assertEquals(result.getResult(), actual.getResult()); assertEquals(result.getErrors().size(), actual.getErrors().size()); - Iterator iter1 = result.getErrors().iterator(); - Iterator iter2 = actual.getErrors().iterator(); + Iterator iter1 = result.getErrors().iterator(); + Iterator iter2 = actual.getErrors().iterator(); while (iter1.hasNext() && iter2.hasNext()) { RpcError err1 = iter1.next(); RpcError err2 = iter2.next(); @@ -524,7 +535,7 @@ public class MountPointEndToEndTest { private void testFailedRpc(final DOMRpcService domRpcService, final SchemaPath schemaPath, final NormalizedNode input) throws InterruptedException, TimeoutException { try { - invokeRpc(domRpcService, schemaPath, input, Futures.immediateFailedCheckedFuture( + invokeRpc(domRpcService, schemaPath, input, FluentFutures.immediateFailedFluentFuture( new ClusteringRpcException("mock"))); fail("Expected exception"); } catch (ExecutionException e) { @@ -534,7 +545,7 @@ public class MountPointEndToEndTest { } private DOMRpcResult invokeRpc(final DOMRpcService domRpcService, final SchemaPath schemaPath, - final NormalizedNode input, final CheckedFuture returnFuture) + final NormalizedNode input, final FluentFuture returnFuture) throws InterruptedException, ExecutionException, TimeoutException { topRpcImplementation.init(returnFuture); final ListenableFuture resultFuture = domRpcService.invokeRpc(schemaPath, input); @@ -547,7 +558,7 @@ public class MountPointEndToEndTest { private static void testDOMDataBrokerOperations(final DOMDataBroker dataBroker) throws InterruptedException, ExecutionException, TimeoutException { - DOMDataWriteTransaction writeTx = dataBroker.newWriteOnlyTransaction(); + DOMDataTreeWriteTransaction writeTx = dataBroker.newWriteOnlyTransaction(); final ContainerNode topNode = Builders.containerBuilder() .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(Top.QNAME)).build(); @@ -569,7 +580,7 @@ public class MountPointEndToEndTest { writeTx.delete(LogicalDatastoreType.CONFIGURATION, topPath); writeTx.commit().get(5, TimeUnit.SECONDS); - DOMDataReadWriteTransaction readTx = dataBroker.newReadWriteTransaction(); + DOMDataTreeReadWriteTransaction readTx = dataBroker.newReadWriteTransaction(); assertFalse(readTx.exists(LogicalDatastoreType.CONFIGURATION, topPath).get(5, TimeUnit.SECONDS)); assertTrue(readTx.cancel()); } @@ -597,7 +608,7 @@ public class MountPointEndToEndTest { writeTx.commit().get(5, TimeUnit.SECONDS); } - private static void verifyDataInStore(final DOMDataReadTransaction readTx, final YangInstanceIdentifier path, + private static void verifyDataInStore(final DOMDataTreeReadOperations readTx, final YangInstanceIdentifier path, final NormalizedNode expNode) throws InterruptedException, ExecutionException, TimeoutException { final Optional> read = readTx.read(LogicalDatastoreType.CONFIGURATION, path) .get(5, TimeUnit.SECONDS); @@ -610,7 +621,7 @@ public class MountPointEndToEndTest { private static void verifyTopologyNodesCreated(final DataBroker dataBroker) { await().atMost(5, TimeUnit.SECONDS).until(() -> { - try (ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) { + try (ReadTransaction readTx = dataBroker.newReadOnlyTransaction()) { Optional configTopology = readTx.read(LogicalDatastoreType.CONFIGURATION, NetconfTopologyUtils.createTopologyListPath(TOPOLOGY_ID)).get(3, TimeUnit.SECONDS); Optional operTopology = readTx.read(LogicalDatastoreType.OPERATIONAL, @@ -623,7 +634,7 @@ public class MountPointEndToEndTest { private AbstractConcurrentDataBrokerTest newDataBrokerTest() throws Exception { AbstractConcurrentDataBrokerTest dataBrokerTest = new AbstractConcurrentDataBrokerTest(true) { @Override - protected Iterable getModuleInfos() throws Exception { + protected Set getModuleInfos() throws Exception { return ImmutableSet.of(BindingReflections.getModuleInfo(NetconfNode.class), BindingReflections.getModuleInfo(NetworkTopology.class), BindingReflections.getModuleInfo(Topology.class), @@ -649,6 +660,10 @@ public class MountPointEndToEndTest { return getMountPointService(mountPoint, DOMRpcService.class); } + private static DOMActionService getDomActionService(final DOMMountPoint mountPoint) { + return getMountPointService(mountPoint, DOMActionService.class); + } + private static T getMountPointService(final DOMMountPoint mountPoint, final Class serviceClass) { final Optional maybeService = mountPoint.getService(serviceClass); @@ -657,9 +672,8 @@ public class MountPointEndToEndTest { } private DOMMountPoint awaitMountPoint(final DOMMountPointService mountPointService) { - await().atMost(5, TimeUnit.SECONDS).until(() -> { - return mountPointService.getMountPoint(yangNodeInstanceId).isPresent(); - }); + await().atMost(5, TimeUnit.SECONDS).until(() -> + mountPointService.getMountPoint(yangNodeInstanceId).isPresent()); return mountPointService.getMountPoint(yangNodeInstanceId).get(); } @@ -680,16 +694,16 @@ public class MountPointEndToEndTest { private static class TopDOMRpcImplementation implements DOMRpcImplementation { private volatile SettableFuture>> rpcInvokedFuture; - private volatile CheckedFuture returnFuture; + private volatile FluentFuture returnFuture; @Override - public CheckedFuture invokeRpc(final DOMRpcIdentifier rpc, + public FluentFuture invokeRpc(final DOMRpcIdentifier rpc, final NormalizedNode input) { rpcInvokedFuture.set(new SimpleEntry<>(rpc, input)); return returnFuture; } - void init(final CheckedFuture retFuture) { + void init(final FluentFuture retFuture) { this.returnFuture = retFuture; rpcInvokedFuture = SettableFuture.create(); }