2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl.statistics;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * Test for {@link TimeCounter}.
20 public class TimeCounterTest {
22 private static final Logger LOG = LoggerFactory.getLogger(TimeCounterTest.class);
23 private TimeCounter timeCounter;
26 public void setUp() throws Exception {
27 timeCounter = new TimeCounter();
36 * awaited average time:
41 * But this times are only theoretical if whole test is executed without latency and atomically. Therefore awaited
42 * average times can't be compared to exact values of awaited average time (therefore == was replaced with >=)
46 public void testGetAverageTimeBetweenMarks() throws Exception {
47 Assert.assertEquals(0, timeCounter.getAverageTimeBetweenMarks());
48 timeCounter.markStart();
49 Assert.assertEquals(0, timeCounter.getAverageTimeBetweenMarks());
52 timeCounter.addTimeMark();
53 Assert.assertTrue(timeCounter.getAverageTimeBetweenMarks() >= 2);
56 timeCounter.addTimeMark();
57 Assert.assertTrue(timeCounter.getAverageTimeBetweenMarks() >= 2);
60 timeCounter.addTimeMark();
61 Assert.assertTrue(timeCounter.getAverageTimeBetweenMarks() >= 3);
64 private void zzz(long length) {
67 } catch (InterruptedException e) {
68 LOG.error("processing sleep interrupted", e);