From 9799dc7bd1c6fde4135147abb8305131d7a1f1a5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 3 Jan 2019 21:31:11 +0100 Subject: [PATCH] Migrate messagebus-impl to MDSAL APIs This removes yet another user of long-deprecated APIs, migrating it over to MD-SAL. Change-Id: I51f2ce0e01ed3078dbd2fa4ad6eb91081d692fa3 Signed-off-by: Robert Varga --- opendaylight/md-sal/messagebus-impl/pom.xml | 29 +----- .../messagebus/app/impl/EventSourceTopic.java | 25 +++--- .../app/impl/EventSourceTopology.java | 70 +++++++-------- .../org/opendaylight/blueprint/messagebus.xml | 8 +- .../impl/EventSourceRegistrationImplTest.java | 2 +- .../app/impl/EventSourceTopicTest.java | 33 ++++--- .../app/impl/EventSourceTopologyTest.java | 89 +++++++++---------- 7 files changed, 108 insertions(+), 148 deletions(-) diff --git a/opendaylight/md-sal/messagebus-impl/pom.xml b/opendaylight/md-sal/messagebus-impl/pom.xml index 56beed9fec..2d0a6f9e76 100644 --- a/opendaylight/md-sal/messagebus-impl/pom.xml +++ b/opendaylight/md-sal/messagebus-impl/pom.xml @@ -26,20 +26,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html - org.opendaylight.controller - sal-binding-api - - - org.opendaylight.controller - sal-core-api - - - org.opendaylight.controller - sal-common-util - - - org.opendaylight.yangtools - yang-data-impl + org.opendaylight.mdsal + mdsal-binding-api org.opendaylight.controller @@ -53,19 +41,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.opendaylight.controller messagebus-spi - - - - org.glassfish.jersey.test-framework.providers - jersey-test-framework-provider-grizzly2 - 2.4 - test - - - org.mockito - mockito-core - test - diff --git a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java index a84f260005..f2ac8d5f44 100644 --- a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java +++ b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopic.java @@ -5,10 +5,8 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.messagebus.app.impl; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; @@ -16,17 +14,18 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import java.util.Collection; import java.util.List; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.ExecutionException; import java.util.regex.Pattern; import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -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.common.api.data.LogicalDatastoreType; +import org.opendaylight.mdsal.binding.api.DataObjectModification; +import org.opendaylight.mdsal.binding.api.DataTreeChangeListener; +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.common.api.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.DisJoinTopicInput; @@ -117,7 +116,7 @@ public final class EventSourceTopic implements DataTreeChangeListener, Aut LOG.debug("Notify existing nodes"); final Pattern nodeRegex = this.nodeIdPattern; - final ReadOnlyTransaction tx = eventSourceTopology.getDataBroker().newReadOnlyTransaction(); + final ReadTransaction tx = eventSourceTopology.getDataBroker().newReadOnlyTransaction(); final ListenableFuture> future = tx.read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH); @@ -171,11 +170,9 @@ public final class EventSourceTopic implements DataTreeChangeListener, Aut } private void registerListner(final EventSourceTopology eventSourceTopology) { - this.listenerRegistration = - eventSourceTopology.getDataBroker().registerDataTreeChangeListener(new DataTreeIdentifier<>( - LogicalDatastoreType.OPERATIONAL, - EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class)), - this); + this.listenerRegistration = eventSourceTopology.getDataBroker().registerDataTreeChangeListener( + DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, + EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class)), this); } @Override diff --git a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java index 50b8e4f459..7f53a53ac6 100644 --- a/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java +++ b/opendaylight/md-sal/messagebus-impl/src/main/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopology.java @@ -5,26 +5,25 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.messagebus.app.impl; import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; +import java.util.Collections; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.messagebus.app.util.Util; import org.opendaylight.controller.messagebus.spi.EventSource; import org.opendaylight.controller.messagebus.spi.EventSourceRegistration; import org.opendaylight.controller.messagebus.spi.EventSourceRegistry; -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.RpcProviderRegistry; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry; +import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicInput; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicOutput; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicOutputBuilder; @@ -41,7 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.even import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.TopologyTypes1Builder; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.topology.event.source.type.TopologyEventSource; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.topology.event.source.type.TopologyEventSourceBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; @@ -50,6 +48,8 @@ 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.NodeKey; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes; +import org.opendaylight.yangtools.concepts.ObjectRegistration; +import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @@ -65,29 +65,26 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR private static final LogicalDatastoreType OPERATIONAL = LogicalDatastoreType.OPERATIONAL; static final InstanceIdentifier EVENT_SOURCE_TOPOLOGY_PATH = - InstanceIdentifier.create(NetworkTopology.class) - .child(Topology.class, EVENT_SOURCE_TOPOLOGY_KEY); + InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, EVENT_SOURCE_TOPOLOGY_KEY); - private static final InstanceIdentifier TOPOLOGY_TYPE_PATH = - EVENT_SOURCE_TOPOLOGY_PATH - .child(TopologyTypes.class) - .augmentation(TopologyTypes1.class); + private static final InstanceIdentifier TOPOLOGY_TYPE_PATH = EVENT_SOURCE_TOPOLOGY_PATH + .child(TopologyTypes.class).augmentation(TopologyTypes1.class); - private final Map eventSourceTopicMap = new ConcurrentHashMap<>(); - private final Map> routedRpcRegistrations = - new ConcurrentHashMap<>(); + private final Map eventSourceTopicMap = new ConcurrentHashMap<>(); + private final Map routedRpcRegistrations = new ConcurrentHashMap<>(); private final DataBroker dataBroker; - private final RpcRegistration aggregatorRpcReg; + private final ObjectRegistration aggregatorRpcReg; private final EventSourceService eventSourceService; - private final RpcProviderRegistry rpcRegistry; + private final RpcProviderService rpcRegistry; - public EventSourceTopology(final DataBroker dataBroker, final RpcProviderRegistry rpcRegistry) { + public EventSourceTopology(final DataBroker dataBroker, final RpcProviderService providerService, + RpcConsumerRegistry rpcService) { this.dataBroker = dataBroker; - this.rpcRegistry = rpcRegistry; - aggregatorRpcReg = rpcRegistry.addRpcImplementation(EventAggregatorService.class, this); - eventSourceService = rpcRegistry.getRpcService(EventSourceService.class); + this.rpcRegistry = providerService; + aggregatorRpcReg = providerService.registerRpcImplementation(EventAggregatorService.class, this); + eventSourceService = rpcService.getRpcService(EventSourceService.class); final TopologyEventSource topologySource = new TopologyEventSourceBuilder().build(); final TopologyTypes1 topologyTypeAugment = @@ -96,15 +93,15 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR LOG.info("EventSourceRegistry has been initialized"); } - private void putData(final LogicalDatastoreType store, + private void putData(final LogicalDatastoreType store, final InstanceIdentifier path, final T data) { final WriteTransaction tx = getDataBroker().newWriteOnlyTransaction(); - tx.put(store, path, data, true); - Futures.addCallback(tx.submit(), new FutureCallback() { + tx.mergeParentStructurePut(store, path, data); + tx.commit().addCallback(new FutureCallback() { @Override - public void onSuccess(final Void result) { + public void onSuccess(final CommitInfo result) { LOG.trace("Data has put into datastore {} {}", store, path); } @@ -119,9 +116,9 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR final InstanceIdentifier path) { final WriteTransaction tx = getDataBroker().newWriteOnlyTransaction(); tx.delete(OPERATIONAL, path); - Futures.addCallback(tx.submit(), new FutureCallback() { + tx.commit().addCallback(new FutureCallback() { @Override - public void onSuccess(final Void result) { + public void onSuccess(final CommitInfo result) { LOG.trace("Data has deleted from datastore {} {}", store, path); } @@ -185,21 +182,18 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR } public void register(final EventSource eventSource) { - final NodeKey nodeKey = eventSource.getSourceNodeKey(); final KeyedInstanceIdentifier sourcePath = EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, nodeKey); - final RoutedRpcRegistration reg = rpcRegistry.addRoutedRpcImplementation( - EventSourceService.class, eventSource); - reg.registerPath(NodeContext.class, sourcePath); - routedRpcRegistrations.put(nodeKey,reg); + final Registration reg = rpcRegistry.registerRpcImplementation(EventSourceService.class, eventSource, + Collections.singleton(sourcePath)); + routedRpcRegistrations.put(nodeKey, reg); insert(sourcePath); - } public void unRegister(final EventSource eventSource) { final NodeKey nodeKey = eventSource.getSourceNodeKey(); final KeyedInstanceIdentifier sourcePath = EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, nodeKey); - final RoutedRpcRegistration removeRegistration = routedRpcRegistrations.remove(nodeKey); + final Registration removeRegistration = routedRpcRegistrations.remove(nodeKey); if (removeRegistration != null) { removeRegistration.close(); remove(sourcePath); @@ -222,7 +216,7 @@ public class EventSourceTopology implements EventAggregatorService, EventSourceR } @VisibleForTesting - Map> getRoutedRpcRegistrations() { + Map getRoutedRpcRegistrations() { return routedRpcRegistrations; } diff --git a/opendaylight/md-sal/messagebus-impl/src/main/resources/org/opendaylight/blueprint/messagebus.xml b/opendaylight/md-sal/messagebus-impl/src/main/resources/org/opendaylight/blueprint/messagebus.xml index b24d6488f3..24a20138aa 100644 --- a/opendaylight/md-sal/messagebus-impl/src/main/resources/org/opendaylight/blueprint/messagebus.xml +++ b/opendaylight/md-sal/messagebus-impl/src/main/resources/org/opendaylight/blueprint/messagebus.xml @@ -10,13 +10,15 @@ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0" odl:use-default-for-reference-types="true"> - - + + + - + + mockDataTreeModification = mock(DataTreeModification.class); DataObjectModification mockModification = mock(DataObjectModification.class); doReturn(mockModification).when(mockDataTreeModification).getRootNode(); - doReturn(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, instanceIdentifierMock)) + doReturn(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifierMock)) .when(mockDataTreeModification).getRootPath(); doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType(); diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java index 8eb46e169c..79a7a558de 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java @@ -8,30 +8,31 @@ package org.opendaylight.controller.messagebus.app.impl; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FluentFuture; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.Set; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.messagebus.spi.EventSource; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.DataTreeIdentifier; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry; +import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicInput; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.DestroyTopicInput; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.DestroyTopicInputBuilder; @@ -40,51 +41,53 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.even import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.Pattern; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.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.NodeKey; import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.concepts.ObjectRegistration; +import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; public class EventSourceTopologyTest { EventSourceTopology eventSourceTopology; DataBroker dataBrokerMock; - RpcProviderRegistry rpcProviderRegistryMock; + RpcProviderService rpcProviderRegistryMock; + RpcConsumerRegistry rpcServiceMock; CreateTopicInput createTopicInputMock; ListenerRegistration listenerRegistrationMock; NodeKey nodeKey; - RpcRegistration aggregatorRpcReg; + ObjectRegistration aggregatorRpcReg; @Before public void setUp() { dataBrokerMock = mock(DataBroker.class); - rpcProviderRegistryMock = mock(RpcProviderRegistry.class); + rpcProviderRegistryMock = mock(RpcProviderService.class); + rpcServiceMock = mock(RpcConsumerRegistry.class); } @Test public void constructorTest() { constructorTestHelper(); - eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock); + eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock, rpcServiceMock); assertNotNull("Instance has not been created correctly.", eventSourceTopology); } private void constructorTestHelper() { - aggregatorRpcReg = mock(RpcRegistration.class); + aggregatorRpcReg = mock(ObjectRegistration.class); EventSourceService eventSourceService = mock(EventSourceService.class); - doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).addRpcImplementation(eq(EventAggregatorService.class), - any(EventSourceTopology.class)); - doReturn(eventSourceService).when(rpcProviderRegistryMock).getRpcService(EventSourceService.class); + doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).registerRpcImplementation( + eq(EventAggregatorService.class), any(EventSourceTopology.class)); + doReturn(eventSourceService).when(rpcServiceMock).getRpcService(EventSourceService.class); WriteTransaction writeTransactionMock = mock(WriteTransaction.class); doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction(); - doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), - any(DataObject.class),eq(true)); - CheckedFuture checkedFutureMock = mock(CheckedFuture.class); - doReturn(checkedFutureMock).when(writeTransactionMock).submit(); + doNothing().when(writeTransactionMock).mergeParentStructurePut(any(LogicalDatastoreType.class), + any(InstanceIdentifier.class), any(DataObject.class)); + FluentFuture checkedFutureMock = mock(FluentFuture.class); + doReturn(checkedFutureMock).when(writeTransactionMock).commit(); } @Test @@ -109,7 +112,7 @@ public class EventSourceTopologyTest { private void topicTestHelper() throws Exception { constructorTestHelper(); createTopicInputMock = mock(CreateTopicInput.class); - eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock); + eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock, rpcServiceMock); NotificationPattern notificationPattern = new NotificationPattern("value1"); doReturn(notificationPattern).when(createTopicInputMock).getNotificationPattern(); @@ -120,18 +123,15 @@ public class EventSourceTopologyTest { doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataTreeChangeListener( any(DataTreeIdentifier.class), any(EventSourceTopic.class)); - ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class); + ReadTransaction readOnlyTransactionMock = mock(ReadTransaction.class); doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction(); - CheckedFuture checkedFutureMock = mock(CheckedFuture.class); + FluentFuture checkedFutureMock = mock(FluentFuture.class); doReturn(checkedFutureMock).when(readOnlyTransactionMock).read(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class)); - Optional optionalMock = mock(Optional.class); - doReturn(optionalMock).when(checkedFutureMock).checkedGet(); - doReturn(true).when(optionalMock).isPresent(); - Topology topologyMock = mock(Topology.class); - doReturn(topologyMock).when(optionalMock).get(); + doReturn(Optional.of(topologyMock)).when(checkedFutureMock).get(); + Node nodeMock = mock(Node.class); List nodeList = new ArrayList<>(); nodeList.add(nodeMock); @@ -164,15 +164,12 @@ public class EventSourceTopologyTest { nodeKey = new NodeKey(nodeId); doReturn(nodeKey).when(nodeMock).key(); doReturn(nodeKey).when(eventSourceMock).getSourceNodeKey(); - BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock( - BindingAwareBroker.RoutedRpcRegistration.class); - doReturn(routedRpcRegistrationMock).when(rpcProviderRegistryMock) - .addRoutedRpcImplementation(EventSourceService.class, eventSourceMock); - doNothing().when(routedRpcRegistrationMock).registerPath(eq(NodeContext.class), - any(KeyedInstanceIdentifier.class)); + ObjectRegistration routedRpcRegistrationMock = mock(ObjectRegistration.class); + doReturn(routedRpcRegistrationMock).when(rpcProviderRegistryMock).registerRpcImplementation( + eq(EventSourceService.class), eq(eventSourceMock), any(Set.class)); eventSourceTopology.register(eventSourceMock); - verify(routedRpcRegistrationMock, times(1)).registerPath(eq(NodeContext.class), - any(KeyedInstanceIdentifier.class)); + verify(rpcProviderRegistryMock, times(1)).registerRpcImplementation(eq(EventSourceService.class), + eq(eventSourceMock), any(Set.class)); } @Test @@ -181,8 +178,7 @@ public class EventSourceTopologyTest { EventSource eventSourceMock = mock(EventSource.class); NodeId nodeId = new NodeId("nodeIdValue1"); nodeKey = new NodeKey(nodeId); - Map> localMap = eventSourceTopology - .getRoutedRpcRegistrations(); + Map localMap = eventSourceTopology.getRoutedRpcRegistrations(); NodeKey nodeKeyMock = mock(NodeKey.class); doReturn(nodeKeyMock).when(eventSourceMock).getSourceNodeKey(); BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = @@ -201,12 +197,9 @@ public class EventSourceTopologyTest { nodeKey = new NodeKey(nodeId); doReturn(nodeKey).when(nodeMock).key(); doReturn(nodeKey).when(eventSourceMock).getSourceNodeKey(); - BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock( - BindingAwareBroker.RoutedRpcRegistration.class); + ObjectRegistration routedRpcRegistrationMock = mock(ObjectRegistration.class); doReturn(routedRpcRegistrationMock).when(rpcProviderRegistryMock) - .addRoutedRpcImplementation(EventSourceService.class, eventSourceMock); - doNothing().when(routedRpcRegistrationMock).registerPath(eq(NodeContext.class), - any(KeyedInstanceIdentifier.class)); + .registerRpcImplementation(eq(EventSourceService.class), eq(eventSourceMock), any(Set.class)); assertNotNull("Return value has not been created correctly.", eventSourceTopology.registerEventSource(eventSourceMock)); } -- 2.36.6