Bug 6665 - Fix switches scalability
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / StatisticsManagerImplTest.java
index 6c4229e10fa6cfd280560c3a654eb24f2adf7acc..0b9c4555591a6334161a9a63d88534919c7c768b 100644 (file)
@@ -51,7 +51,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
 import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
@@ -85,8 +85,6 @@ public class StatisticsManagerImplTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(StatisticsManagerImplTest.class);
 
-    private static final BigInteger DUMMY_DATAPATH_ID = new BigInteger("444");
-    private static final Short DUMMY_VERSION = OFConstants.OFP_VERSION_1_3;
     public static final NodeId NODE_ID = new NodeId("ofp-unit-dummy-node-id");
 
     @Mock
@@ -128,8 +126,6 @@ public class StatisticsManagerImplTest {
     @Mock
     private DeviceManager deviceManager;
     @Mock
-    private LifecycleConductor conductor;
-    @Mock
     private GetFeaturesOutput featuresOutput;
     @Mock
     private DeviceInitializationPhaseHandler deviceInitializationPhaseHandler;
@@ -137,6 +133,8 @@ public class StatisticsManagerImplTest {
     private DeviceInfo deviceInfo;
     @Mock
     private DataBroker dataBroker;
+    @Mock
+    private LifecycleService lifecycleService;
 
     private RequestContext<List<MultipartReply>> currentRequestContext;
     private StatisticsManagerImpl statisticsManager;
@@ -162,7 +160,7 @@ public class StatisticsManagerImplTest {
         when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(Boolean.TRUE);
         when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
         when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
-        when(mockedDeviceInfo.getNodeId()).thenReturn(new NodeId("ofp-unit-dummy-node-id"));
+        when(mockedDeviceInfo.getNodeId()).thenReturn(NODE_ID);
 
         when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
@@ -185,9 +183,8 @@ public class StatisticsManagerImplTest {
                 Matchers.<StatisticsManagerControlService>any())).thenReturn(serviceControlRegistration);
 
         final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
-        statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, conductor, convertorManager);
+        statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, new HashedWheelTimer(), convertorManager);
         statisticsManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
-        when(conductor.getDeviceContext(deviceInfo)).thenReturn(mockedDeviceContext);
     }
 
     @Test
@@ -204,9 +201,12 @@ public class StatisticsManagerImplTest {
         }).when(outboundQueue)
                 .commitEntry(Matchers.anyLong(), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
 
+        Mockito.when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+        Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+
         statisticsManager.setDeviceInitializationPhaseHandler(mockedDevicePhaseHandler);
-        statisticsManager.onDeviceContextLevelUp(deviceInfo);
-        verify(mockedDevicePhaseHandler).onDeviceContextLevelUp(deviceInfo);
+        statisticsManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
+        verify(mockedDevicePhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
     }
 
     @Test
@@ -255,6 +255,10 @@ public class StatisticsManagerImplTest {
         when(itemLifeCycleRegistry.getLifeCycleSources()).thenReturn(
                 Collections.<ItemLifeCycleSource>emptyList());
 
+        when(statisticContext.gainDeviceContext()).thenReturn(mockedDeviceContext);
+        when(statisticContext.gainDeviceState()).thenReturn(mockedDeviceState);
+        when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
         getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
 
         final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
@@ -292,6 +296,10 @@ public class StatisticsManagerImplTest {
 
         getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
 
+        when(statisticContext.gainDeviceContext()).thenReturn(mockedDeviceContext);
+        when(statisticContext.gainDeviceState()).thenReturn(mockedDeviceState);
+        when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
         final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
                 new ChangeStatisticsWorkModeInputBuilder()
                         .setMode(StatisticsWorkMode.FULLYDISABLED);
@@ -328,6 +336,10 @@ public class StatisticsManagerImplTest {
 
         getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
 
+        when(statisticContext.gainDeviceContext()).thenReturn(mockedDeviceContext);
+        when(statisticContext.gainDeviceState()).thenReturn(mockedDeviceState);
+        when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
         final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
                 new ChangeStatisticsWorkModeInputBuilder()
                         .setMode(StatisticsWorkMode.FULLYDISABLED);
@@ -377,10 +389,8 @@ public class StatisticsManagerImplTest {
         statisticsManager.pollStatistics(mockedDeviceContext.getDeviceState(), statisticsContext, mockTimerCounter, mockedDeviceInfo);
         verify(mockedDeviceContext).getDeviceState();
 
-        when(mockedDeviceContext.getDeviceState().isValid()).thenReturn(true);
         statisticsManager.pollStatistics(mockedDeviceContext.getDeviceState(), statisticsContext, mockTimerCounter, mockedDeviceInfo);
 
-        when(mockedDeviceContext.getDeviceState().isStatisticsPollingEnabled()).thenReturn(true);
         statisticsManager.pollStatistics(mockedDeviceContext.getDeviceState(), statisticsContext, mockTimerCounter, mockedDeviceInfo);
 
         when(statisticsContext.gatherDynamicData()).thenReturn(Futures.immediateCheckedFuture(Boolean.TRUE));