/[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 958 - (hide annotations) (download)
Mon Jul 5 09:48:06 2010 UTC (13 years, 10 months ago) by torben
Original Path: android/TrainInfoService/src/dk/thoerup/traininfoservice/TestServlet.java
File size: 2517 byte(s)
Switch to servlet3.0 annotations
1 torben 735 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 torben 958 import javax.servlet.annotation.WebServlet;
9 torben 735 import javax.servlet.http.HttpServlet;
10     import javax.servlet.http.HttpServletRequest;
11     import javax.servlet.http.HttpServletResponse;
12    
13 torben 958 @WebServlet(urlPatterns={"/TestServlet"})
14 torben 735 public class TestServlet extends HttpServlet {
15     private static final long serialVersionUID = 1L;
16 torben 851
17     Random r = new Random();
18 torben 735
19 torben 852 //South-West corner= 54.5, 8.0
20 torben 853 //North-East corner= 57.8, 12.7
21     //Latitude span=3.3
22     //Longitude span=4.7
23 torben 851 void testFindNearest(int count) throws SQLException {
24 torben 735
25     StationDAO db = new StationDAO();
26    
27    
28 torben 736 for (int i=0; i<count; i++) {
29 torben 853 float lat = (r.nextFloat()*3.3F) + 54.5F;
30     float lng = (r.nextFloat()*4.7F) + 8.0F;
31 torben 735 db.getByLocation(lat, lng);
32     }
33    
34    
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 735 char c1 = ((char)r.nextInt(26));
44     c1 += 'a';
45     char c2 = ((char)r.nextInt(26)) ;
46     c2 += 'a';
47    
48     String search = "" + c1 + c2;
49     System.out.println(search);
50    
51     db.getByName(search);
52     }
53 torben 740 }
54    
55     void testFindFavorites(int count) throws SQLException {
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 torben 735
71    
72 torben 740 db.getByList(sb.toString());
73     }
74 torben 735 }
75    
76     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
77 torben 736
78    
79     String test = request.getParameter("test");
80     String strCount = request.getParameter("count");
81     int count = Integer.parseInt(strCount);
82    
83    
84 torben 735 try {
85     long start = System.currentTimeMillis();
86 torben 736
87     if ( test.equals("name") ) {
88     testFindName(count);
89     } else if ( test.equals("nearest") ) {
90     testFindNearest(count);
91 torben 740 } else if ( test.equals("favorites") ) {
92     testFindFavorites(count);
93 torben 736 } else {
94     throw new ServletException("No parameter test");
95     }
96    
97 torben 735 long stop = System.currentTimeMillis();
98    
99     long elapsed = stop-start;
100    
101 torben 736 float avg = ((float)elapsed) / count;
102 torben 735
103 torben 736 String out = "Count=" + count + "\n" +
104 torben 735 "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