when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(Boolean.TRUE);
- when(mockedDeviceState.getFeatures()).thenReturn(featuresOutput);
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
+ when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
when(deviceInfo.getNodeId()).thenReturn(NODE_ID);
- when(mockedDeviceState.getNodeId()).thenReturn(NODE_ID);
+ when(mockedDeviceContext.getDeviceInfo()).thenReturn(deviceInfo);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl());
statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, conductor);
statisticsManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
- when(deviceManager.getDeviceContextFromNodeId(Mockito.<NodeId>any())).thenReturn(mockedDeviceContext);
- when(conductor.getDeviceContext(Mockito.<NodeId>any())).thenReturn(mockedDeviceContext);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(mockedDeviceContext);
+ when(conductor.getDeviceContext(deviceInfo)).thenReturn(mockedDeviceContext);
}
@Test
@Test
public void testOnDeviceContextClosed() throws Exception {
final StatisticsContext statisticContext = Mockito.mock(StatisticsContext.class);
- final Map<NodeId, StatisticsContext> contextsMap = getContextsMap(statisticsManager);
+ final Map<DeviceInfo, StatisticsContext> contextsMap = getContextsMap(statisticsManager);
- contextsMap.put(deviceInfo.getNodeId(), statisticContext);
+ contextsMap.put(deviceInfo, statisticContext);
Assert.assertEquals(1, contextsMap.size());
statisticsManager.setDeviceTerminationPhaseHandler(mockedTerminationPhaseHandler);
- statisticsManager.onDeviceContextLevelDown(mockedDeviceContext);
+ statisticsManager.onDeviceContextLevelDown(deviceInfo);
verify(statisticContext).close();
- verify(mockedTerminationPhaseHandler).onDeviceContextLevelDown(mockedDeviceContext);
+ verify(mockedTerminationPhaseHandler).onDeviceContextLevelDown(deviceInfo);
Assert.assertEquals(0, contextsMap.size());
}
- private static Map<NodeId, StatisticsContext> getContextsMap(final StatisticsManagerImpl statisticsManager)
+ private static Map<DeviceInfo, StatisticsContext> getContextsMap(final StatisticsManagerImpl statisticsManager)
throws NoSuchFieldException, IllegalAccessException {
// HACK: contexts map for testing shall be accessed in some more civilized way
final Field contextsField = StatisticsManagerImpl.class.getDeclaredField("contexts");
Assert.assertNotNull(contextsField);
contextsField.setAccessible(true);
- return (Map<NodeId, StatisticsContext>) contextsField.get(statisticsManager);
+ return (Map<DeviceInfo, StatisticsContext>) contextsField.get(statisticsManager);
}
@Test
when(itemLifeCycleRegistry.getLifeCycleSources()).thenReturn(
Collections.<ItemLifeCycleSource>emptyList());
- getContextsMap(statisticsManager).put(deviceInfo.getNodeId(), statisticContext);
+ getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
new ChangeStatisticsWorkModeInputBuilder()
when(itemLifeCycleRegistry.getLifeCycleSources()).thenReturn(
Collections.singletonList(itemLifecycleSource));
- getContextsMap(statisticsManager).put(deviceInfo.getNodeId(), statisticContext);
+ getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
new ChangeStatisticsWorkModeInputBuilder()
when(itemLifeCycleRegistry.getLifeCycleSources()).thenReturn(
Collections.singletonList(itemLifecycleSource));
- getContextsMap(statisticsManager).put(deviceInfo.getNodeId(), statisticContext);
+ getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
new ChangeStatisticsWorkModeInputBuilder()
@Test
public void testCalculateTimerDelay() throws Exception {
final TimeCounter timeCounter = Mockito.mock(TimeCounter.class);
- when(timeCounter.getAverageTimeBetweenMarks()).thenReturn((Long)2000L, (Long)4000L);
+ when(timeCounter.getAverageTimeBetweenMarks()).thenReturn(2000L, (Long)4000L);
statisticsManager.calculateTimerDelay(timeCounter);
Assert.assertEquals(3000L, StatisticsManagerImpl.getCurrentTimerDelay());
final TimeCounter mockTimerCounter = Mockito.mock(TimeCounter.class);
statisticsManager.pollStatistics(mockedDeviceContext, statisticsContext, mockTimerCounter);
- verify(mockedDeviceContext).getDeviceState();
+ verify(mockedDeviceContext).getDeviceInfo();
when(mockedDeviceContext.getDeviceState().isValid()).thenReturn(true);
statisticsManager.pollStatistics(mockedDeviceContext, statisticsContext, mockTimerCounter);