X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2FStatisticsContextImplTest.java;h=cebe9bfb2c0cbccbeaeab6b7c13a0b29c69ce0d6;hb=af3dd0d3e6d3eef07ab4a9399406c7708a55fe49;hp=2bebe44a60029e867586b09bd611b0bbfff25fe9;hpb=6e2627630ebabb37526133a13deeb62adcc85d35;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java index 2bebe44a60..cebe9bfb2c 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java @@ -1,27 +1,22 @@ /* + * 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 org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -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.Futures; -import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; import java.util.Collections; -import java.util.concurrent.ExecutionException; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -29,11 +24,12 @@ import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; -import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; 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; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -46,17 +42,24 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio private static final Logger LOG = LoggerFactory.getLogger(StatisticsContextImplTest.class); private static final Long TEST_XID = 55L; - private StatisticsContextImpl statisticsContext; + private StatisticsContextImpl statisticsContext; + private ConvertorManager convertorManager; @Before public void setUp() throws Exception { - when(mockedDeviceContext.reserveXidForDeviceMessage()).thenReturn(TEST_XID); - when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext); + convertorManager = ConvertorManagerFactory.createDefaultManager(); + when(mockedDeviceInfo.reserveXidForDeviceMessage()).thenReturn(TEST_XID); + Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState); initStatisticsContext(); } private void initStatisticsContext() { - statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor); + statisticsContext = new StatisticsContextImpl<>(mockedDeviceContext, convertorManager, + MultipartWriterProviderFactory + .createDefaultProvider(mockedDeviceContext), + MoreExecutors.newDirectExecutorService(), true, false, 3000, + 50000); + statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService); statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService); } @@ -70,11 +73,21 @@ 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 statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor); + final StatisticsContextImpl statisticsContext = + new StatisticsContextImpl<>(mockedDeviceContext, + convertorManager, + MultipartWriterProviderFactory + .createDefaultProvider(mockedDeviceContext), + MoreExecutors.newDirectExecutorService(), + true, + false, + 3000,50000); + final RequestContext requestContext = statisticsContext.createRequestContext(); statisticsContext.close(); try { @@ -90,9 +103,7 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio @Test public void testGatherDynamicData_none() throws Exception { - final ListenableFuture gatheringResult = statisticsContext.gatherDynamicData(); - Assert.assertTrue(gatheringResult.isDone()); - Assert.assertTrue(gatheringResult.get()); + statisticsContext.instantiateServiceInstance(); Mockito.verifyNoMoreInteractions(mockedStatisticsGatheringService, mockedStatisticsOnFlyGatheringService); } @@ -105,62 +116,27 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio when(mockedDeviceState.isMetersAvailable()).thenReturn(Boolean.TRUE); when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(Boolean.TRUE); when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(Boolean.TRUE); - when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(dummyNodeII); + 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.emptyList()).build()) - ); - when(mockedStatisticsOnFlyGatheringService.getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class))) - .thenReturn( - Futures.immediateFuture(RpcResultBuilder.success(Collections.emptyList()).build()) - ); - - final ListenableFuture gatheringResult = statisticsContext.gatherDynamicData(); - Assert.assertTrue(gatheringResult.isDone()); - Assert.assertTrue(gatheringResult.get()); + when(mockedStatisticsGatheringService + .getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class))) + .thenReturn(Futures.immediateFuture( + RpcResultBuilder.success(Collections.emptyList()).build())); + when(mockedStatisticsOnFlyGatheringService + .getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class))) + .thenReturn(Futures.immediateFuture( + RpcResultBuilder.success(Collections.emptyList()).build())); + + statisticsContext.registerMastershipWatcher(mockedMastershipWatcher); + statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService); + statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService); + statisticsContext.instantiateServiceInstance(); + verify(mockedStatisticsGatheringService, times(7)) .getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class)); verify(mockedStatisticsOnFlyGatheringService) .getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class)); Mockito.verifyNoMoreInteractions(mockedStatisticsGatheringService, mockedStatisticsOnFlyGatheringService); } - - @Test - public void testDeviceConnectionCheck_WORKING() throws Exception { - final ListenableFuture deviceConnectionCheckResult = statisticsContext.deviceConnectionCheck(); - Assert.assertNull(deviceConnectionCheckResult); - } - - @Test - public void testDeviceConnectionCheck_RIP() throws Exception { - Mockito.reset(mockedConnectionContext); - when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.RIP); - final ListenableFuture deviceConnectionCheckResult = statisticsContext.deviceConnectionCheck(); - Assert.assertNotNull(deviceConnectionCheckResult); - Assert.assertTrue(deviceConnectionCheckResult.isDone()); - try { - deviceConnectionCheckResult.get(); - Assert.fail("connection in state RIP should have caused exception here"); - } catch (final Exception e) { - LOG.debug("expected behavior for RIP connection achieved"); - Assert.assertTrue(e instanceof ExecutionException); - } - } - - @Test - public void testDeviceConnectionCheck_HANSHAKING() throws Exception { - Mockito.reset(mockedConnectionContext); - when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.HANDSHAKING); - final ListenableFuture deviceConnectionCheckResult = statisticsContext.deviceConnectionCheck(); - Assert.assertNotNull(deviceConnectionCheckResult); - Assert.assertTrue(deviceConnectionCheckResult.isDone()); - try { - final Boolean checkPositive = deviceConnectionCheckResult.get(); - Assert.assertTrue(checkPositive); - } catch (final Exception e) { - Assert.fail("connection in state HANDSHAKING should NOT have caused exception here"); - } - } }