X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2FStatisticsContextImplParamTest.java;h=915dd009383273660d6cf17be0a4ac33bb7577ae;hb=3a44a80f20e2ad3b9683a8ef2c459f96a86c53fb;hp=22e5bc44dd914a36eb5117aba0caa099be3a5803;hpb=1f2f4d39bcd7b0fc141a593d0e03cc62cc0abfc8;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplParamTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplParamTest.java index 22e5bc44dd..915dd00938 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplParamTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplParamTest.java @@ -1,43 +1,51 @@ /* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * - * * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * * - * * This program and the accompanying materials are made available under the - * * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.openflowplugin.impl.statistics; import static com.google.common.util.concurrent.Futures.immediateFuture; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.concurrent.ExecutionException; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.mockito.Mock; import org.mockito.Mockito; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +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; @RunWith(Parameterized.class) public class StatisticsContextImplParamTest extends StatisticsContextImpMockInitiation { + @Mock + private OpenflowProviderConfig config = mock(OpenflowProviderConfig.class); - public StatisticsContextImplParamTest(final boolean isTable, final boolean isFlow, final boolean isGroup, final boolean isMeter, final boolean isPort, - final boolean isQueue) { + public StatisticsContextImplParamTest(final boolean isTable, final boolean isFlow, + final boolean isGroup, final boolean isMeter, + final boolean isPort, final boolean isQueue) { super(); this.isTable = isTable; this.isFlow = isFlow; @@ -59,32 +67,54 @@ public class StatisticsContextImplParamTest extends StatisticsContextImpMockInit }); } - - + @Before + public void setUp() { + 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)); + } @Test public void gatherDynamicDataTest() { - - final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceContext.getDeviceState().getNodeId(), false, mockConductor); - - final ListenableFuture>> rpcResult = immediateFuture(RpcResultBuilder.success(Collections.emptyList()).build()); + when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(Boolean.TRUE); + when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(Boolean.TRUE); + when(mockedDeviceState.isGroupAvailable()).thenReturn(Boolean.TRUE); + when(mockedDeviceState.isMetersAvailable()).thenReturn(Boolean.TRUE); + when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(Boolean.TRUE); + when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(Boolean.TRUE); + when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState); + + final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager(); + final StatisticsContextImpl statisticsContext = new StatisticsContextImpl<>( + mockedDeviceContext, convertorManager, + MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext), + MoreExecutors.newDirectExecutorService(), + config, + true, + false); + + final ListenableFuture>> rpcResult = immediateFuture(RpcResultBuilder + .success(Collections.emptyList()).build()); when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType .class))).thenReturn(rpcResult); when(mockedStatisticsOnFlyGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType .class))).thenReturn(rpcResult); + statisticsContext.registerMastershipWatcher(mockedMastershipWatcher); statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService); statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService); + statisticsContext.instantiateServiceInstance(); - final ListenableFuture futureResult = statisticsContext.gatherDynamicData(); - - try { - assertTrue(futureResult.get()); - } catch (InterruptedException | ExecutionException e) { - fail("Exception wasn't expected."); - } - + verify(mockedStatisticsGatheringService, times(7)) + .getStatisticsOfType(any(EventIdentifier.class), any(MultipartType.class)); + verify(mockedStatisticsOnFlyGatheringService) + .getStatisticsOfType(any(EventIdentifier.class), any(MultipartType.class)); } }