Merge "RoleManager changes"
authormichal rehak <mirehak@cisco.com>
Tue, 21 Jun 2016 09:00:31 +0000 (09:00 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 21 Jun 2016 09:00:31 +0000 (09:00 +0000)
12 files changed:
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceStateImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringOnTheFlyServiceTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/direct/AbstractDirectStatisticsServiceTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/AggregatedFlowStatisticsTranslatorTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/translator/FlowRemovedTranslatorTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtilsTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistrationUtilsTest.java

index f9b30b50bb2ca985050376db60c6362ed4e01883..5a74eed9bee0b5462abb531012f2cb802ddc494c 100644 (file)
@@ -73,7 +73,7 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
     private DeviceTerminationPhaseHandler deviceTerminationPhaseHandler;
     private final DataBroker dataBroker;
     private final EntityOwnershipService entityOwnershipService;
-    private final ConcurrentMap<NodeId, RoleContext> contexts = new ConcurrentHashMap<>();
+    private final ConcurrentMap<DeviceInfo, RoleContext> contexts = new ConcurrentHashMap<>();
     private final ConcurrentMap<Entity, RoleContext> watchingEntities = new ConcurrentHashMap<>();
     private final EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
     private final EntityOwnershipListenerRegistration txEntityOwnershipListenerRegistration;
@@ -100,7 +100,7 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
         final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
         final RoleContext roleContext = new RoleContextImpl(deviceInfo, entityOwnershipService, makeEntity(deviceInfo.getNodeId()), makeTxEntity(deviceInfo.getNodeId()), conductor);
         roleContext.setSalRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
-        Verify.verify(contexts.putIfAbsent(deviceInfo.getNodeId(), roleContext) == null, "Role context for master Node %s is still not closed.", deviceInfo.getNodeId());
+        Verify.verify(contexts.putIfAbsent(deviceInfo, roleContext) == null, "Role context for master Node %s is still not closed.", deviceInfo.getNodeId());
         makeDeviceRoleChange(OfpRole.BECOMESLAVE, roleContext, true);
         /* First start to watch entity so we don't miss any notification, and then try to register in EOS */
         notifyListenersRoleInitializationDone(roleContext.getDeviceInfo(), roleContext.initialization());
@@ -118,10 +118,10 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
             final RoleContext roleContext = iterator.next();
             watchingEntities.remove(roleContext.getEntity());
             watchingEntities.remove(roleContext.getTxEntity());
-            contexts.remove(roleContext.getDeviceInfo().getNodeId());
+            contexts.remove(roleContext.getDeviceInfo());
             if (roleContext.isTxCandidateRegistered()) {
                 LOG.info("Node {} was holder txEntity, so trying to remove device from operational DS.");
-                removeDeviceFromOperationalDS(roleContext.getDeviceInfo().getNodeId());
+                removeDeviceFromOperationalDS(roleContext.getDeviceInfo());
             } else {
                 roleContext.close();
             }
@@ -131,7 +131,7 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
     @Override
     public void onDeviceContextLevelDown(final DeviceInfo deviceInfo) {
         LOG.trace("onDeviceContextLevelDown for node {}", deviceInfo.getNodeId());
-        final RoleContext roleContext = contexts.get(deviceInfo.getNodeId());
+        final RoleContext roleContext = contexts.get(deviceInfo);
         if (roleContext != null) {
             LOG.debug("Found roleContext associated to deviceContext: {}, now trying close the roleContext", deviceInfo.getNodeId());
             if (roleContext.isMainCandidateRegistered()) {
@@ -205,11 +205,10 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
                 roleContext.unregisterCandidate(roleContext.getTxEntity());
                 if (ownershipChange.wasOwner() && !ownershipChange.isOwner() && !ownershipChange.hasOwner()) {
                     LOG.debug("Trying to remove from operational node: {}", roleContext.getDeviceInfo().getNodeId());
-                    removeDeviceFromOperationalDS(roleContext.getDeviceInfo().getNodeId());
+                    removeDeviceFromOperationalDS(roleContext.getDeviceInfo());
                 }
             } else {
-                final NodeId nodeId = roleContext.getDeviceInfo().getNodeId();
-                contexts.remove(nodeId, roleContext);
+                contexts.remove(roleContext.getDeviceInfo(), roleContext);
                 roleContext.close();
                 conductor.closeConnection(roleContext.getDeviceInfo());
             }
@@ -244,10 +243,10 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
                     roleContext.unregisterCandidate(roleContext.getTxEntity());
                     if (!ownershipChange.hasOwner()) {
                         LOG.debug("Trying to remove from operational node: {}", roleContext.getDeviceInfo().getNodeId());
-                        removeDeviceFromOperationalDS(roleContext.getDeviceInfo().getNodeId());
+                        removeDeviceFromOperationalDS(roleContext.getDeviceInfo());
                     } else {
                         final NodeId nodeId = roleContext.getDeviceInfo().getNodeId();
-                        contexts.remove(nodeId, roleContext);
+                        contexts.remove(roleContext.getDeviceInfo(), roleContext);
                         roleContext.close();
                         conductor.closeConnection(roleContext.getDeviceInfo());
                     }
@@ -256,8 +255,7 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
         } else {
             LOG.debug("Tx-EntityOwnershipRegistration is not active for entity {}", ownershipChange.getEntity().getType());
             watchingEntities.remove(roleContext.getTxEntity(), roleContext);
-            final NodeId nodeId = roleContext.getDeviceInfo().getNodeId();
-            contexts.remove(nodeId, roleContext);
+            contexts.remove(roleContext.getDeviceInfo(), roleContext);
             roleContext.close();
             conductor.closeConnection(roleContext.getDeviceInfo());
         }
@@ -285,7 +283,7 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
     ListenableFuture<RpcResult<SetRoleOutput>> sendRoleChangeToDevice(final OfpRole newRole, final RoleContext roleContext) {
         LOG.debug("Sending new role {} to device {}", newRole, roleContext.getDeviceInfo().getNodeId());
         final Future<RpcResult<SetRoleOutput>> setRoleOutputFuture;
-        final Short version = conductor.gainVersionSafely(roleContext.getDeviceInfo());
+        final Short version = roleContext.getDeviceInfo().getVersion();
         if (null == version) {
             LOG.debug("Device version is null");
             return Futures.immediateFuture(null);
@@ -309,17 +307,17 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
     }
 
     @VisibleForTesting
-    CheckedFuture<Void, TransactionCommitFailedException> removeDeviceFromOperationalDS(final NodeId nodeId) {
+    CheckedFuture<Void, TransactionCommitFailedException> removeDeviceFromOperationalDS(final DeviceInfo deviceInfo) {
 
         final WriteTransaction delWtx = dataBroker.newWriteOnlyTransaction();
-        delWtx.delete(LogicalDatastoreType.OPERATIONAL, DeviceStateUtil.createNodeInstanceIdentifier(nodeId));
+        delWtx.delete(LogicalDatastoreType.OPERATIONAL, DeviceStateUtil.createNodeInstanceIdentifier(deviceInfo.getNodeId()));
         final CheckedFuture<Void, TransactionCommitFailedException> delFuture = delWtx.submit();
         Futures.addCallback(delFuture, new FutureCallback<Void>() {
 
             @Override
             public void onSuccess(final Void result) {
-                LOG.debug("Delete Node {} was successful", nodeId);
-                final RoleContext roleContext = contexts.remove(nodeId);
+                LOG.debug("Delete Node {} was successful", deviceInfo);
+                final RoleContext roleContext = contexts.remove(deviceInfo);
                 if (roleContext != null) {
                     roleContext.close();
                 }
@@ -327,9 +325,9 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
 
             @Override
             public void onFailure(@Nonnull final Throwable t) {
-                LOG.warn("Delete Node {} failed. {}", nodeId, t);
-                contexts.remove(nodeId);
-                final RoleContext roleContext = contexts.remove(nodeId);
+                LOG.warn("Delete Node {} failed. {}", deviceInfo, t);
+                contexts.remove(deviceInfo);
+                final RoleContext roleContext = contexts.remove(deviceInfo);
                 if (roleContext != null) {
                     roleContext.close();
                 }
@@ -346,7 +344,7 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
     @Override
     public void servicesChangeDone(final DeviceInfo deviceInfo, final boolean success) {
         LOG.debug("Services stopping done for node {} as " + (success ? "successful" : "unsuccessful"), deviceInfo);
-        final RoleContext roleContext = contexts.get(deviceInfo.getNodeId());
+        final RoleContext roleContext = contexts.get(deviceInfo);
         if (null != roleContext) {
             /* Services stopped or failure */
             roleContext.unregisterCandidate(roleContext.getTxEntity());
@@ -354,17 +352,17 @@ public class RoleManagerImpl implements RoleManager, EntityOwnershipListener, Se
     }
 
     @VisibleForTesting
-    RoleContext getRoleContext(final NodeId nodeId){
-        return contexts.get(nodeId);
+    RoleContext getRoleContext(final DeviceInfo deviceInfo){
+        return contexts.get(deviceInfo);
     }
 
     /**
      * This method is only for testing
      */
     @VisibleForTesting
-    void setRoleContext(NodeId nodeId, RoleContext roleContext){
-        if(!contexts.containsKey(nodeId)) {
-            contexts.put(nodeId, roleContext);
+    void setRoleContext(DeviceInfo deviceInfo, RoleContext roleContext){
+        if(!contexts.containsKey(deviceInfo)) {
+            contexts.put(deviceInfo, roleContext);
         }
     }
 
index 82230c9862722fef02bcc90ca597dccd5cc6e40d..b719795a588ac6f5b878e79fd081cae9a38cff43 100644 (file)
@@ -33,20 +33,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 @RunWith(MockitoJUnitRunner.class)
 public class DeviceStateImplTest {
 
-    @Mock
-    private FeaturesReply featuresReply;
     private DeviceStateImpl deviceState;
 
-    private final short version = 13;
-    private final long portNr = 10L;
-    private final Long portBandwidth = 1024L;
-    private final List<PhyPort> pPort = Arrays.asList(new PhyPortBuilder()
-                    .setPortNo(portNr).setMaxSpeed(portBandwidth).build());
-
     @Before
     public void initialization() {
-        Mockito.when(featuresReply.getVersion()).thenReturn(version);
-        Mockito.when(featuresReply.getPhyPort()).thenReturn(pPort);
         deviceState = new DeviceStateImpl();
     }
 
index fe20b2e68e6f6681e2ef8bc7a7ee3da6b079a82d..9babd0a35d78dbc65057d07174c557c3265b293d 100644 (file)
@@ -14,6 +14,7 @@ import java.math.BigInteger;
 import com.google.common.base.VerifyException;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -32,6 +33,7 @@ import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipL
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
@@ -43,10 +45,13 @@ import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTermin
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.atLeastOnce;
@@ -104,6 +109,11 @@ public class RoleManagerImplTest {
     @Mock
     DeviceInfo deviceInfo2;
 
+    @Mock
+    MessageSpy messageSpy;
+
+    @Mock
+    OutboundQueue outboundQueue;
 
     @Mock
     GetFeaturesOutput featuresOutput;
@@ -131,11 +141,14 @@ public class RoleManagerImplTest {
         Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
         Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
         Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
+        Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
+        Mockito.when(deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider()).thenReturn(outboundQueue);
         Mockito.when(connectionContext.getFeatures()).thenReturn(featuresReply);
         Mockito.when(connectionContext.getNodeId()).thenReturn(nodeId);
         Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
-        Mockito.when(featuresReply.getDatapathId()).thenReturn(new BigInteger("1"));
-        Mockito.when(featuresReply.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+        Mockito.when(deviceInfo.getDatapathId()).thenReturn(new BigInteger("1"));
+        Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+        Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
         Mockito.doNothing().when(deviceInitializationPhaseHandler).onDeviceContextLevelUp(Mockito.<DeviceInfo>any());
         Mockito.doNothing().when(deviceTerminationPhaseHandler).onDeviceContextLevelDown(Mockito.<DeviceInfo>any());
         Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
@@ -150,8 +163,11 @@ public class RoleManagerImplTest {
         Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext);
         roleManagerSpy = Mockito.spy(roleManager);
         roleManagerSpy.onDeviceContextLevelUp(deviceInfo);
-        roleContextSpy = Mockito.spy(roleManager.getRoleContext(nodeId));
+        Mockito.doNothing().when(roleManagerSpy).makeDeviceRoleChange(Mockito.<OfpRole>any(), Mockito.<RoleContext>any(), Mockito.anyBoolean());
+        roleContextSpy = Mockito.spy(roleManager.getRoleContext(deviceInfo));
+        Mockito.when(roleContextSpy.getDeviceInfo()).thenReturn(deviceInfo);
         Mockito.when(roleContextSpy.getDeviceInfo().getNodeId()).thenReturn(nodeId);
+//        Mockito.when(roleManagerSpy.sendRoleChangeToDevice(Mockito.<OfpRole>any(), Mockito.<RoleContext>any())).thenReturn(rpcFuture);
         inOrder = Mockito.inOrder(entityOwnershipListenerRegistration, roleManagerSpy, roleContextSpy);
     }
 
@@ -172,7 +188,7 @@ public class RoleManagerImplTest {
         roleManagerSpy.ownershipChanged(masterTxEntity);
         roleManagerSpy.close();
         inOrder.verify(entityOwnershipListenerRegistration, Mockito.calls(2)).close();
-        inOrder.verify(roleManagerSpy).removeDeviceFromOperationalDS(nodeId);
+        inOrder.verify(roleManagerSpy).removeDeviceFromOperationalDS(deviceInfo);
         inOrder.verifyNoMoreInteractions();
     }
 
@@ -181,7 +197,7 @@ public class RoleManagerImplTest {
         roleManagerSpy.ownershipChanged(slaveEntity);
         roleManagerSpy.close();
         inOrder.verify(entityOwnershipListenerRegistration, Mockito.calls(2)).close();
-        inOrder.verify(roleManagerSpy, Mockito.never()).removeDeviceFromOperationalDS(nodeId);
+        inOrder.verify(roleManagerSpy, Mockito.never()).removeDeviceFromOperationalDS(deviceInfo);
         inOrder.verifyNoMoreInteractions();
     }
 
@@ -230,7 +246,7 @@ public class RoleManagerImplTest {
         inOrder.verify(roleContextSpy, Mockito.atLeastOnce()).isTxCandidateRegistered();
         inOrder.verify(roleContextSpy, Mockito.calls(1)).unregisterCandidate(Mockito.<Entity>any());
         inOrder.verify(roleContextSpy, Mockito.never()).close();
-        inOrder.verify(roleManagerSpy, Mockito.calls(1)).removeDeviceFromOperationalDS(Mockito.<NodeId>any());
+        inOrder.verify(roleManagerSpy, Mockito.calls(1)).removeDeviceFromOperationalDS(Mockito.<DeviceInfo>any());
     }
 
     @Test
@@ -270,7 +286,7 @@ public class RoleManagerImplTest {
 
             @Override
             public void roleChangeOnDevice(final DeviceInfo deviceInfo_, final boolean success, final OfpRole newRole, final boolean initializationPhase) {
-                Assert.assertTrue(deviceInfo.equals(deviceInfo_));
+                Assert.assertTrue(RoleManagerImplTest.this.deviceInfo.equals(deviceInfo_));
                 Assert.assertTrue(success);
                 Assert.assertFalse(initializationPhase);
                 Assert.assertTrue(newRole.equals(OfpRole.BECOMEMASTER));
@@ -279,24 +295,17 @@ public class RoleManagerImplTest {
         roleManager.notifyListenersRoleInitializationDone(deviceInfo, true);
         roleManager.notifyListenersRoleChangeOnDevice(deviceInfo, true, OfpRole.BECOMEMASTER, false);
     }
-
-    @Test
-    public void testMakeDeviceRoleChange() throws Exception{
-        roleManagerSpy.makeDeviceRoleChange(OfpRole.BECOMEMASTER, roleContextSpy, true);
-        verify(roleManagerSpy, atLeastOnce()).sendRoleChangeToDevice(Mockito.<OfpRole>any(), Mockito.<RoleContext>any());
-        verify(roleManagerSpy, atLeastOnce()).notifyListenersRoleChangeOnDevice(Mockito.<DeviceInfo>any(), eq(true), Mockito.<OfpRole>any(), eq(true));
-    }
-
+    
     @Test
     public void testServicesChangeDone() throws Exception {
-        roleManagerSpy.setRoleContext(nodeId2, roleContextSpy);
+        roleManagerSpy.setRoleContext(deviceInfo2, roleContextSpy);
         roleManagerSpy.servicesChangeDone(deviceInfo2, true);
         verify(roleContextSpy).unregisterCandidate(Mockito.<Entity>any());
     }
 
     @Test
     public void testServicesChangeDoneContextIsNull() throws Exception {
-        roleManagerSpy.setRoleContext(nodeId, roleContextSpy);
+        roleManagerSpy.setRoleContext(deviceInfo, roleContextSpy);
         roleManagerSpy.servicesChangeDone(deviceInfo2, true);
         verify(roleContextSpy, never()).unregisterCandidate(Mockito.<Entity>any());
     }
index 08f97f5c619db89afb3ebca3ae17350dc5feddb5..e3268407a07cf29880bda6d6c1c7ec8b8148b9e5 100644 (file)
@@ -48,8 +48,6 @@ public class RpcContextImplTest {
     @Mock
     private DeviceState deviceState;
     @Mock
-    private DeviceInfo deviceInfo;
-    @Mock
     private XidSequencer xidSequencer;
     @Mock
     private MessageSpy messageSpy;
@@ -61,6 +59,8 @@ public class RpcContextImplTest {
     private NotificationPublishService notificationPublishService;
     @Mock
     private TestRpcService serviceInstance;
+    @Mock
+    private DeviceInfo deviceInfo;
 
     private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
 
index 2897c25cabfb712a7862ac04bf1c7e3e224b2ec0..3cf2cb40555dbc2ba499682519f90019340d151a 100644 (file)
@@ -137,8 +137,8 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 @RunWith(MockitoJUnitRunner.class)
 public class StatisticsGatheringUtilsTest {
 
-    public static final String DUMMY_NODE_ID_VALUE = "1";
-    public static final NodeId DUMMY_NODE_ID = new NodeId(DUMMY_NODE_ID_VALUE);
+    static final String DUMMY_NODE_ID_VALUE = "1";
+    static final NodeId DUMMY_NODE_ID = new NodeId(DUMMY_NODE_ID_VALUE);
 
     private final KeyedInstanceIdentifier<Node, NodeKey> dummyNodePath = InstanceIdentifier.create(Nodes.class)
             .child(Node.class, new NodeKey(DUMMY_NODE_ID));
index aab0e8e04a6f5a02ed91782e0a6b15390f57a288..9058d86dcd0988918c11bbc6a6a218d8150bc225 100644 (file)
@@ -101,6 +101,8 @@ public class StatisticsManagerImplTest {
     @Mock
     DeviceState mockedDeviceState;
     @Mock
+    DeviceInfo mockedDeviceInfo;
+    @Mock
     DeviceInitializationPhaseHandler mockedDevicePhaseHandler;
     @Mock
     DeviceTerminationPhaseHandler mockedTerminationPhaseHandler;
index 8bb91a8249dbc16fb02c5a0301d5293b9e05468f..eb17d48ae775499080e9c194199cc91b54c3bacd 100644 (file)
@@ -32,6 +32,7 @@ public class StatisticsGatheringOnTheFlyServiceTest extends ServiceMocking {
         statisticsGatheringService = new StatisticsGatheringOnTheFlyService(mockedRequestContextStack, mockedDeviceContext);
         Mockito.doReturn(NODE_ID).when(mockedPrimConnectionContext).getNodeId();
         Mockito.when(mockedDeviceInfo.getNodeId()).thenReturn(NODE_ID);
+        Mockito.when(mockedDeviceContext.getDeviceInfo().getNodeId()).thenReturn(NODE_ID);
     }
 
     @Test
index ac20355da025133340165830708bff5620a7dc60..f4f2ab6af870c0356e1ac63fb6cc608c7a99ffe4 100644 (file)
@@ -69,6 +69,8 @@ public abstract class AbstractDirectStatisticsServiceTest {
     protected DeviceState deviceState;
     @Mock
     protected DeviceInfo deviceInfo;
+    @Mock
+    protected GetFeaturesOutput getFeaturesOutput;
 
     protected NodeConnectorId nodeConnectorId;
     protected KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
@@ -101,6 +103,8 @@ public abstract class AbstractDirectStatisticsServiceTest {
         when(deviceInfo.getNodeId()).thenReturn(new NodeId(NODE_ID));
         when(deviceInfo.getVersion()).thenReturn(OF_VERSION);
         when(deviceInfo.getDatapathId()).thenReturn(DATAPATH_ID);
+        when(getFeaturesOutput.getVersion()).thenReturn(OF_VERSION);
+        when(getFeaturesOutput.getDatapathId()).thenReturn(DATAPATH_ID);
         when(connectionContext.getFeatures()).thenReturn(features);
         when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
         when(features.getVersion()).thenReturn(OF_VERSION);
index 83eae57e0f2e5d123ee228a34ad1da603bc2ab7c..0e38bc7f0147b42b1ee53bba4335197a08cc885d 100644 (file)
@@ -30,8 +30,6 @@ public class AggregatedFlowStatisticsTranslatorTest {
 
     private AggregatedFlowStatisticsTranslator translator;
     @Mock
-    private DeviceState deviceState;
-    @Mock
     private DeviceInfo deviceInfo;
 
     @Before
index 5fa15e094b6a8cd326f89cb5104c366614c6aa50..1c2886d13c61352e5b5b47813a0a8d892d6a530d 100644 (file)
@@ -106,7 +106,7 @@ public class FlowRemovedTranslatorTest {
             builder.setMatchV10(new MatchV10Builder().setWildcards(flowWildcards).build());
         } else {
             builder.setMatch(new MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList()).build())
-                .setTableId(new TableId(42l));
+                .setTableId(new TableId(42L));
         }
 
         return builder.build();
index 70bd8cd29fb538b6e8ebaa45446397c75a1a4962..c8dcf376e1bd1e746871783c7b772559efb94dd2 100644 (file)
@@ -134,6 +134,8 @@ public class DeviceInitializationUtilsTest {
     private DeviceInfo mockedDeviceInfo;
     @Mock
     private DeviceInitializationUtils deviceInitializationUtils;
+    @Mock
+    private DeviceInfo deviceInfo;
 
     @Before
     public void setUp() throws Exception {
index b6f36a1974d749129ddd0525d28cbab6f3e2131b..16da6bf9de35f4dc60ee3808cc1d795560170268 100644 (file)
@@ -46,19 +46,15 @@ public class MdSalRegistrationUtilsTest {
         final ConnectionContext mockedConnectionContext = mock(ConnectionContext.class);
 
         final DeviceState mockedDeviceState = mock(DeviceState.class);
-        when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
-
         final DeviceInfo mockedDeviceInfo = mock(DeviceInfo.class);
+        when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
         when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
 
         final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
         when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
 
-        final GetFeaturesOutput mockedFeaturesOutput = mock(GetFeaturesOutput.class);
-
         final BigInteger mockedDataPathId = mock(BigInteger.class);
         when(mockedFeatures.getDatapathId()).thenReturn(mockedDataPathId);
-        when(mockedFeaturesOutput.getDatapathId()).thenReturn(mockedDataPathId);
         when(mockedDeviceInfo.getDatapathId()).thenReturn(mockedDataPathId);
 
         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);