-
/**
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
*/
package org.opendaylight.openflowplugin.impl.statistics;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.Timeout;
import java.lang.reflect.Field;
import java.math.BigInteger;
import java.util.Collections;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
+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.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.Timeout;
@RunWith(MockitoJUnitRunner.class)
private static final Logger LOG = LoggerFactory.getLogger(StatisticsManagerImplTest.class);
- private static final BigInteger DUMMY_DATAPATH_ID = new BigInteger("444");
- private static final Short DUMMY_VERSION = OFConstants.OFP_VERSION_1_3;
public static final NodeId NODE_ID = new NodeId("ofp-unit-dummy-node-id");
@Mock
@Mock
private DeviceManager deviceManager;
@Mock
- private LifecycleConductor conductor;
- @Mock
private GetFeaturesOutput featuresOutput;
@Mock
private DeviceInitializationPhaseHandler deviceInitializationPhaseHandler;
private DeviceInfo deviceInfo;
@Mock
private DataBroker dataBroker;
+ @Mock
+ private LifecycleService lifecycleService;
private RequestContext<List<MultipartReply>> currentRequestContext;
private StatisticsManagerImpl statisticsManager;
when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
- when(mockedDeviceInfo.getNodeId()).thenReturn(new NodeId("ofp-unit-dummy-node-id"));
+ when(mockedDeviceInfo.getNodeId()).thenReturn(NODE_ID);
when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
- when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker));
+ when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(OFConstants.OFP_VERSION_1_3, dataBroker, nodePath));
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
when(mockedDeviceContext.getMultiMsgCollector(
Matchers.<RequestContext<List<MultipartReply>>>any())).thenAnswer(
Matchers.eq(StatisticsManagerControlService.class),
Matchers.<StatisticsManagerControlService>any())).thenReturn(serviceControlRegistration);
- statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, conductor);
+ final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
+ final long basicTimerDelay = 3000L;
+ final long maximumTimerDelay = 900000L;
+ statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, new HashedWheelTimer(),
+ convertorManager, basicTimerDelay, maximumTimerDelay);
statisticsManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
- when(conductor.getDeviceContext(deviceInfo)).thenReturn(mockedDeviceContext);
}
@Test
}).when(outboundQueue)
.commitEntry(Matchers.anyLong(), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
+ Mockito.when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+ Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+
statisticsManager.setDeviceInitializationPhaseHandler(mockedDevicePhaseHandler);
- statisticsManager.onDeviceContextLevelUp(deviceInfo);
- verify(mockedDevicePhaseHandler).onDeviceContextLevelUp(deviceInfo);
+ statisticsManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
+ verify(mockedDevicePhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
}
@Test
statisticsManager.onDeviceContextLevelDown(deviceInfo);
verify(statisticContext).close();
verify(mockedTerminationPhaseHandler).onDeviceContextLevelDown(deviceInfo);
- Assert.assertEquals(0, contextsMap.size());
+ Assert.assertEquals(1, contextsMap.size());
}
private static Map<DeviceInfo, StatisticsContext> getContextsMap(final StatisticsManagerImpl statisticsManager)
when(itemLifeCycleRegistry.getLifeCycleSources()).thenReturn(
Collections.<ItemLifeCycleSource>emptyList());
+ when(statisticContext.gainDeviceContext()).thenReturn(mockedDeviceContext);
+ when(statisticContext.gainDeviceState()).thenReturn(mockedDeviceState);
+ when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
+ when(statisticContext.gainDeviceContext()).thenReturn(mockedDeviceContext);
+ when(statisticContext.gainDeviceState()).thenReturn(mockedDeviceState);
+ when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
new ChangeStatisticsWorkModeInputBuilder()
.setMode(StatisticsWorkMode.FULLYDISABLED);
getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
+ when(statisticContext.gainDeviceContext()).thenReturn(mockedDeviceContext);
+ when(statisticContext.gainDeviceState()).thenReturn(mockedDeviceState);
+ when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
new ChangeStatisticsWorkModeInputBuilder()
.setMode(StatisticsWorkMode.FULLYDISABLED);
public void testCalculateTimerDelay() throws Exception {
final TimeCounter timeCounter = Mockito.mock(TimeCounter.class);
when(timeCounter.getAverageTimeBetweenMarks()).thenReturn(2000L, (Long)4000L);
-
statisticsManager.calculateTimerDelay(timeCounter);
Assert.assertEquals(3000L, StatisticsManagerImpl.getCurrentTimerDelay());
statisticsManager.calculateTimerDelay(timeCounter);
statisticsManager.pollStatistics(mockedDeviceContext.getDeviceState(), statisticsContext, mockTimerCounter, mockedDeviceInfo);
verify(mockedDeviceContext).getDeviceState();
- when(mockedDeviceContext.getDeviceState().isValid()).thenReturn(true);
statisticsManager.pollStatistics(mockedDeviceContext.getDeviceState(), statisticsContext, mockTimerCounter, mockedDeviceInfo);
- when(mockedDeviceContext.getDeviceState().isStatisticsPollingEnabled()).thenReturn(true);
statisticsManager.pollStatistics(mockedDeviceContext.getDeviceState(), statisticsContext, mockTimerCounter, mockedDeviceInfo);
when(statisticsContext.gatherDynamicData()).thenReturn(Futures.immediateCheckedFuture(Boolean.TRUE));
statisticsManager.pollStatistics(mockedDeviceContext.getDeviceState(), statisticsContext, mockTimerCounter, mockedDeviceInfo);
Mockito.verify(mockTimerCounter,times(2)).addTimeMark();
}
-}
\ No newline at end of file
+}