Remove blueprint XML from mapping service implementation 75/104175/5
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>
Wed, 25 Jan 2023 09:29:31 +0000 (11:29 +0200)
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>
Thu, 16 Feb 2023 15:58:35 +0000 (17:58 +0200)
Convert it to OSGi DS

Change-Id: I4241b55118aee648e410bece97df8f67373befd1
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
mappingservice/implementation/pom.xml
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/LispMappingService.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingService.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingServiceShell.java
mappingservice/implementation/src/main/resources/OSGI-INF/blueprint/mappingservice.xml [deleted file]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/LispMappingServiceTest.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/lisp/MappingServiceTest.java

index 71721286df82679ac01a77d8b747e86997c1afc6..97901f1aa9253e663dace384713f91fa0be57080 100644 (file)
       <artifactId>mappingservice.inmemorydb</artifactId>
       <scope>test</scope>
     </dependency>
+    <!-- osgi annotations -->
+    <dependency>
+      <groupId>com.guicedee.services</groupId>
+      <artifactId>javax.inject</artifactId>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>jakarta.annotation</groupId>
+      <artifactId>jakarta.annotation-api</artifactId>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.service.component.annotations</artifactId>
+    </dependency>
     <!-- needed for osgi console -->
     <dependency>
       <groupId>org.opendaylight.mdsal</groupId>
index b8ba330f03af125418d422d9f341dc328b5db271..bec9825fe8cb02d4be545f640b6a75bf2d0b3802 100644 (file)
@@ -11,6 +11,9 @@ package org.opendaylight.lispflowmapping.implementation;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.List;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.apache.commons.lang3.tuple.MutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.opendaylight.lispflowmapping.config.ConfigIni;
@@ -27,6 +30,7 @@ import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServic
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier;
 import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
