1 /*
2 * The contents of this file are subject to the terms
3 * of the Common Development and Distribution License
4 * (the "License"). You may not use this file except
5 * in compliance with the License.
6 *
7 * You can obtain a copy of the license at
8 * http://www.sun.com/cddl/cddl.html.
9 * See the License for the specific language governing
10 * permissions and limitations under the License.
11 *
12 * When distributing Covered Code, include this CDDL
13 * HEADER in each file and include the License file at
14 * license.txt. If applicable, add the following below
15 * this CDDL HEADER, with the fields enclosed by brackets
16 * "[]" replaced with your own identifying information:
17 * Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * Portions Copyright 2006 eBay, Inc.
20 */
21
22 package com.ebay.carad.os.vitalsigns;
23
24 import com.ebay.carad.os.vitalsigns.util.ITimeConstants;
25
26 import junit.framework.TestCase;
27
28 /***
29 * @author Jeremy Thomerson
30 * @version $Id$
31 */
32 public class DashboardReportTest extends TestCase {
33
34 private static class TestDataRetriever implements IDataRetriever {
35 private int mInvocationCount = 0;
36 public Float getData(IDashboardAgent agent) {
37 mInvocationCount++;
38 return IDataRetriever.ZERO;
39 }
40 public int getInvocationCount() {
41 return mInvocationCount;
42 }
43 public Object clone() throws CloneNotSupportedException {
44 return super.clone();
45 }
46 }
47 public void testRunFrequency() throws Exception {
48 IDashboardAgent agent = new DashboardAgent();
49 TestDataRetriever dr = new TestDataRetriever();
50
51 DashboardReport rep = new DashboardReport();
52 rep.setFrequencyInMinutes(397);
53 // 397 chosen because it's large and prime - less likely to generate error described below
54 rep.setDataRetriever(dr);
55
56 assertEquals(0, dr.getInvocationCount());
57 rep.run(agent, System.currentTimeMillis());
58 assertEquals(1, dr.getInvocationCount());
59
60 rep.run(agent, System.currentTimeMillis());
61 // should still be one, because it should not have invoked the second time
62 // TODO : this test is buggy, and generates occasional failures, likely
63 // having to do with current minute % frequency == 0
64 assertEquals(1, dr.getInvocationCount());
65
66 long time = ((rep.getFrequencyInMinutes() + 13) * ITimeConstants.MINUTE);
67 rep.run(agent, System.currentTimeMillis() + time);
68 assertEquals(2, dr.getInvocationCount());
69 rep.run(agent, System.currentTimeMillis() + time);
70 // should still be one, because it should not have invoked the second time
71 assertEquals(2, dr.getInvocationCount());
72 }
73
74 }