Bug 5596 - restart devices management improvement 80/44480/1
authorJozef Bacigal <jozef.bacigal@pantheon.tech>
Thu, 11 Aug 2016 10:54:43 +0000 (12:54 +0200)
committerJozef Bacigal <jozef.bacigal@pantheon.tech>
Mon, 22 Aug 2016 12:11:09 +0000 (14:11 +0200)
Change-Id: I61b384062e780eec342d7b7eb0ffa05bc0f6c7de
Signed-off-by: Jozef Bacigal <jozef.bacigal@pantheon.tech>
17 files changed:
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OFPContext.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/connection/ConnectionContext.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManager.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/registry/flow/DeviceFlowRegistryImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java

index 0840568efb23f2d88d3b6aa015e42d9b2783adea..c16d5fafb6b16fd97d6f0a728d473f7332ce4ba0 100644 (file)
@@ -48,8 +48,9 @@ public interface OFPContext {
     /**
      * About to stop services in cluster not master anymore or going down
      * @return Future most of services need time to be closed
+     * @param deviceDisconnected
      */
-    default ListenableFuture<Void> stopClusterServices(){
+    default ListenableFuture<Void> stopClusterServices(final boolean deviceDisconnected){
         return Futures.immediateFailedFuture(new RejectedExecutionException("Cannot stop abstract services, check implementation of cluster services"));
     }
 
index 88e1c9174f379e9f9b63dbb74cd2650afcc4a073..4e91673d086166389548f1adc63cb222788083fa 100644 (file)
@@ -106,6 +106,8 @@ public interface ConnectionContext {
      */
     void setDeviceDisconnectedHandler(DeviceDisconnectedHandler deviceDisconnectedHandler);
 
+    String getSafeNodeIdForLOG();
+
     void setOutboundQueueHandleRegistration(OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration);
 
     /**
@@ -139,7 +141,7 @@ public interface ConnectionContext {
 
     /**
      * Create and return basic device info
-     * @return
+     * @return created device info
      */
     DeviceInfo getDeviceInfo();
 
index 30eccf1db3b0049e81f8774239b20144ee598eab..986bbb178e4fae8ecac206b4c1c4c5095601a1c9 100644 (file)
@@ -162,12 +162,14 @@ public class ConnectionContextImpl implements ConnectionContext {
 
     @Override
     public void onConnectionClosed() {
+
+        connectionState = ConnectionContext.CONNECTION_STATE.RIP;
+
         if (null == nodeId){
             SessionStatistics.countEvent(connectionAdapter.getRemoteAddress().toString(), SessionStatistics.ConnectionStatus.CONNECTION_DISCONNECTED_BY_DEVICE);
         } else {
             SessionStatistics.countEvent(nodeId.toString(), SessionStatistics.ConnectionStatus.CONNECTION_DISCONNECTED_BY_DEVICE);
         }
-        connectionState = ConnectionContext.CONNECTION_STATE.RIP;
 
         final InetSocketAddress remoteAddress = connectionAdapter.getRemoteAddress();
         final Short auxiliaryId;
@@ -200,7 +202,8 @@ public class ConnectionContextImpl implements ConnectionContext {
      * This method returns safe nodeId for logging
      * @return string value od nodeId or string "null"
      */
-    private String getSafeNodeIdForLOG() {
+    @Override
+    public String getSafeNodeIdForLOG() {
         return null == nodeId ? "null" : nodeId.getValue();
     }
 
index 1bf37f17825be7b3456f2030a921f197ab4f1513..1d5263a8a7af15d1f55d1f09f7425ea4fde43bcf 100644 (file)
@@ -51,7 +51,7 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
     @Override
     public void onDisconnectEvent(final DisconnectEvent notification) {
         LOG.info("ConnectionEvent: Connection closed by device, Device:{}, NodeId:{}",
-                connectionContext.getConnectionAdapter().getRemoteAddress(), connectionContext.getNodeId());
+                connectionContext.getConnectionAdapter().getRemoteAddress(), connectionContext.getSafeNodeIdForLOG());
         connectionContext.onConnectionClosed();
     }
 
@@ -98,7 +98,7 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
         if (shouldBeDisconnected) {
             if (LOG.isInfoEnabled()) {
                 LOG.info("ConnectionEvent:Closing connection as device is idle. Echo sent at {}. Device:{}, NodeId:{}",
-                        new Date(System.currentTimeMillis() - echoReplyTimeout), remoteAddress, connectionContext.getNodeId());
+                        new Date(System.currentTimeMillis() - echoReplyTimeout), remoteAddress, connectionContext.getSafeNodeIdForLOG());
             }
 
             connectionContext.closeConnection(true);
index 558f44cfb57a25e8db25512625f330fcd8e9e129..96acf077a969620cd8ccaeef7d571fdc33f3a83c 100644 (file)
@@ -545,7 +545,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     }
 
     @Override
-    public ListenableFuture<Void> stopClusterServices() {
+    public ListenableFuture<Void> stopClusterServices(boolean deviceDisconnected) {
         return this.transactionChainManager.deactivateTransactionManager();
     }
 
index 35c372b332fab7a85a1136d1e140016f19265d57..a3ed4479c6245f134c380c9ebae4cb60c5a30323 100644 (file)
@@ -260,11 +260,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     @Override
     public void onDeviceContextLevelDown(final DeviceInfo deviceInfo) {
 
-        deviceContexts.remove(deviceInfo);
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Device context removed for node {}", deviceInfo.getLOGValue());
-        }
-
         LifecycleService lifecycleService = lifecycleServices.remove(deviceInfo);
         if (LOG.isDebugEnabled()) {
             LOG.debug("Lifecycle service removed for node {}", deviceInfo.getLOGValue());
@@ -279,6 +274,12 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                 LOG.warn("Closing lifecycle service for node {} was unsuccessful ", deviceInfo.getLOGValue(), e);
             }
         }
+
+        deviceContexts.remove(deviceInfo);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Device context removed for node {}", deviceInfo.getLOGValue());
+        }
+
     }
 
     @Override
index 7ccdc42824ccb132454e54f60500ff5de2cae776..dcb7f70bbb8ca2237745298d22667f81cc0de3a2 100644 (file)
@@ -276,7 +276,7 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
     }
 
     ListenableFuture<Void> shuttingDown() {
-        LOG.debug("TxManager is going SHUTTING_DOWN for node {}", nodeII);
+        LOG.debug("TxManager is going SHUTTING_DOWN for node {}", nodeII.getKey().getId().getValue());
         ListenableFuture<Void> future;
         synchronized (txLock) {
             this.transactionChainManagerStatus = TransactionChainManagerStatus.SHUTTING_DOWN;
index d5e024a90586f4e1851856e6809fb9f7197dc5af..729a3d8718defb60a2a01985ed0e8c3da2766b9a 100644 (file)
@@ -45,8 +45,7 @@ public class LifecycleServiceImpl implements LifecycleService {
         try {
 
             if (LOG.isDebugEnabled()) {
-                LOG.debug("Starting clustering MASTER services for node {}", this.deviceContext.getDeviceInfo().getLOGValue());
-                LOG.debug("===============================================");
+                LOG.debug("========== Starting clustering MASTER services for node {} ==========", this.deviceContext.getDeviceInfo().getLOGValue());
             }
 
             if (connectionInterrupted()) {
@@ -108,21 +107,26 @@ public class LifecycleServiceImpl implements LifecycleService {
     @Override
     public ListenableFuture<Void> closeServiceInstance() {
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Stopping clustering MASTER services for node {}", this.deviceContext.getDeviceInfo().getLOGValue());
-            LOG.debug("===============================================");
+            LOG.debug("========== Stopping clustering MASTER services for node {} ==========", this.deviceContext.getDeviceInfo().getLOGValue());
         }
 
+        final boolean connectionInterrupted =
+                this.deviceContext
+                        .getPrimaryConnectionContext()
+                        .getConnectionState()
+                        .equals(ConnectionContext.CONNECTION_STATE.RIP);
+
         LOG.info("Stopping role context cluster services for node {}", getIdentifier());
-        roleContext.stopClusterServices();
+        roleContext.stopClusterServices(connectionInterrupted);
 
         LOG.info("Stopping statistics context cluster services for node {}", getIdentifier());
-        statContext.stopClusterServices();
+        statContext.stopClusterServices(connectionInterrupted);
 
         LOG.info("Stopping rpc context cluster services for node {}", getIdentifier());
-        rpcContext.stopClusterServices();
+        rpcContext.stopClusterServices(connectionInterrupted);
 
         LOG.info("Stopping device context cluster services for node {}", getIdentifier());
-        return deviceContext.stopClusterServices();
+        return deviceContext.stopClusterServices(connectionInterrupted);
     }
 
     @Override
index baefc62aca38b780a121f3224b8841d84592e960..c44f1e3e9c0cb6cb7c08f25adb58fd843414f54d 100644 (file)
@@ -84,7 +84,7 @@ public class DeviceFlowRegistryImpl implements DeviceFlowRegistry {
 
     @Override
     public ListenableFuture<List<Optional<FlowCapableNode>>> fill() {
-        LOG.debug("Filling flow registry with flows for node: {}", instanceIdentifier);
+        LOG.debug("Filling flow registry with flows for node: {}", instanceIdentifier.getKey().getId().getValue());
 
         // Prepare path for read transaction
         // TODO: Read only Tables, and not entire FlowCapableNode (fix Yang model)
index 483b8c7fafbbc219395c875c46f4c09fcfbb8851..888a4e9590f5853bde315c33c6bf9094465093cd 100644 (file)
@@ -24,7 +24,6 @@ import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
 import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
@@ -54,14 +53,11 @@ class RoleContextImpl implements RoleContext {
     private final DeviceInfo deviceInfo;
     private CONTEXT_STATE state;
     private final RoleManager myManager;
-    private final LifecycleService lifecycleService;
 
     RoleContextImpl(final DeviceInfo deviceInfo,
                     final HashedWheelTimer hashedWheelTimer,
-                    final RoleManager myManager,
-                    final LifecycleService lifecycleService) {
+                    final RoleManager myManager) {
         this.deviceInfo = deviceInfo;
-        this.lifecycleService = lifecycleService;
         state = CONTEXT_STATE.WORKING;
         this.myManager = myManager;
         this.hashedWheelTimer = hashedWheelTimer;
@@ -113,46 +109,49 @@ class RoleContextImpl implements RoleContext {
             @Override
             public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
                 if (LOG.isDebugEnabled()) {
-                    LOG.debug("Role MASTER was successfully set on device, node {}", deviceInfo.getNodeId().getValue());
+                    LOG.debug("Role MASTER was successfully set on device, node {}", deviceInfo.getLOGValue());
                 }
             }
 
             @Override
             public void onFailure(final Throwable throwable) {
-                LOG.warn("Was not able to set MASTER role on device, node {}", deviceInfo.getNodeId().getValue());
-                lifecycleService.closeConnection();
+                LOG.warn("Was not able to set MASTER role on device, node {}", deviceInfo.getLOGValue());
             }
         });
     }
 
     @Override
-    public ListenableFuture<Void> stopClusterServices() {
-        ListenableFuture<Void> future = Futures.transform(makeDeviceSlave(), new Function<RpcResult<SetRoleOutput>, Void>() {
-                    @Nullable
-                    @Override
-                    public Void apply(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
-                        return null;
-                    }
-                });
-
-                Futures.addCallback(future, new FutureCallback<Void>() {
-                    @Override
-                    public void onSuccess(@Nullable Void aVoid) {
-                        if (LOG.isDebugEnabled()) {
-                            LOG.debug("Role SLAVE was successfully propagated on device, node {}", deviceInfo.getNodeId().getValue());
-                        }
-                        myManager.removeDeviceFromOperationalDS(deviceInfo, MAX_CLEAN_DS_RETRIES);
+    public ListenableFuture<Void> stopClusterServices(final boolean deviceDisconnected) {
+
+        if (!deviceDisconnected) {
+            ListenableFuture<Void> future = Futures.transform(makeDeviceSlave(), new Function<RpcResult<SetRoleOutput>, Void>() {
+                @Nullable
+                @Override
+                public Void apply(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
+                    return null;
+                }
+            });
+
+            Futures.addCallback(future, new FutureCallback<Void>() {
+                @Override
+                public void onSuccess(@Nullable Void aVoid) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Role SLAVE was successfully propagated on device, node {}", deviceInfo.getLOGValue());
                     }
+                }
 
-                    @Override
-                    public void onFailure(final Throwable throwable) {
-                        LOG.warn("Was not able to set role SLAVE to device on node {} ", deviceInfo.getNodeId().getValue());
-                        LOG.trace("Error occurred on device role setting, probably connection loss: ", throwable);
-                        myManager.removeDeviceFromOperationalDS(deviceInfo, MAX_CLEAN_DS_RETRIES);
+                @Override
+                public void onFailure(final Throwable throwable) {
+                    LOG.warn("Was not able to set role SLAVE to device on node {} ", deviceInfo.getLOGValue());
+                    LOG.trace("Error occurred on device role setting, probably connection loss: ", throwable);
+                    myManager.removeDeviceFromOperationalDS(deviceInfo, MAX_CLEAN_DS_RETRIES);
 
-                    }
-                });
-        return future;
+                }
+            });
+            return future;
+        } else {
+            return myManager.removeDeviceFromOperationalDS(deviceInfo, MAX_CLEAN_DS_RETRIES);
+        }
     }
 
     @Override
@@ -177,7 +176,7 @@ class RoleContextImpl implements RoleContext {
             setRoleOutputFuture = getSalRoleService().setRole(setRoleInput);
             final TimerTask timerTask = timeout -> {
                 if (!setRoleOutputFuture.isDone()) {
-                    LOG.warn("New role {} was not propagated to device {} during 10 sec", newRole, deviceInfo.getNodeId());
+                    LOG.warn("New role {} was not propagated to device {} during 10 sec", newRole, deviceInfo.getLOGValue());
                     setRoleOutputFuture.cancel(true);
                 }
             };
index 45141930493634968720268710b4c4de571f898c..e6decb4a7c9a74a89b423b54c71476830f8ee298 100644 (file)
@@ -71,7 +71,7 @@ public class RoleManagerImpl implements RoleManager {
     @Override
     public void onDeviceContextLevelUp(@CheckForNull final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
         final DeviceContext deviceContext = Preconditions.checkNotNull(lifecycleService.getDeviceContext());
-        final RoleContext roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, this, lifecycleService);
+        final RoleContext roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, this);
         roleContext.setSalRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
         Verify.verify(contexts.putIfAbsent(deviceInfo, roleContext) == null, "Role context for master Node %s is still not closed.", deviceInfo.getLOGValue());
         Futures.addCallback(roleContext.makeDeviceSlave(), new FutureCallback<RpcResult<SetRoleOutput>>() {
@@ -85,7 +85,6 @@ public class RoleManagerImpl implements RoleManager {
                     @Override
                     public void onFailure(Throwable throwable) {
                         LOG.warn("Was not able to set role SLAVE to device on node {} ",deviceInfo.getLOGValue());
-                        lifecycleService.closeConnection();
                     }
                 });
         lifecycleService.setRoleContext(roleContext);
index b5563d6e86b1f95d160b8473e3ab134502ba1f1f..6d1954d30d6870fbb5c33f64d73ccfdfdb7d07dc 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.device.XidSequencer;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
@@ -90,7 +89,7 @@ class RpcContextImpl implements RpcContext {
             final RoutedRpcRegistration<S> routedRpcReg = rpcProviderRegistry.addRoutedRpcImplementation(serviceClass, serviceInstance);
             routedRpcReg.registerPath(NodeContext.class, nodeInstanceIdentifier);
             rpcRegistrations.put(serviceClass, routedRpcReg);
-            LOG.debug("Registration of service {} for device {}.", serviceClass, nodeInstanceIdentifier);
+            LOG.debug("Registration of service {} for device {}.", serviceClass.getSimpleName(), nodeInstanceIdentifier.getKey().getId().getValue());
         }
     }
 
@@ -120,8 +119,8 @@ class RpcContextImpl implements RpcContext {
                 rpcRegistration.unregisterPath(NodeContext.class, nodeInstanceIdentifier);
                 rpcRegistration.close();
                 if (LOG.isDebugEnabled()) {
-                    LOG.debug("Closing RPC Registration of service {} for device {}.", rpcRegistration.getServiceType(),
-                            nodeInstanceIdentifier);
+                    LOG.debug("Closing RPC Registration of service {} for device {}.", rpcRegistration.getServiceType().getSimpleName(),
+                            nodeInstanceIdentifier.getKey().getId().getValue());
                 }
             }
         }
@@ -133,12 +132,12 @@ class RpcContextImpl implements RpcContext {
             LOG.trace("Device queue {} at capacity", this);
             return null;
         } else {
-            LOG.trace("Acquired semaphore for {}, available permits:{} ", nodeInstanceIdentifier.getKey().getId(), tracker.availablePermits());
+            LOG.trace("Acquired semaphore for {}, available permits:{} ", nodeInstanceIdentifier.getKey().getId().getValue(), tracker.availablePermits());
         }
 
         final Long xid = deviceInfo.reserveXidForDeviceMessage();
         if (xid == null) {
-            LOG.warn("Xid cannot be reserved for new RequestContext, node:{}", nodeInstanceIdentifier.getKey().getId());
+            LOG.warn("Xid cannot be reserved for new RequestContext, node:{}", nodeInstanceIdentifier.getKey().getId().getValue());
             tracker.release();
             return null;
         }
@@ -161,7 +160,7 @@ class RpcContextImpl implements RpcContext {
         if (rpcRegistration != null) {
             rpcRegistration.unregisterPath(NodeContext.class, nodeInstanceIdentifier);
             rpcRegistration.close();
-            LOG.debug("Unregistration serviceClass {} for Node {}", serviceClass, nodeInstanceIdentifier.getKey().getId());
+            LOG.debug("Un-registration serviceClass {} for Node {}", serviceClass.getSimpleName(), nodeInstanceIdentifier.getKey().getId().getValue());
         }
     }
 
@@ -214,7 +213,7 @@ class RpcContextImpl implements RpcContext {
     }
 
     @Override
-    public ListenableFuture<Void> stopClusterServices() {
+    public ListenableFuture<Void> stopClusterServices(boolean deviceDisconnected) {
         MdSalRegistrationUtils.unregisterServices(this);
         return Futures.immediateFuture(null);
     }
index c90cff8c6dddd4244f58e35b2f730c27b7f476e2..9906515af633106c39dd1f239c6e653ff2d35722 100644 (file)
@@ -69,7 +69,7 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
             currentRoleGuard.acquire();
             LOG.trace("currentRole lock queue length: {} " + currentRoleGuard.getQueueLength());
         } catch (final InterruptedException e) {
-            LOG.error("Unexpected exception {} for acquire semaphor for input {}", e, input);
+            LOG.error("Unexpected exception {} for acquire semaphore for input {}", e, input);
             return RpcResultBuilder.<SetRoleOutput> failed().buildFuture();
         }
         // compare with last known role and set if different. If they are same, then return.
index 144d664c2b631c5203b4b207a66e87de749576ec..9c8755e83de2ff7f07644bc8130366d5e809a362 100644 (file)
@@ -426,7 +426,7 @@ class StatisticsContextImpl implements StatisticsContext {
     }
 
     @Override
-    public ListenableFuture<Void> stopClusterServices() {
+    public ListenableFuture<Void> stopClusterServices(boolean deviceDisconnected) {
         myManager.stopScheduling(deviceInfo);
         return Futures.immediateFuture(null);
     }
index 176a776689d13343ddc7539d7cf650ad80afcfbf..19bb57d8f0d30ae9881b70474cec8beda0958ce1 100644 (file)
@@ -104,7 +104,7 @@ public class SystemNotificationsListenerImplTest {
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
         Mockito.verify(connectionContext).getConnectionAdapter();
-        Mockito.verify(connectionContext).getNodeId();
+        Mockito.verify(connectionContext, Mockito.atLeastOnce()).getSafeNodeIdForLOG();
     }
 
     /**
@@ -123,7 +123,7 @@ public class SystemNotificationsListenerImplTest {
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
         Mockito.verify(connectionContext).getConnectionAdapter();
-        Mockito.verify(connectionContext).getNodeId();
+        Mockito.verify(connectionContext, Mockito.atLeastOnce()).getSafeNodeIdForLOG();
     }
 
     /**
@@ -144,7 +144,7 @@ public class SystemNotificationsListenerImplTest {
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
         Mockito.verify(connectionContext).getConnectionAdapter();
-        Mockito.verify(connectionContext).getNodeId();
+        Mockito.verify(connectionContext, Mockito.atLeastOnce()).getSafeNodeIdForLOG();
     }
 
     /**
@@ -163,7 +163,7 @@ public class SystemNotificationsListenerImplTest {
         verifyCommonInvocationsSubSet();
         Mockito.verify(connectionContext).onConnectionClosed();
         Mockito.verify(connectionContext).getConnectionAdapter();
-        Mockito.verify(connectionContext).getNodeId();
+        Mockito.verify(connectionContext, Mockito.atLeastOnce()).getSafeNodeIdForLOG();
     }
 
     /**
@@ -212,7 +212,7 @@ public class SystemNotificationsListenerImplTest {
         Mockito.verify(connectionAdapter).disconnect();
         Mockito.verify(connectionContext).changeStateToTimeouting();
         Mockito.verify(connectionContext).closeConnection(true);
-        Mockito.verify(connectionContext).getNodeId();
+        Mockito.verify(connectionContext, Mockito.atLeastOnce()).getSafeNodeIdForLOG();
 
     }
 
index 3e8b905f10bb50a9fa0d3e4e74c295296a32c04c..dc3b6dccc4b428ff0118a50739d985c83dc36f5b 100644 (file)
@@ -44,7 +44,7 @@ public class RoleContextImplTest {
 
     @Before
     public void setup() throws CandidateAlreadyRegisteredException {
-        roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, roleManager, lifecycleService);
+        roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, roleManager);
         Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
     }
 
index 4344cc01e6bd3aabcbb3c76c15c55e7620f315cc..d38ff06800cc8da44022af9744d30ba99e6eb508 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.impl.rpc;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -58,6 +59,8 @@ public class RpcContextImplTest {
     private DeviceContext deviceContext;
     @Mock
     private BindingAwareBroker.RoutedRpcRegistration<TestRpcService> routedRpcReg;
+
+    private Class<TestRpcService> serviceClass;
     @Mock
     private NotificationPublishService notificationPublishService;
     @Mock
@@ -166,6 +169,8 @@ public class RpcContextImplTest {
 
     @Test
     public void testClose() {
+        serviceClass = TestRpcService.class;
+        when(routedRpcReg.getServiceType()).thenReturn(serviceClass);
         rpcContext.registerRpcServiceImplementation(TestRpcService.class, serviceInstance);
         rpcContext.close();
         assertEquals(rpcContext.isEmptyRpcRegistrations(), true);