Changeset 554 for trunk/quest-ui-core
- Timestamp:
- 08/16/12 17:08:27 (12 years ago)
- Location:
- trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/plugin/php
- Files:
-
- 2 added
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/plugin/php/WeblogParser.java
r488 r554 16 16 import java.util.Set; 17 17 18 import de.ugoe.cs.quest.plugin.php.eventcore.WebEvent; 18 import de.ugoe.cs.quest.eventcore.Event; 19 import de.ugoe.cs.quest.eventcore.IEventTarget; 20 import de.ugoe.cs.quest.eventcore.IEventType; 21 import de.ugoe.cs.quest.plugin.php.eventcore.PHPEventTarget; 22 import de.ugoe.cs.quest.plugin.php.eventcore.PHPEventType; 23 import de.ugoe.cs.quest.plugin.php.eventcore.WebRequest; 19 24 import de.ugoe.cs.util.FileTools; 20 25 import de.ugoe.cs.util.console.Console; … … 67 72 * </p> 68 73 */ 69 private List<List< WebEvent>> sequences;74 private List<List<Event>> sequences; 70 75 71 76 /** … … 90 95 * </p> 91 96 */ 92 private List<Collection<List< WebEvent>>> sequencesFrequentUsers;97 private List<Collection<List<Event>>> sequencesFrequentUsers; 93 98 94 99 /** … … 145 150 * @return generated event sequences 146 151 */ 147 public Collection<List< WebEvent>> getSequences() {152 public Collection<List<Event>> getSequences() { 148 153 return sequences; 149 154 } … … 232 237 * @return list of the sequences of all frequent users 233 238 */ 234 public List<Collection<List< WebEvent>>> getFrequentUserSequences() {239 public List<Collection<List<Event>>> getFrequentUserSequences() { 235 240 return sequencesFrequentUsers; 236 241 } … … 255 260 256 261 Map<String, List<Integer>> cookieSessionMap = new HashMap<String, List<Integer>>(); 262 Map<String, Long> cookieTimestampMap = new HashMap<String, Long>(); 263 257 264 int lastId = -1; 258 265 … … 261 268 loadRobotRegex(); 262 269 263 sequences = new ArrayList<List< WebEvent>>();270 sequences = new ArrayList<List<Event>>(); 264 271 users = new ArrayList<String>(); 265 272 … … 298 305 List<String> getVars = extractGetVarsFromUri(uri); 299 306 300 WebEvent event = new WebEvent(url, path, timestamp, 301 postedVars, getVars); 307 IEventType type = new PHPEventType(path, postedVars, getVars); 308 IEventTarget target = new PHPEventTarget(path); 309 Event event = new Event(type, target); 310 event.addReplayable(new WebRequest(url, path, postedVars, getVars)); 302 311 303 312 // find session and add event … … 308 317 sessionIds.add(++lastId); 309 318 cookieSessionMap.put(cookie, sessionIds); 310 sequences.add(new LinkedList< WebEvent>());319 sequences.add(new LinkedList<Event>()); 311 320 users.add(cookie); 312 321 } 313 322 Integer lastSessionIndex = sessionIds 314 323 .get(sessionIds.size() - 1); 315 List< WebEvent> lastSession = sequences324 List<Event> lastSession = sequences 316 325 .get(lastSessionIndex); 317 326 long lastEventTime = timestamp; 318 327 if (!lastSession.isEmpty()) { 319 lastEventTime = lastSession.get(lastSession.size() - 1) 320 .getTimestamp(); 328 lastEventTime = cookieTimestampMap.get(cookie); 321 329 } 322 330 if (timestamp - lastEventTime > timeout) { 323 331 sessionIds.add(++lastId); 324 List< WebEvent> newSession = new LinkedList<WebEvent>();332 List<Event> newSession = new LinkedList<Event>(); 325 333 newSession.add(event); 326 334 sequences.add(newSession); … … 329 337 lastSession.add(event); 330 338 } 339 cookieTimestampMap.put(cookie, timestamp); 331 340 } catch (URISyntaxException e) { 332 341 Console.traceln("Ignored line " + lineCounter + ": " … … 358 367 private void generateFrequentUserSequences(Set<String> uniqueUsers) { 359 368 frequentUsers = new ArrayList<String>(); 360 sequencesFrequentUsers = new ArrayList<Collection<List< WebEvent>>>();369 sequencesFrequentUsers = new ArrayList<Collection<List<Event>>>(); 361 370 for (String user : uniqueUsers) { 362 371 List<String> tmp = new ArrayList<String>(); … … 367 376 if (size >= frequentUsersThreshold) { 368 377 frequentUsers.add(user); 369 Collection<List< WebEvent>> sequencesUser = new ArrayList<List<WebEvent>>();378 Collection<List<Event>> sequencesUser = new ArrayList<List<Event>>(); 370 379 for (int i = 0; i < sequences.size(); i++) { 371 380 if (users.get(i).equals(user)) { -
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/plugin/php/commands/CMDloadWebSequences.java
r434 r554 9 9 10 10 import de.ugoe.cs.quest.CommandHelpers; 11 import de.ugoe.cs.quest.eventcore.Event; 11 12 import de.ugoe.cs.quest.plugin.php.WeblogParser; 12 import de.ugoe.cs.quest.plugin.php.eventcore.WebEvent;13 13 import de.ugoe.cs.quest.ui.GlobalDataContainer; 14 14 import de.ugoe.cs.util.console.Command; … … 93 93 if (generateFrequentUsers) { 94 94 List<String> frequentUserIDs = parser.getFrequentUsers(); 95 List<Collection<List< WebEvent>>> frequentUserSessions = parser95 List<Collection<List<Event>>> frequentUserSessions = parser 96 96 .getFrequentUserSequences(); 97 97 for (int i = 0; i < frequentUserIDs.size(); i++) { -
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/plugin/php/eventcore/WebRequest.java
r434 r554 1 1 2 package de.ugoe.cs.quest.plugin.php.eventcore; 2 3 … … 8 9 /** 9 10 * <p> 10 * Contains all information related to a web request, i.e., the path, the POST 11 * variables and the GET variables. The generated replay are for the command 12 * line tool {@code curl}. The requests do not contain correct values for the 13 * POST and GET request. Instead, only the parameters that are part of the 14 * requests are added and the values of the parameters are 15 * DATA_$PARAMNAME$_DATA, where $PARAMNAME$ is the upper case string of the 16 * parameter name. This allows test data generators to insert concrete values, 17 * as EventBench does not include a test data generator for web software. 11 * Contains all information related to a web request, i.e., the path, the POST variables and the GET 12 * variables. The generated replay are for the command line tool {@code curl}. The requests do not 13 * contain correct values for the POST and GET request. Instead, only the parameters that are part 14 * of the requests are added and the values of the parameters are DATA_$PARAMNAME$_DATA, where 15 * $PARAMNAME$ is the upper case string of the parameter name. This allows test data generators to 16 * insert concrete values, as EventBench does not include a test data generator for web software. 18 17 * </p> 19 18 * … … 23 22 public class WebRequest implements IReplayable { 24 23 25 26 27 28 29 30 24 /** 25 * <p> 26 * Id for object serialization. 27 * </p> 28 */ 29 private static final long serialVersionUID = 1L; 31 30 32 33 34 35 36 37 31 /** 32 * <p> 33 * POST variables of the web request. 34 * </p> 35 */ 36 List<String> postVars; 38 37 39 40 41 42 43 44 38 /** 39 * <p> 40 * GET variables of the web request. 41 * </p> 42 */ 43 List<String> getVars; 45 44 46 47 48 49 50 51 45 /** 46 * <p> 47 * URI of the web request. 48 * </p> 49 */ 50 String targetUri; 52 51 53 54 55 56 57 58 52 /** 53 * <p> 54 * URL of the server. 55 * </p> 56 */ 57 String serverUrl; 59 58 60 /** 61 * <p> 62 * Constructor. Creates a new WebRequest. 63 * </p> 64 * 65 * @param uri 66 * URI of the request 67 * @param postVars 68 * POST variables of the request 69 * @param getVars 70 * GET variables of the request 71 */ 72 public WebRequest(String url, String uri, List<String> postVars, 73 List<String> getVars) { 74 serverUrl = url; 75 targetUri = uri; 76 this.postVars = new ArrayList<String>(postVars); // defensive copy 77 this.getVars = new ArrayList<String>(getVars); 78 } 59 /** 60 * <p> 61 * Constructor. Creates a new WebRequest. 62 * </p> 63 * 64 * @param uri 65 * URI of the request 66 * @param postVars 67 * POST variables of the request 68 * @param getVars 69 * GET variables of the request 70 */ 71 public WebRequest(String url, String uri, List<String> postVars, List<String> getVars) { 72 serverUrl = url; 73 targetUri = uri; 74 this.postVars = new ArrayList<String>(postVars); // defensive copy 75 this.getVars = new ArrayList<String>(getVars); 76 } 79 77 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 } else { 96 builder.append('&'); 97 } 98 builder.append(postVar + "=DATA_" + postVar.toUpperCase() 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 } else { 115 builder.append('&'); 116 } 117 builder.append(getVar + "=DATA_" + getVar.toUpperCase() 118 119 120 121 122 78 /* 79 * (non-Javadoc) 80 * 81 * @see de.ugoe.cs.quest.eventcore.IReplayable#getReplay() 82 */ 83 @Override 84 public String getReplay() { 85 StringBuilder builder = new StringBuilder(); 86 builder.append("curl"); 87 if (!postVars.isEmpty()) { 88 boolean isFirstPost = true; 89 for (String postVar : postVars) { 90 if (isFirstPost) { 91 builder.append(" --data \""); 92 isFirstPost = false; 93 } 94 else { 95 builder.append('&'); 96 } 97 builder.append(postVar + "=DATA_" + postVar.toUpperCase() + "_DATA"); 98 } 99 builder.append('\"'); 100 } 101 builder.append(' '); 102 if (serverUrl != null) { 103 builder.append(serverUrl); 104 } 105 builder.append(targetUri); 106 if (!getVars.isEmpty()) { 107 boolean isFirstGet = true; 108 for (String getVar : getVars) { 109 if (isFirstGet) { 110 builder.append('?'); 111 isFirstGet = false; 112 } 113 else { 114 builder.append('&'); 115 } 116 builder.append(getVar + "=DATA_" + getVar.toUpperCase() + "_DATA"); 117 } 118 } 119 return builder.toString(); 120 } 123 121 124 /* 125 * (non-Javadoc) 126 * 127 * @see de.ugoe.cs.quest.eventcore.IReplayable#getTarget() 128 */ 129 @Override 130 public String getTarget() { 131 return targetUri; 132 } 122 /** 123 * <p> 124 * Two {@link WebRequest}s are equal, if their {@link #targetUri}, {@link #postVars}, and 125 * {@link #getVars} are equal. 126 * </p> 127 * 128 * @see java.lang.Object#equals(java.lang.Object) 129 */ 130 @Override 131 public boolean equals(Object other) { 132 if (this == other) { 133 return true; 134 } 135 if (other instanceof WebRequest) { 136 return targetUri.equals(((WebRequest) other).targetUri) && 137 postVars.equals(((WebRequest) other).postVars) && 138 getVars.equals(((WebRequest) other).getVars); 139 } 140 return false; 141 } 133 142 134 /** 135 * <p> 136 * Two {@link WebRequest}s are equal, if their {@link #targetUri}, 137 * {@link #postVars}, and {@link #getVars} are equal. 138 * </p> 139 * 140 * @see java.lang.Object#equals(java.lang.Object) 141 */ 142 @Override 143 public boolean equals(Object other) { 144 if (this == other) { 145 return true; 146 } 147 if (other instanceof WebRequest) { 148 return targetUri.equals(((WebRequest) other).targetUri) 149 && postVars.equals(((WebRequest) other).postVars) 150 && getVars.equals(((WebRequest) other).getVars); 151 } 152 return false; 153 } 143 /* 144 * (non-Javadoc) 145 * 146 * @see java.lang.Object#hashCode() 147 */ 148 @Override 149 public int hashCode() { 150 int multiplier = 17; 151 int hash = 42; 154 152 155 /* 156 * (non-Javadoc) 157 * 158 * @see java.lang.Object#hashCode() 159 */ 160 @Override 161 public int hashCode() { 162 int multiplier = 17; 163 int hash = 42; 153 hash = multiplier * hash + targetUri.hashCode(); 154 hash = multiplier * hash + postVars.hashCode(); 155 hash = multiplier * hash + getVars.hashCode(); 164 156 165 hash = multiplier * hash + targetUri.hashCode(); 166 hash = multiplier * hash + postVars.hashCode(); 167 hash = multiplier * hash + getVars.hashCode(); 168 169 return hash; 170 } 157 return hash; 158 } 171 159 172 160 }
Note: See TracChangeset
for help on using the changeset viewer.