OPNFLWPLUG-981: per-capability configuration for stats polling
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / StatisticsContextImplTest.java
index 23a0621049191a059d38c6ccc967c13668d77146..509f5ad7b19720586330631b7ad39e0d7e4e55d9 100644 (file)
@@ -22,6 +22,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Matchers;
+import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
@@ -31,6 +32,8 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorM
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint32Type;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
@@ -44,22 +47,35 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio
     private static final Long TEST_XID = 55L;
     private StatisticsContextImpl<MultipartReply> statisticsContext;
     private ConvertorManager convertorManager;
+    @Mock
+    private OpenflowProviderConfig config =
+            Mockito.mock(OpenflowProviderConfig.class);
 
     @Before
     public void setUp() throws Exception {
         convertorManager = ConvertorManagerFactory.createDefaultManager();
         when(mockedDeviceInfo.reserveXidForDeviceMessage()).thenReturn(TEST_XID);
         Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+        Mockito.when(config.isIsTableStatisticsPollingOn()).thenReturn(true);
+        Mockito.when(config.isIsFlowStatisticsPollingOn()).thenReturn(true);
+        Mockito.when(config.isIsGroupStatisticsPollingOn()).thenReturn(true);
+        Mockito.when(config.isIsMeterStatisticsPollingOn()).thenReturn(true);
+        Mockito.when(config.isIsPortStatisticsPollingOn()).thenReturn(true);
+        Mockito.when(config.isIsQueueStatisticsPollingOn()).thenReturn(true);
+        Mockito.when(config.getBasicTimerDelay()).thenReturn(new NonZeroUint32Type(3000L));
+        Mockito.when(config.getMaximumTimerDelay()).thenReturn(new NonZeroUint32Type(50000L));
+
         initStatisticsContext();
     }
 
     private void initStatisticsContext() {
-        statisticsContext = new StatisticsContextImpl<>(
-                mockedDeviceContext, convertorManager,
-                MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext),
+        statisticsContext = new StatisticsContextImpl<>(mockedDeviceContext, convertorManager,
+                MultipartWriterProviderFactory
+                        .createDefaultProvider(mockedDeviceContext),
                 MoreExecutors.newDirectExecutorService(),
+                config,
                 true,
-                false, 3000, 50000);
+                false);
 
         statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
         statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
@@ -74,15 +90,20 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio
     }
 
     /**
-     * There is nothing to check in close method
+     * There is nothing to check in close method.
      */
     @Test
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void testClose() throws Exception {
-        final StatisticsContextImpl<MultipartReply> statisticsContext = new StatisticsContextImpl<>(
-                mockedDeviceContext, convertorManager,
-                MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext),
-                MoreExecutors.newDirectExecutorService(),
-                true, false, 3000, 50000);
+        statisticsContext =
+                new StatisticsContextImpl<>(mockedDeviceContext,
+                        convertorManager,
+                        MultipartWriterProviderFactory
+                                .createDefaultProvider(mockedDeviceContext),
+                        MoreExecutors.newDirectExecutorService(),
+                        config,
+                        true,
+                        false);
 
         final RequestContext<Object> requestContext = statisticsContext.createRequestContext();
         statisticsContext.close();
@@ -115,18 +136,14 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio
         when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(DUMMY_NODE_ID);
         initStatisticsContext();
 
-        when(mockedStatisticsGatheringService.getStatisticsOfType(Matchers.any(EventIdentifier.class),
-                    Matchers.any(MultipartType.class)))
-                .thenReturn(
-                        Futures.immediateFuture(RpcResultBuilder.success(Collections.<MultipartReply>emptyList())
-                            .build())
-                );
-        when(mockedStatisticsOnFlyGatheringService.getStatisticsOfType(Matchers.any(EventIdentifier.class),
-                    Matchers.any(MultipartType.class)))
-                .thenReturn(
-                        Futures.immediateFuture(RpcResultBuilder.success(Collections.<MultipartReply>emptyList())
-                            .build())
-                );
+        when(mockedStatisticsGatheringService
+                     .getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class)))
+                .thenReturn(Futures.immediateFuture(
+                        RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build()));
+        when(mockedStatisticsOnFlyGatheringService
+                     .getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class)))
+                .thenReturn(Futures.immediateFuture(
+                        RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build()));
 
         statisticsContext.registerMastershipWatcher(mockedMastershipWatcher);
         statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);