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

Contents of /android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/TestServlet.java

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20