/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/db/TestServlet.java
ViewVC logotype

Annotation of /android/TrainInfoService/src/dk/thoerup/traininfoservice/db/TestServlet.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1342 - (hide annotations) (download)
Wed Apr 20 15:31:47 2011 UTC (13 years, 1 month ago) by torben
File size: 2673 byte(s)
convert another system.out to logger
1 torben 1255 package dk.thoerup.traininfoservice.db;
2 torben 735
3     import java.io.IOException;
4     import java.sql.SQLException;
5     import java.util.Random;
6 torben 1342 import java.util.logging.Logger;
7 torben 735
8     import javax.servlet.ServletException;
9 torben 958 import javax.servlet.annotation.WebServlet;
10 torben 735 import javax.servlet.http.HttpServlet;
11     import javax.servlet.http.HttpServletRequest;
12     import javax.servlet.http.HttpServletResponse;
13    
14 torben 1255
15 torben 958 @WebServlet(urlPatterns={"/TestServlet"})
16 torben 735 public class TestServlet extends HttpServlet {
17     private static final long serialVersionUID = 1L;
18 torben 1342 Logger log = Logger.getLogger(TestServlet.class.getName());
19 torben 851
20     Random r = new Random();
21 torben 735
22 torben 852 //South-West corner= 54.5, 8.0
23 torben 853 //North-East corner= 57.8, 12.7
24     //Latitude span=3.3
25     //Longitude span=4.7
26 torben 851 void testFindNearest(int count) throws SQLException {
27 torben 735
28     StationDAO db = new StationDAO();
29    
30    
31 torben 736 for (int i=0; i<count; i++) {
32 torben 853 float lat = (r.nextFloat()*3.3F) + 54.5F;
33     float lng = (r.nextFloat()*4.7F) + 8.0F;
34 torben 735 db.getByLocation(lat, lng);
35     }
36     }
37    
38 torben 736 void testFindName(int count) throws SQLException {
39 torben 735
40     StationDAO db = new StationDAO();
41    
42 torben 736 for (int i=0; i<count; i++) {
43 torben 1256 char c1 = getRandomCharacter();
44     char c2 = getRandomCharacter();
45 torben 735
46     String search = "" + c1 + c2;
47 torben 1342 log.info(search);
48 torben 735
49     db.getByName(search);
50     }
51 torben 740 }
52 torben 1256
53     private char getRandomCharacter() {
54     char c1 = ((char)r.nextInt(26));
55     c1 += 'a';
56     return c1;
57     }
58 torben 740
59     void testFindFavorites(int count) throws SQLException {
60    
61     StationDAO db = new StationDAO();
62    
63     for (int i=0; i<count; i++) {
64     final int MAX = 8;
65    
66     StringBuilder sb = new StringBuilder();
67     sb.append('(');
68     for (int j=0; j<MAX;j++) {
69     if (j>0)
70     sb.append(',');
71     sb.append(r.nextInt(400));
72     }
73     sb.append(')');
74 torben 735
75    
76 torben 740 db.getByList(sb.toString());
77     }
78 torben 735 }
79    
80     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
81 torben 736
82    
83     String test = request.getParameter("test");
84     String strCount = request.getParameter("count");
85     int count = Integer.parseInt(strCount);
86    
87    
88 torben 735 try {
89     long start = System.currentTimeMillis();
90 torben 736
91     if ( test.equals("name") ) {
92     testFindName(count);
93     } else if ( test.equals("nearest") ) {
94     testFindNearest(count);
95 torben 740 } else if ( test.equals("favorites") ) {
96     testFindFavorites(count);
97 torben 736 } else {
98     throw new ServletException("No parameter test");
99     }
100    
101 torben 735 long stop = System.currentTimeMillis();
102    
103     long elapsed = stop-start;
104    
105 torben 736 float avg = ((float)elapsed) / count;
106 torben 735
107 torben 736 String out = "Count=" + count + "\n" +
108 torben 735 "Elapsed=" + elapsed + "\n" +
109     "Avg.=" + avg;
110    
111     response.getWriter().print( out );
112    
113    
114     } catch (Exception e) {
115     throw new ServletException(e);
116     }
117     }
118    
119     }

  ViewVC Help
Powered by ViewVC 1.1.20