@@ -57,18 +61,24 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.OdlLi
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapReplyInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequestInputBuilder;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
+@Component(service = {IFlowMapping.class, IMapRequestResultHandler.class, IMapNotifyHandler.class},
+        immediate = true, property = "type=default")
 public class LispMappingService implements IFlowMapping, IMapRequestResultHandler,
         IMapNotifyHandler, OdlLispProtoListener, AutoCloseable, ClusterSingletonService {
     private static final String LISPFLOWMAPPING_ENTITY_NAME = "lispflowmapping";
     private static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER = ServiceGroupIdentifier.create(
             LISPFLOWMAPPING_ENTITY_NAME);
 
-
     private static final Logger LOG = LoggerFactory.getLogger(LispMappingService.class);
-    private final ClusterSingletonServiceProvider clusterSingletonService;
 
     private volatile boolean smr = ConfigIni.getInstance().smrIsSet();
     private volatile String elpPolicy = ConfigIni.getInstance().getElpPolicy();
@@ -77,22 +87,39 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
     private ThreadLocal<Pair<MapNotify, List<TransportAddress>>> tlsMapNotify = new ThreadLocal<>();
     private ThreadLocal<Pair<MapRequest, TransportAddress>> tlsMapRequest = new ThreadLocal<>();
 
-    private final OdlLispSbService lispSB;
     private IMapResolverAsync mapResolver;
     private IMapServerAsync mapServer;
 
     private final IMappingService mapService;
+    private final OdlLispSbService lispSB;
+    private final ClusterSingletonServiceProvider clusterSingletonService;
+    private final RpcProviderService rpcProviderService;
     private final NotificationService notificationService;
-
-    public LispMappingService(final NotificationService notificationService,
-            final IMappingService mappingService,
-            final OdlLispSbService odlLispService, final ClusterSingletonServiceProvider clusterSingletonService) {
-
-        this.notificationService = notificationService;
+    private final Registration rpcRegistration;
+    private final Registration listenerRegistration;
+
+    @Inject
+    @Activate
+    public LispMappingService(@Reference final IMappingService mappingService,
+            @Reference final OdlLispSbService odlLispService,
+            @Reference final ClusterSingletonServiceProvider clusterSingletonService,
+            @Reference final RpcProviderService rpcProviderService,
+            @Reference final NotificationService notificationService) {
         this.mapService = mappingService;
         this.lispSB = odlLispService;
         this.clusterSingletonService = clusterSingletonService;
-        LOG.debug("LispMappingService Module constructed!");
+        this.rpcProviderService = rpcProviderService;
+        this.notificationService = notificationService;
+
+        // initialize
+        listenerRegistration = notificationService.registerNotificationListener(this);
+        rpcRegistration = rpcProviderService.registerRpcImplementation(OdlLispSbService.class, lispSB);
+
+        mapResolver = new MapResolver(mapService, smr, elpPolicy, this);
+        mapServer = new MapServer(mapService, smr, this, notificationService);
+        clusterSingletonService.registerClusterSingletonService(this);
+        mapResolver.setSmrNotificationListener((ISmrNotificationListener) mapServer);
+        LOG.info("LISP (RFC6830) Mapping Service initialized");
     }
 
     public boolean shouldUseSmr() {
@@ -115,20 +142,6 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
         return this.notificationService;
     }
 
-    public void initialize() {
-        mapResolver = new MapResolver(mapService, smr, elpPolicy, this);
-        mapServer = new MapServer(mapService, smr, this, notificationService);
-        this.clusterSingletonService.registerClusterSingletonService(this);
-        mapResolver.setSmrNotificationListener((ISmrNotificationListener) mapServer);
-        LOG.info("LISP (RFC6830) Mapping Service init finished");
-    }
-
-    public void basicInit() {
-        mapResolver = new MapResolver(mapService, smr, elpPolicy, this);
-        mapServer = new MapServer(mapService, smr, this, notificationService);
-        mapResolver.setSmrNotificationListener((ISmrNotificationListener) mapServer);
-    }
-
     @Override
     public MapReply handleMapRequest(MapRequest request) {
         if (LOG.isDebugEnabled()) {
@@ -283,10 +296,14 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
         mapServer = null;
     }
 
+    @Deactivate
+    @PreDestroy
     @Override
     public void close() throws Exception {
         destroy();
         clusterSingletonService.close();
+        rpcRegistration.close();
+        listenerRegistration.close();
     }
 
     @Override
@@ -307,3 +324,4 @@ public class LispMappingService implements IFlowMapping, IMapRequestResultHandle
         return SERVICE_GROUP_IDENTIFIER;
     }
 }
+
index c4cf63f579aa16b41668c93cc0cb28d4abdb597b..25f6f13014e9a638d9cc996bd74c656b8ca1ebf2 100644 (file)
@@ -13,6 +13,8 @@ import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
+import javax.annotation.PreDestroy;
+import javax.inject.Singleton;
 import org.opendaylight.lispflowmapping.config.ConfigIni;
 import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
 import org.opendaylight.lispflowmapping.implementation.mdsal.AuthenticationKeyDataListener;
@@ -26,6 +28,7 @@ import org.opendaylight.lispflowmapping.lisp.type.MappingData;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
@@ -90,10 +93,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev15090
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingsOutput;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -108,6 +116,8 @@ import org.slf4j.LoggerFactory;
  * @author Florin Coras
  *
  */
+@Component(service = IMappingService.class, immediate = true, property = "type=default")
+@Singleton
 public class MappingService implements OdlMappingserviceService, IMappingService, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(MappingService.class);
 
@@ -115,27 +125,22 @@ public class MappingService implements OdlMappingserviceService, IMappingService
     private DataStoreBackEnd dsbe;
     private AuthenticationKeyDataListener keyListener;
     private MappingDataListener mappingListener;
-    private final ILispDAO dao;
 
-    private final DataBroker dataBroker;
-    private final NotificationPublishService notificationPublishService;
+    @Reference
+    private volatile ILispDAO dao;
+    @Reference
+    private volatile DataBroker dataBroker;
+    @Reference
+    private volatile RpcProviderService rpcProviderService;
+    @Reference
+    private volatile NotificationPublishService notificationPublishService;
+    private Registration rpcRegistration;
 
     private boolean mappingMergePolicy = ConfigIni.getInstance().mappingMergeIsSet();
     private final boolean notificationPolicy = ConfigIni.getInstance().smrIsSet();
     private final boolean iterateMask = true;
     private boolean isMaster = false;
 
-    public MappingService(final DataBroker broker,
-            final NotificationPublishService notificationPublishService,
-            final ILispDAO lispDAO) {
-        this.dataBroker = broker;
-        this.notificationPublishService = notificationPublishService;
-        this.dao = lispDAO;
-
-        LOG.debug("MappingService created!");
-    }
-
-
     @Override
     public void setMappingMerge(boolean mergeMapping) {
         this.mappingMergePolicy = mergeMapping;
@@ -150,10 +155,13 @@ public class MappingService implements OdlMappingserviceService, IMappingService
         ConfigIni.getInstance().setLookupPolicy(policy);
     }
 
+    @Activate
     public void initialize() {
         LOG.info("Mapping Service initializing...");
         dsbe = new DataStoreBackEnd(dataBroker);
 
+        rpcRegistration = rpcProviderService.registerRpcImplementation(OdlMappingserviceService.class, this);
+
         mappingSystem = new MappingSystem(dao, iterateMask, notificationPublishService, mappingMergePolicy);
         mappingSystem.setDataStoreBackEnd(dsbe);
         mappingSystem.initialize();
@@ -544,9 +552,12 @@ public class MappingService implements OdlMappingserviceService, IMappingService
         return mappingSystem.prettyPrintKeys();
     }
 
+    @PreDestroy
+    @Deactivate
     @Override
     public void close() throws Exception {
         LOG.info("Mapping Service is being destroyed!");
+        rpcRegistration.close();
         keyListener.closeDataChangeListener();
         mappingListener.closeDataChangeListener();
         mappingSystem.destroy();
index 15d680b71c4c301265cee87824f47932ee0768c4..6ac6e21dfc535bf3e49af79023fe39ec0ef2123a 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.lispflowmapping.implementation;
 
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService;
 import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServiceShell;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
@@ -16,6 +18,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.ei
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder;
 import org.opendaylight.yangtools.yang.common.Uint16;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -25,12 +30,16 @@ import org.slf4j.LoggerFactory;
  * @author Lorand Jakab
  *
  */
+@Singleton
+@Component(service = IMappingServiceShell.class, immediate = true, property = "type=default")
 public class MappingServiceShell implements IMappingServiceShell {
     protected static final Logger LOG = LoggerFactory.getLogger(MappingServiceShell.class);
 
     private final IMappingService mappingService;
 
-    public MappingServiceShell(final IMappingService mappingService) {
+    @Inject
+    @Activate
+    public MappingServiceShell(final @Reference IMappingService mappingService) {
         this.mappingService = mappingService;
     }
 
diff --git a/mappingservice/implementation/src/main/resources/OSGI-INF/blueprint/mappingservice.xml b/mappingservice/implementation/src/main/resources/OSGI-INF/blueprint/mappingservice.xml
deleted file mode 100644 (file)
index 22726bc..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-  xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-  odl:use-default-for-reference-types="true">
-
-  <reference id="dataBroker"
-    interface="org.opendaylight.mdsal.binding.api.DataBroker" />
-  <reference id="notificationPublishService"
-    interface="org.opendaylight.mdsal.binding.api.NotificationPublishService" />
-  <reference id="notificationService"
-    interface="org.opendaylight.mdsal.binding.api.NotificationService" />
-  <reference id="lispDAO"
-    interface="org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO" />
-  <reference id="clusterSingletonService"
-             interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider" />
-
-  <odl:rpc-service id="odlLispSbService"
-    interface="org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.OdlLispSbService" />
-
-  <bean id="mappingService"
-    class="org.opendaylight.lispflowmapping.implementation.MappingService"
-    init-method="initialize" destroy-method="close">
-    <argument ref="dataBroker" />
-    <argument ref="notificationPublishService" />
-    <argument ref="lispDAO" />
-  </bean>
-  <service ref="mappingService"
-    interface="org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingService"
-    odl:type="default" />
-  <odl:rpc-implementation ref="mappingService" />
-
-  <bean id="mappingServiceShell"
-    class="org.opendaylight.lispflowmapping.implementation.MappingServiceShell">
-    <argument ref="mappingService" />
-  </bean>
-  <service ref="mappingServiceShell"
-    interface="org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServiceShell"
-    odl:type="default" />
-
-  <bean id="lispMappingService"
-    class="org.opendaylight.lispflowmapping.implementation.LispMappingService"
-    init-method="initialize" destroy-method="close">
-    <argument ref="notificationService" />
-    <argument ref="mappingService" />
-    <argument ref="odlLispSbService" />
-    <argument ref="clusterSingletonService" />
-  </bean>
-  <service ref="lispMappingService"
-    interface="org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping"
-    odl:type="default" />
-  <service ref="lispMappingService"
-    interface="org.opendaylight.lispflowmapping.interfaces.lisp.IMapRequestResultHandler"
-    odl:type="default" />
-  <service ref="lispMappingService"
-    interface="org.opendaylight.lispflowmapping.interfaces.lisp.IMapNotifyHandler"
-    odl:type="default" />
-  <odl:notification-listener ref="lispMappingService" />
-</blueprint>
index c7c5cd7c3f75d6f6c340c82106c756397b79848a..021da330b73fa0f4229bd4fe8e9d486d4a02ef44 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.lispflowmapping.interfaces.mappingservice.IMappingServic
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
 import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary;
@@ -65,6 +66,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendM
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapReplyInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequestInputBuilder;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.Uint16;
 
@@ -76,8 +78,11 @@ public class LispMappingServiceTest {
     @Mock(name = "tlsMapReply") private static ThreadLocal<MapReply> tlsMapReplyMock;
     @Mock(name = "tlsMapNotify") private static ThreadLocal<Pair<MapNotify, List<TransportAddress>>> tlsMapNotifyMock;
     @Mock(name = "tlsMapRequest") private static ThreadLocal<Pair<MapRequest, TransportAddress>> tlsMapRequestMock;
+    @Mock private static Registration rpcRegistration;
+    @Mock(name = "listenerRegistration") private static Registration listenerRegistration;
 
     private final NotificationService notificationService = Mockito.mock(NotificationService.class);
+    private final RpcProviderService rpcProviderService = Mockito.mock(RpcProviderService.class);
     private final IMappingService mappingService = Mockito.mock(IMappingService.class);
     private final OdlLispSbService odlLispSbService = Mockito.mock(OdlLispSbService.class);
     private final ClusterSingletonServiceProvider clusterSingletonService = Mockito.mock(
@@ -85,7 +90,7 @@ public class LispMappingServiceTest {
 
     @InjectMocks
     private final LispMappingService lispMappingService = new LispMappingService(
-            notificationService, mappingService, odlLispSbService, clusterSingletonService);
+            mappingService, odlLispSbService, clusterSingletonService, rpcProviderService, notificationService);
 
     private static final byte[] IPV4_BYTES_1 =       new byte[] {1, 2, 3, 0};
     private static final byte[] IPV4_BYTES_2 =       new byte[] {1, 2, 4, 0};
@@ -339,8 +344,12 @@ public class LispMappingServiceTest {
      */
     @Test
     public void closeTest() throws Exception {
+        setMock("rpcRegistration", rpcRegistration);
+        setMock("listenerRegistration", listenerRegistration);
         lispMappingService.close();
-
+        Mockito.verify(rpcRegistration).close();
+        Mockito.verify(listenerRegistration).close();
+        Mockito.verify(clusterSingletonService).close();
         assertNull(getField("mapResolver"));
         assertNull(getField("mapServer"));
     }
@@ -362,6 +371,13 @@ public class LispMappingServiceTest {
         lispMappingService.onXtrReplyMapping(Mockito.mock(XtrReplyMapping.class));
     }
 
+    private void setMock(final String fieldName, final Object value)
+            throws IllegalAccessException, NoSuchFieldException {
+        final Field field = LispMappingService.class.getDeclaredField(fieldName);
+        field.setAccessible(true);
+        field.set(lispMappingService, value);
+    }
+
     @SuppressWarnings("unchecked")
     private <T> T getField(String fieldName) throws NoSuchFieldException, IllegalAccessException {
         final Field field = LispMappingService.class.getDeclaredField(fieldName);
index af644bd2a98593912a90aaf0a34eaccd7e52ab35..61e08edb1004538ad1f4d4fec303916d61ecf625 100644 (file)
@@ -32,6 +32,7 @@ import org.opendaylight.lispflowmapping.lisp.type.MappingData;
 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId;
@@ -83,6 +84,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev15090
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.UpdateMappingsInput;
+import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
 import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -97,15 +99,16 @@ public class MappingServiceTest {
     @Mock(name = "dsbe") private static DataStoreBackEnd dsbe;
     @Mock(name = "keyListener") private static AuthenticationKeyDataListener keyListener;
     @Mock(name = "mappingListener") private static MappingDataListener mappingListener;
+    @Mock(name = "rpcRegistration") private static Registration rpcRegistration;
 
     private final DataBroker dataBroker = Mockito.mock(DataBroker.class);
+    private final RpcProviderService rpcProviderService = Mockito.mock(RpcProviderService.class);
     private final NotificationPublishService notificationPublishService = Mockito
             .mock(NotificationPublishService.class);
     private final ILispDAO lispDAO = Mockito.mock(ILispDAO.class);
 
     @InjectMocks
-    MappingService mappingService = new MappingService(dataBroker,
-            notificationPublishService, lispDAO);
+    MappingService mappingService = new MappingService();
 
     private static final String IPV4_STRING = "1.2.3.0";
     private static final Eid IPV4_EID = LispAddressUtil.asIpv4Eid(IPV4_STRING);
@@ -520,6 +523,7 @@ public class MappingServiceTest {
     @Test
     public void close() throws Exception {
         mappingService.close();
+        Mockito.verify(rpcRegistration).close();
         Mockito.verify(keyListener).closeDataChangeListener();
         Mockito.verify(mappingListener).closeDataChangeListener();
     }