Unit test for AveragingProgressTracker class 97/52997/7
authormiroslav.kovac <miroslav.kovac@pantheon.tech>
Wed, 8 Mar 2017 12:03:38 +0000 (13:03 +0100)
committerTom Pantelis <tpanteli@brocade.com>
Thu, 9 Mar 2017 14:32:34 +0000 (14:32 +0000)
Change-Id: Ice50c174cfe365e171aef1b3c4485cf49356c534
Signed-off-by: miroslav.kovac <miroslav.kovac@pantheon.tech>
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AveragingProgressTrackerTest.java [new file with mode: 0644]

diff --git a/opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AveragingProgressTrackerTest.java b/opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AveragingProgressTrackerTest.java
new file mode 100644 (file)
index 0000000..fdaff6f
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.access.client;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class AveragingProgressTrackerTest {
+
+    private static final long NOW = 1000000000;
+    private static final long CHECKER = 500000000;
+    private ProgressTracker averagingProgressTracker;
+
+    @Before
+    public void setUp() {
+        averagingProgressTracker = new AveragingProgressTracker(4);
+        long delay = averagingProgressTracker.estimateIsolatedDelay(NOW);
+        assertEquals(0, delay);
+        for (int i = 0; i < 2; i++) {
+            delay = averagingProgressTracker.openTask(NOW);
+            assertEquals(0, delay);
+        }
+    }
+
+    @Test
+    public void estimateIsolatedDelayTest() {
+        long delay = averagingProgressTracker.openTask(NOW);
+        assertEquals(CHECKER, delay);
+
+        delay = averagingProgressTracker.openTask(NOW);
+        assertEquals(NOW, delay);
+
+        delay = averagingProgressTracker.estimateIsolatedDelay(NOW);
+        assertEquals(CHECKER, delay);
+
+        averagingProgressTracker.closeTask(3000000000L, 0, 0, 0);
+
+        delay = averagingProgressTracker.estimateIsolatedDelay(NOW);
+        assertEquals(0, delay);
+    }
+
+    @Test
+    public void copyObjectTest() {
+        final ProgressTracker copyAverageProgressTracker =
+                new AveragingProgressTracker((AveragingProgressTracker) averagingProgressTracker);
+        assertEquals(copyAverageProgressTracker.openTask(NOW), averagingProgressTracker.openTask(NOW));
+        assertEquals(averagingProgressTracker.tasksClosed(), copyAverageProgressTracker.tasksClosed());
+        assertEquals(averagingProgressTracker.tasksEncountered(), copyAverageProgressTracker.tasksEncountered());
+        assertEquals(averagingProgressTracker.tasksOpen(), copyAverageProgressTracker.tasksOpen());
+    }
+
+}
\ No newline at end of file

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.