Clover coverage report -
Coverage timestamp: Sat Jul 7 2007 16:41:13 CEST
file stats: LOC: 490   Methods: 40
NCLOC: 310   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
TestOutcomeTable.java 50% 53.5% 57.5% 53.7%
coverage coverage
 1    /**
 2    * JTRunner is free software; you can redistribute it and/or modify it under the
 3    * terms of the GNU General Public License as published by the Free Software
 4    * Foundation; either version 2, or (at your option) any later version.
 5    */
 6   
 7    package jtr.test;
 8   
 9    import java.io.Serializable;
 10    import java.util.Calendar;
 11    import java.util.ArrayList;
 12    import java.util.HashMap;
 13    import java.util.List;
 14    import java.util.Set;
 15    import java.util.SortedSet;
 16    import java.util.TreeSet;
 17   
 18    import jtr.remote.test.DistributionError;
 19    import jtr.remote.test.NodeInfo;
 20   
 21    /**
 22    * This class is meant to be a repository of different <code>IOutcome</code>
 23    * instances.<br>
 24    * Whenever an <code>IRunner</code> faces an exception, an
 25    * <code>IOutcome</code> is instantiated and added to this repository.<br>
 26    * Once the test is done, the content of the <code>TestOutcomeTable</code> is
 27    * provided to the user as a briefing of what happened during the runs.
 28    *
 29    * @param T The actual type of the outcome
 30    * @author Francesco Russo (frusso@dev.java.net)
 31    * @version 4.0
 32    * @since 1.0
 33    * @see jtr.test.IOutcome
 34    * @see jtr.test.IOutcomeFactory
 35    */
 36    public class TestOutcomeTable<T extends IOutcome> implements Serializable {
 37   
 38    /**
 39    * The constructor.
 40    * @param node
 41    */
 42  3 public TestOutcomeTable(NodeInfo node) {
 43  3 results = new HashMap<NodeInfo,HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>>>();
 44  3 this.node = node;
 45  3 briefing = new TestBriefing();
 46    }
 47   
 48  2 public void setStartTime() {
 49  2 briefing.setStartTime(Calendar.getInstance());
 50    }
 51   
 52  2 public void setEndTime() {
 53  2 briefing.setEndTime(Calendar.getInstance());
 54    }
 55   
 56  0 public void addDistributionError(DistributionError error) {
 57  0 briefing.addDistributionError(error);
 58    }
 59   
 60    /**
 61    * Add a new outcome to the repository.
 62    *
 63    * @param runner
 64    * The unique name of the IRunner that faced the exception. This
 65    * is its thread-name automatically generated by the JTR runtime
 66    * @param outcome
 67    * The outcome
 68    */
 69  44400 public synchronized void put(String runner, T outcome) {
 70  44400 if(outcome.isFailure())
 71  12004 briefing.incrFailures();
 72    else
 73  32396 briefing.incrSuccesses();
 74   
 75  44400 outcome.setNode(node);
 76  44400 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> classes = results.get(node);
 77  44400 if(classes!=null) {
 78  44398 Class c = outcome.getRunnerCategory();
 79  44398 HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>> instances = classes.get(c);
 80  44398 if(instances!=null) {
 81  44388 String id = outcome.getRunnerId();
 82  44388 HashMap<Integer,HashMap<Integer,IOutcome>> epochs = instances.get(id);
 83  44388 if(epochs!=null) {
 84  44302 int epoch = outcome.getEpoch();
 85  44302 HashMap<Integer,IOutcome> runs = epochs.get(epoch);
 86  44302 if(runs==null) {
 87  4802 runs = new HashMap<Integer,IOutcome>();
 88  4802 epochs.put(epoch,runs);
 89    }
 90  44302 runs.put(outcome.getRun(),outcome);
 91    } else {
 92    // epochs is null
 93  86 epochs = new HashMap<Integer,HashMap<Integer,IOutcome>>();
 94  86 HashMap<Integer,IOutcome> runs = new HashMap<Integer,IOutcome>();
 95  86 runs.put(outcome.getRun(),outcome);
 96  86 epochs.put(outcome.getEpoch(),runs);
 97  86 instances.put(outcome.getRunnerId(),epochs);
 98  86 briefing.incrInstances();
 99    }
 100    } else {
 101    // instances is null
 102  10 instances = new HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>();
 103  10 HashMap<Integer,HashMap<Integer,IOutcome>> epochs = new HashMap<Integer,HashMap<Integer,IOutcome>>();
 104  10 HashMap<Integer,IOutcome> runs = new HashMap<Integer,IOutcome>();
 105  10 runs.put(outcome.getRun(),outcome);
 106  10 epochs.put(outcome.getEpoch(),runs);
 107  10 instances.put(outcome.getRunnerId(),epochs);
 108  10 briefing.incrInstances();
 109  10 classes.put(outcome.getRunnerCategory(),instances);
 110    }
 111    } else {
 112    // classes is null
 113  2 classes = new HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>>();
 114  2 HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>> instances = new HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>();
 115  2 HashMap<Integer,HashMap<Integer,IOutcome>> epochs = new HashMap<Integer,HashMap<Integer,IOutcome>>();
 116  2 HashMap<Integer,IOutcome> runs = new HashMap<Integer,IOutcome>();
 117  2 runs.put(outcome.getRun(),outcome);
 118  2 epochs.put(outcome.getEpoch(),runs);
 119  2 instances.put(outcome.getRunnerId(),epochs);
 120  2 briefing.incrInstances();
 121  2 classes.put(outcome.getRunnerCategory(),instances);
 122  2 results.put(node,classes);
 123    }
 124    }
 125   
 126  6 public TestBriefing getBriefing() {
 127  6 return briefing;
 128    }
 129   
 130    /**
 131    * This class defines the briefing of the JTR test session
 132    * represented by the hosting <code>TestOutcomeTable</code>.
 133    *
 134    * @author frusso
 135    * @version 4.0
 136    * @since 4.0
 137    */
 138    public class TestBriefing implements Serializable {
 139   
 140    /**
 141    * Local constructor.
 142    */
 143  3 TestBriefing() {
 144  3 super();
 145    }
 146   
 147    // local setters...
 148    /**
 149    * Set the time the test session started.
 150    * @param start
 151    */
 152  2 void setStartTime(Calendar start) {
 153  2 startTime = start;
 154    }
 155   
 156    /**
 157    * Set the time the test session ended.
 158    * @param end
 159    */
 160  2 void setEndTime(Calendar end) {
 161  2 endTime = end;
 162    }
 163   
 164    /**
 165    * Set the time, in milliseconds, the test sessions took.
 166    * @param time
 167    */
 168  0 void setElapsed(long time) {
 169  0 elapsed = time;
 170    }
 171   
 172    /**
 173    * Set the number of runner instances involved in the test.
 174    * @param num
 175    */
 176  0 void setInstances(int num) {
 177  0 instances = num;
 178    }
 179   
 180    /**
 181    * Increment by one the number of runner instances involved in the test.
 182    *
 183    */
 184  98 void incrInstances() {
 185  98 instances++;
 186    }
 187   
 188    /**
 189    * Set the number of successes recordered in the test session.
 190    * @param num
 191    */
 192  0 void setSuccesses(int num) {
 193  0 successes = num;
 194    }
 195   
 196    /**
 197    * Increment by one the number of successes recordered in the test session.
 198    *
 199    */
 200  32396 void incrSuccesses() {
 201  32396 successes++;
 202    }
 203   
 204    /**
 205    * Set the number of failures.
 206    * @param num
 207    */
 208  0 void setFailures(int num) {
 209  0 failures = num;
 210    }
 211   
 212    /**
 213    * Increment by one the number of failures.
 214    */
 215  12004 void incrFailures() {
 216  12004 failures++;
 217    }
 218   
 219    /**
 220    * Add a ditribution error to the list.
 221    * @param error
 222    */
 223  0 void addDistributionError(DistributionError error) {
 224  0 if(distributionErrors==null)
 225  0 distributionErrors = new ArrayList<DistributionError>();
 226  0 distributionErrors.add(error);
 227    }
 228   
 229    // publicly available getters...
 230    /**
 231    * Returns the time the test session started.
 232    * @return Calendar
 233    */
 234  6 public Calendar getStartTime() {
 235  6 return startTime;
 236    }
 237   
 238    /**
 239    * Returns the time the test session ended.
 240    * @return Calendar
 241    */
 242  6 public Calendar getEndTime() {
 243  6 return endTime;
 244    }
 245   
 246    /**
 247    * Returns the amount of time required by the test session, expressed
 248    * in milliseconds.
 249    * @return long
 250    */
 251  12 public long getElapsed() {
 252  12 if(elapsed==null)
 253  2 elapsed = endTime.getTimeInMillis() - startTime.getTimeInMillis();
 254  12 return elapsed;
 255    }
 256   
 257    /**
 258    * Returns the number of runner instances involved in the test session.
 259    * @return int
 260    */
 261  6 public int getInstances() {
 262  6 return instances;
 263    }
 264   
 265    /**
 266    * Returns the number of successes.
 267    * @return int
 268    */
 269  12 public int getSuccesses() {
 270  12 return successes;
 271    }
 272   
 273    /**
 274    * Returns the number of failures.
 275    * @return int
 276    */
 277  12 public int getFailures() {
 278  12 return failures;
 279    }
 280   
 281    /**
 282    * Returns the avarage number of runs (both succeeded and failed) per second.
 283    * @return float
 284    */
 285  0 public float getAvg() {
 286  0 return (successes + failures)/(getElapsed()/1000);
 287    }
 288   
 289    /**
 290    * Gets the list of recordered distribution errors.
 291    * @return List<DistributionError>
 292    */
 293  0 public List<DistributionError> getDistributionErrors() {
 294  0 return distributionErrors;
 295    }
 296   
 297  6 public String toString() {
 298  6 float totalRequests = getSuccesses() + getFailures();
 299  6 float avg = totalRequests/(getElapsed()/k);
 300   
 301  6 String msg = "START: "+getStartTime().getTime()+",\nEND: "+getEndTime().getTime()+",\nELAPSED: "+getElapsed()+" (milliSecs)"+
 302    ",\nINSTANCES: "+getInstances()+", SUCCESSES: "+getSuccesses()+", FAILURES: "+getFailures()+
 303    ",\nAVG REQUESTS PER SEC: "+Float.toString(avg);
 304   
 305  6 if(distributionErrors!=null) {
 306  0 int i = 0;
 307  0 msg = msg + "\n\nDISTRIBUTION ERRORS: "+distributionErrors.size();
 308  0 for(DistributionError error : distributionErrors) {
 309  0 msg = msg + "\n" + error;
 310    }
 311    }
 312   
 313  6 return msg;
 314    }
 315   
 316    private List<DistributionError> distributionErrors;
 317    private Calendar startTime;
 318    private Calendar endTime;
 319    private Long elapsed;
 320    private long k = 1000;
 321    private int instances = 0;
 322    private int successes = 0;
 323    private int failures = 0;
 324    }
 325   
 326    /////////////////////////////////
 327    // Methods usefl for accessing //
 328    // the outcomes stored here in //
 329    /////////////////////////////////
 330   
 331  0 public Object getNode() {
 332  0 return results.keySet().iterator().next();
 333    }
 334   
 335  0 public Object getCategory(NodeInfo node, int index) {
 336  0 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> categories = results.get(node);
 337  0 Set<Class> keys = categories.keySet();
 338  0 int i = 0;
 339  0 for(Class c : keys) {
 340  0 if(i==index)
 341  0 return c;
 342  0 i++;
 343    }
 344  0 return null;
 345    }
 346   
 347  0 public int getCategoriesCount(NodeInfo node) {
 348  0 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> categories = results.get(node);
 349  0 return categories.size();
 350    }
 351   
 352  0 public String getInstance(Class c, int index) {
 353  0 Set<NodeInfo> nodes = results.keySet();
 354  0 for(NodeInfo node : nodes) {
 355  0 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> categories = results.get(node);
 356  0 HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>> instances = categories.get(c);
 357  0 Set<String> keys = instances.keySet();
 358  0 int i = 0;
 359  0 for(String k : keys) {
 360  0 if(i==index)
 361  0 return k;
 362  0 i++;
 363    }
 364    }
 365  0 return null;
 366    }
 367   
 368  0 public int getInstancesCount(Class c) {
 369  0 Set<NodeInfo> nodes = results.keySet();
 370  0 for(NodeInfo node : nodes) {
 371  0 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> categories = results.get(node);
 372  0 if(categories.containsKey(c)) {
 373  0 HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>> instances = categories.get(c);
 374  0 return instances.size();
 375    }
 376    }
 377  0 return -1;
 378    }
 379   
 380  0 public Object getEpoch(String s, int index) {
 381  0 Set<NodeInfo> nodes = results.keySet();
 382  0 for(NodeInfo node : nodes) {
 383  0 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> categories = results.get(node);
 384  0 Set<Class> cats = categories.keySet();
 385  0 for(Class c : cats) {
 386  0 HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>> instances = categories.get(c);
 387  0 if(instances.containsKey(s)) {
 388  0 HashMap<Integer,HashMap<Integer,IOutcome>> epochs = instances.get(s);
 389  0 Set<Integer> eKeys = epochs.keySet();
 390  0 int i = 0;
 391  0 for(Integer k : eKeys) {
 392  0 if(i==index)
 393  0 return k;
 394  0 i++;
 395    }
 396    }
 397    }
 398    }
 399  0 return null;
 400    }
 401   
 402  0 public int getEpochsCount(String s) {
 403  0 Set<NodeInfo> nodes = results.keySet();
 404  0 for(NodeInfo node : nodes) {
 405  0 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> categories = results.get(node);
 406  0 Set<Class> catKeys = categories.keySet();
 407  0 for(Class c : catKeys) {
 408  0 HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>> instances = categories.get(c);
 409  0 if(instances.containsKey(s)) {
 410  0 return instances.get(s).size();
 411    }
 412    }
 413    }
 414  0 return 0;
 415    }
 416   
 417  0 public int getRunsCount(Integer epoch) {
 418  0 Set<NodeInfo> nodes = results.keySet();
 419  0 for(NodeInfo node : nodes) {
 420  0 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> categories = results.get(node);
 421  0 Set<Class> catKeys = categories.keySet();
 422  0 for(Class c : catKeys) {
 423  0 HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>> instances = categories.get(c);
 424  0 Set<String> instKeys = instances.keySet();
 425  0 for(String k : instKeys) {
 426  0 HashMap<Integer,HashMap<Integer,IOutcome>> epochs = instances.get(k);
 427  0 return epochs.get(epoch).size();
 428    }
 429    }
 430    }
 431  0 return 0;
 432    }
 433   
 434  245 public List<IOutcome> getOutcomes(String instance) {
 435  245 ArrayList<IOutcome> res = new ArrayList<IOutcome>();
 436   
 437  245 Set<NodeInfo> nodesK = results.keySet();
 438  245 for(NodeInfo nodeK : nodesK) {
 439  245 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> classes = results.get(nodeK);
 440  245 Set<Class> classesK = classes.keySet();
 441  245 for(Class classK : classesK) {
 442  905 HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>> instances = classes.get(classK);
 443  905 if(instances.containsKey(instance)) {
 444  245 HashMap<Integer,HashMap<Integer,IOutcome>> epochs = instances.get(instance);
 445  245 Set<Integer> epochsK = epochs.keySet();
 446  245 for(Integer epochK : epochsK) {
 447  12250 HashMap<Integer,IOutcome> runs = epochs.get(epochK);
 448  12250 Set<Integer> runsK = runs.keySet();
 449  12250 for(Integer runK : runsK) {
 450  111000 res.add( runs.get(runK) );
 451    }
 452    }
 453  245 break;
 454    }
 455    }
 456    }
 457   
 458  245 return res;
 459    }
 460   
 461  98 public SortedSet<IOutcome> getOrderedOutcomes(String instance) {
 462  98 List<IOutcome> outcomes = getOutcomes(instance);
 463  98 return new TreeSet(outcomes);
 464    }
 465   
 466  0 public void addAll(TestOutcomeTable outcome) {
 467  0 results.putAll(outcome.results);
 468    }
 469   
 470  2 public Set<NodeInfo> getNodes() {
 471  2 return results.keySet();
 472    }
 473   
 474  5 public Set<Class> getCategories(NodeInfo n) {
 475  5 return results.get(n).keySet();
 476    }
 477   
 478  30 public Set<String> getInstances(Class c) {
 479  30 Set<NodeInfo> nodes = results.keySet();
 480  30 for(NodeInfo node : nodes) {
 481  30 HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>> categories = results.get(node);
 482  30 return categories.get(c).keySet();
 483    }
 484  0 return null;
 485    }
 486   
 487    private HashMap<NodeInfo,HashMap<Class,HashMap<String,HashMap<Integer,HashMap<Integer,IOutcome>>>>> results;
 488    private NodeInfo node;
 489    private TestBriefing briefing;
 490    }