1 |
package dk.thoerup.traininfoservice; |
package dk.thoerup.traininfoservice.db; |
2 |
|
|
3 |
import java.io.IOException; |
import java.io.IOException; |
4 |
import java.sql.SQLException; |
import java.sql.SQLException; |
5 |
import java.util.Random; |
import java.util.Random; |
6 |
|
import java.util.logging.Logger; |
7 |
|
|
8 |
import javax.servlet.ServletException; |
import javax.servlet.ServletException; |
9 |
|
import javax.servlet.annotation.WebServlet; |
10 |
import javax.servlet.http.HttpServlet; |
import javax.servlet.http.HttpServlet; |
11 |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletRequest; |
12 |
import javax.servlet.http.HttpServletResponse; |
import javax.servlet.http.HttpServletResponse; |
13 |
|
|
14 |
|
|
15 |
|
@WebServlet(urlPatterns={"/TestServlet"}) |
16 |
public class TestServlet extends HttpServlet { |
public class TestServlet extends HttpServlet { |
17 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
18 |
|
Logger log = Logger.getLogger(TestServlet.class.getName()); |
19 |
|
|
20 |
|
Random r = new Random(); |
21 |
|
|
22 |
//South-West corner= 54.0, 7.0 |
//South-West corner= 54.5, 8.0 |
23 |
//North-East corner= 58.0, 13.0 |
//North-East corner= 57.8, 12.7 |
24 |
//Latitude span=4.0 |
//Latitude span=3.3 |
25 |
//Longitude span=6.0 |
//Longitude span=4.7 |
26 |
void testFindNearest(int count) throws SQLException { |
void testFindNearest(int count) throws SQLException { |
|
Random r = new Random(); |
|
27 |
|
|
28 |
StationDAO db = new StationDAO(); |
StationDAO db = new StationDAO(); |
29 |
|
|
30 |
|
|
31 |
for (int i=0; i<count; i++) { |
for (int i=0; i<count; i++) { |
32 |
float lat = (r.nextFloat()*4.0F) + 54.0F; |
float lat = (r.nextFloat()*3.3F) + 54.5F; |
33 |
float lng = (r.nextFloat()*6.0F) + 7.0F; |
float lng = (r.nextFloat()*4.7F) + 8.0F; |
34 |
db.getByLocation(lat, lng); |
db.getByLocation(lat, lng); |
35 |
} |
} |
|
|
|
|
|
|
|
|
|
36 |
} |
} |
37 |
|
|
38 |
void testFindName(int count) throws SQLException { |
void testFindName(int count) throws SQLException { |
|
Random r = new Random(); |
|
39 |
|
|
40 |
StationDAO db = new StationDAO(); |
StationDAO db = new StationDAO(); |
41 |
|
|
42 |
for (int i=0; i<count; i++) { |
for (int i=0; i<count; i++) { |
43 |
char c1 = ((char)r.nextInt(26)); |
char c1 = getRandomCharacter(); |
44 |
c1 += 'a'; |
char c2 = getRandomCharacter(); |
|
char c2 = ((char)r.nextInt(26)) ; |
|
|
c2 += 'a'; |
|
45 |
|
|
46 |
String search = "" + c1 + c2; |
String search = "" + c1 + c2; |
47 |
System.out.println(search); |
log.info(search); |
48 |
|
|
49 |
db.getByName(search); |
db.getByName(search); |
50 |
} |
} |
51 |
|
} |
52 |
|
|
53 |
|
private char getRandomCharacter() { |
54 |
|
char c1 = ((char)r.nextInt(26)); |
55 |
|
c1 += 'a'; |
56 |
|
return c1; |
57 |
|
} |
58 |
|
|
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 |
|
|
75 |
|
|
76 |
|
db.getByList(sb.toString()); |
77 |
|
} |
78 |
} |
} |
79 |
|
|
80 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
92 |
testFindName(count); |
testFindName(count); |
93 |
} else if ( test.equals("nearest") ) { |
} else if ( test.equals("nearest") ) { |
94 |
testFindNearest(count); |
testFindNearest(count); |
95 |
|
} else if ( test.equals("favorites") ) { |
96 |
|
testFindFavorites(count); |
97 |
} else { |
} else { |
98 |
throw new ServletException("No parameter test"); |
throw new ServletException("No parameter test"); |
99 |
} |
} |