| 1 4 package com.tctest.performance.http.load.webapp; 5 6 import org.apache.commons.lang.SerializationUtils; 7 8 import com.tctest.performance.http.load.AbstractHttpLoadTest; 9 import com.tctest.performance.sampledata.OrganicObjectGraph; 10 import com.tctest.performance.sampledata.OrganicObjectGraphManager; 11 12 import java.io.File ; 13 import java.io.FileInputStream ; 14 import java.io.FileNotFoundException ; 15 import java.io.FilenameFilter ; 16 import java.util.ArrayList ; 17 import java.util.HashMap ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 public abstract class ValidateHttpFieldReplicationTest extends AbstractHttpLoadTest { 23 24 private static final String VALIDATE = "validate"; 25 private boolean validate; 26 27 protected ValidateHttpFieldReplicationTest(String [] args) { 28 super(setArgs(args)); 29 if (args.length == 2 && args[0].equals(VALIDATE)) validate = true; 30 } 31 32 protected abstract int changes(); 33 34 protected abstract int graphSize(); 35 36 protected final void execute() throws Exception { 37 if (!validate) super.execute(); 38 else validateObjectGraphs(resultsDir()); 39 } 40 41 private static String [] setArgs(String [] args) { 42 if (args.length == 2 && args[0].equals(VALIDATE)) return new String [] { "0", args[1] }; 43 return args; 44 } 45 46 protected final void validateArgs(String [] args) { 47 if (args.length < 2) { 48 System.out.println("Usage:"); 49 System.out.println(" [<duration in seconds> | validate] <working dir path> [report]"); 50 System.exit(0); 51 } 52 } 53 54 private final void validateObjectGraphs(File resultsDir) throws Exception , FileNotFoundException { 55 if (!resultsDir.exists()) { 56 System.err.println("No Data Available to Validate"); 57 return; 58 } 59 String [] files = resultsDir.list(new FilenameFilter () { 60 public boolean accept(File dir, String name) { 61 return name.endsWith("obj"); 62 } 63 }); 64 OrganicObjectGraph[] graphArray; 65 OrganicObjectGraph graph; 66 String hostKey; 67 Map hostGraphs = new HashMap (); 68 List graphs; 69 70 for (int i = 0; i < files.length; i++) { 72 String [] parts = files[i].split("_"); 73 if ((parts.length == 3) && parts[1].equals("graph")) { 74 System.out.println(" loading: " + files[i]); 75 FileInputStream in = new FileInputStream (resultsDir() + File.separator + files[i]); 76 graph = (OrganicObjectGraph) SerializationUtils.deserialize(in); 77 System.out.println(" sequence #: " + graph.sequenceNumber()); 78 System.out.println(" change iteration count #: " + graph.changeIterationCount()); 79 System.out.println(" envkey: " + graph.envKey()); 80 System.out.println("--"); 81 hostKey = graph.envKey(); 82 if (!hostGraphs.containsKey(hostKey)) { 83 graphs = new ArrayList (); 84 graphs.add(graph); 85 hostGraphs.put(hostKey, graphs); 86 } else { 87 graphs = (List ) hostGraphs.get(hostKey); 88 graphs.add(graph); 89 } 90 } 91 } 92 System.out.println(""); 93 94 Iterator iter = hostGraphs.entrySet().iterator(); 95 while (iter.hasNext()) { 96 Map.Entry entry = (Map.Entry ) iter.next(); 97 graphs = (ArrayList ) entry.getValue(); 98 graphArray = new OrganicObjectGraph[graphs.size()]; 99 100 for (int i = 0; i < graphArray.length; i++) { 102 graph = (OrganicObjectGraph) graphs.get(i); 103 graphArray[graph.sequenceNumber()] = graph; 104 } 105 if (!OrganicObjectGraphManager.validate(graphArray, graphSize(), changes())) { 107 System.out.println("\nGraph Validation: Failed"); 108 return; 109 } 110 } 111 System.out.println("\nGraph Validation: Passed"); 112 } 113 } 114 | Popular Tags |