View Javadoc

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 2004 eBay, Inc.
20   */
21  package com.ebay.carad.os.vitalsigns.dao;
22  
23  import java.util.Random;
24  
25  import com.ebay.carad.os.vitalsigns.util.ITimeConstants;
26  
27  /***
28   * Factory capable of adding certain sets of data to a TestDataDAO for the purposes
29   * of unit testing.
30   * 
31   * TODO : fix up logging in this class
32   * 
33   * @author Jeremy Thomerson
34   * @version $Id$
35   */
36  public class TestDataDaoFactory {
37  
38      public static TestDataDao getTestDaoWithData() {
39          TestDataDao dao = new TestDataDao();
40          addIncreasingLine(dao, 1);
41          return dao;
42      }
43  
44      public static void addIncreasingLine(TestDataDao dao, int reportID) {
45          long time = System.currentTimeMillis();
46          int cnt = 0;
47          long lengthOfLine = (400 * ITimeConstants.DAY);
48          long millisBetweenPoints = (2 * ITimeConstants.HOUR);
49          int expectedCount = (int) (lengthOfLine / millisBetweenPoints);
50          long stop = (System.currentTimeMillis() - lengthOfLine);
51          while (time > stop) {
52              float data = (float) (1 - ((double) cnt / (double) expectedCount));
53  //            System.out.print(data + " ");
54              dao.storeData(time, data, new Integer(reportID));
55              time = time - millisBetweenPoints;
56              cnt++;
57          }
58  //        System.out.println();
59          System.out.println("expected count of: " + expectedCount + ", real count: " + cnt);
60      }
61      
62      public static void addAlternatingLine(TestDataDao dao, int reportID) {
63          long time = System.currentTimeMillis();
64          int cnt = 0;
65          long lengthOfLine = (400 * ITimeConstants.DAY);
66          long millisBetweenPoints = (2 * ITimeConstants.HOUR);
67          int expectedCount = (int) (lengthOfLine / millisBetweenPoints);
68          long stop = (System.currentTimeMillis() - lengthOfLine);
69          int currentValue = 1;
70          Random rand = new Random();
71          int iterationsLeftBeforeSwitch = rand.nextInt(24);
72          boolean goingUp = rand.nextBoolean();
73          while (time > stop) {
74              float data = currentValue;
75              currentValue = goingUp ? ++currentValue : --currentValue;
76              if (--iterationsLeftBeforeSwitch < 1) {
77                  goingUp = !goingUp;
78                  iterationsLeftBeforeSwitch = rand.nextInt(24);
79              }
80  //            System.out.print(data + " ");
81              dao.storeData(time, data, new Integer(reportID));
82              time = time - millisBetweenPoints;
83              cnt++;
84          }
85  //        System.out.println();
86          System.out.println("expected count of: " + expectedCount + ", real count: " + cnt);
87      }
88      
89      public static void main(String[] args) {
90          getTestDaoWithData();
91      }
92  
93  }
94