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;
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;
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);
}
/**
- * 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();
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);