Redesign statistics context and manager
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / StatisticsPollingServiceTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.impl.statistics;
10
11 import static org.mockito.Mockito.verify;
12 import static org.mockito.Mockito.when;
13
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import java.util.function.Supplier;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.runners.MockitoJUnitRunner;
22
23 @RunWith(MockitoJUnitRunner.class)
24 public class StatisticsPollingServiceTest {
25     @Mock
26     private TimeCounter timeCounter;
27     @Mock
28     private Supplier<ListenableFuture<Boolean>> gatheringSupplier;
29
30     private StatisticsPollingService statisticsPollingService;
31
32     @Before
33     public void setUp() throws Exception {
34         when(timeCounter.getAverageTimeBetweenMarks()).thenReturn(15000L);
35         when(gatheringSupplier.get()).thenReturn(Futures.immediateFuture(true));
36         statisticsPollingService = new StatisticsPollingService(
37                 timeCounter, 10000, 12000,
38                 gatheringSupplier);
39     }
40
41     @Test
42     public void startUp() throws Exception {
43         statisticsPollingService.startUp();
44         verify(timeCounter).markStart();
45     }
46
47     @Test
48     public void runOneIteration() throws Exception {
49         statisticsPollingService.runOneIteration();
50         verify(gatheringSupplier).get();
51         verify(timeCounter).addTimeMark();
52     }
53
54     @Test
55     public void scheduler() throws Exception {
56         statisticsPollingService.scheduler();
57         verify(timeCounter).getAverageTimeBetweenMarks();
58     }
59
60 }