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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 740 - (show annotations) (download)
Wed May 19 11:14:33 2010 UTC (14 years ago) by torben
File size: 2483 byte(s)
Add test for findByFavorites
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 //South-West corner= 54.0, 7.0
17 //North-East corner= 58.0, 13.0
18 //Latitude span=4.0
19 //Longitude span=6.0
20 void testFindNearest(int count) throws SQLException {
21 Random r = new Random();
22
23 StationDAO db = new StationDAO();
24
25
26 for (int i=0; i<count; i++) {
27 float lat = (r.nextFloat()*4.0F) + 54.0F;
28 float lng = (r.nextFloat()*6.0F) + 7.0F;
29 db.getByLocation(lat, lng);
30 }
31
32
33
34 }
35
36 void testFindName(int count) throws SQLException {
37 Random r = new Random();
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 Random r = new Random();
56
57 StationDAO db = new StationDAO();
58
59 for (int i=0; i<count; i++) {
60 final int MAX = 8;
61
62 StringBuilder sb = new StringBuilder();
63 sb.append('(');
64 for (int j=0; j<MAX;j++) {
65 if (j>0)
66 sb.append(',');
67 sb.append(r.nextInt(400));
68 }
69 sb.append(')');
70
71
72 db.getByList(sb.toString());
73 }
74 }
75
76 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
77
78
79 String test = request.getParameter("test");
80 String strCount = request.getParameter("count");
81 int count = Integer.parseInt(strCount);
82
83
84 try {
85 long start = System.currentTimeMillis();
86
87 if ( test.equals("name") ) {
88 testFindName(count);
89 } else if ( test.equals("nearest") ) {
90 testFindNearest(count);
91 } else if ( test.equals("favorites") ) {
92 testFindFavorites(count);
93 } else {
94 throw new ServletException("No parameter test");
95 }
96
97 long stop = System.currentTimeMillis();
98
99 long elapsed = stop-start;
100
101 float avg = ((float)elapsed) / count;
102
103 String out = "Count=" + count + "\n" +
104 "Elapsed=" + elapsed + "\n" +
105 "Avg.=" + avg;
106
107 response.getWriter().print( out );
108
109
110 } catch (Exception e) {
111 throw new ServletException(e);
112 }
113 }
114
115 }

  ViewVC Help
Powered by ViewVC 1.1.20