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;
27 timeCounter = new TimeCounter();
35 * awaited average time:
39 * But this times are only theoretical if whole test is executed without latency and atomically. Therefore awaited
40 * average times can't be compared to exact values of awaited average time (therefore == was replaced with >=)
41 * @throws Exception if interrupted
44 public void testGetAverageTimeBetweenMarks() {
45 Assert.assertEquals(0, timeCounter.getAverageTimeBetweenMarks());
46 timeCounter.markStart();
47 Assert.assertEquals(0, timeCounter.getAverageTimeBetweenMarks());
50 timeCounter.addTimeMark();
51 Assert.assertTrue(timeCounter.getAverageTimeBetweenMarks() >= 2);
54 timeCounter.addTimeMark();
55 Assert.assertTrue(timeCounter.getAverageTimeBetweenMarks() >= 2);
58 timeCounter.addTimeMark();
59 Assert.assertTrue(timeCounter.getAverageTimeBetweenMarks() >= 3);
62 private static void zzz(long length) {
65 } catch (InterruptedException e) {
66 LOG.error("processing sleep interrupted", e);