X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2FStatisticsContextImplParamTest.java;h=fade81a4c1cab4ddfc771d55f1c8c03a110f8643;hb=6916d4f22823d56b391d0d45cb8544260def3431;hp=445265bb952e6c7680ec9bab3c7f953ba4e96e9a;hpb=ddf1b1a5e0f3d401f562945ceb473570641fb45e;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 445265bb95..fade81a4c1 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 @@ -9,20 +9,21 @@ 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.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.common.util.concurrent.ListenableFuture; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.concurrent.ExecutionException; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.mockito.Matchers; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier; +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; @@ -34,8 +35,9 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder; public class StatisticsContextImplParamTest extends StatisticsContextImpMockInitiation { - 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; @@ -57,32 +59,39 @@ public class StatisticsContextImplParamTest extends StatisticsContextImpMockInit }); } - - - @Test - public void gatherDynamicDataTest() { + public void gatherDynamicDataTest() throws InterruptedException { + + 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(mockedDeviceInfo, false, mockConductor, convertorManager); + final StatisticsContextImpl statisticsContext = new StatisticsContextImpl<>( + mockedDeviceContext, convertorManager, + MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext), + true, false, 3000, 50000); - final ListenableFuture>> rpcResult = immediateFuture(RpcResultBuilder.success(Collections.emptyList()).build()); + 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(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class)); + verify(mockedStatisticsOnFlyGatheringService) + .getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class)); } }