1 4 package com.tcsimulator; 5 6 import com.tc.object.config.ConfigVisitor; 7 import com.tc.object.config.DSOApplicationConfig; 8 import com.tc.process.LinkedJavaProcess; 9 import com.tc.simulator.distrunner.ArgParser; 10 import com.tcsimulator.distrunner.ServerSpec; 11 12 import java.io.File ; 13 import java.io.IOException ; 14 import java.net.InetAddress ; 15 import java.util.ArrayList ; 16 import java.util.Collection ; 17 import java.util.HashSet ; 18 import java.util.Iterator ; 19 20 public class TestStarter { 21 22 private TestSpec testSpec; 23 private final boolean debug = false; 24 25 public TestStarter() { 26 testSpec = new TestSpec(); 27 } 28 29 public static void main(String [] args) throws IOException , InterruptedException { 30 TestStarter runner = new TestStarter(); 31 runner.execute(); 32 } 33 34 public static void visitDSOApplicationConfig(ConfigVisitor visitor, DSOApplicationConfig cfg) { 35 String classname = TestStarter.class.getName(); 36 cfg.addRoot("testSpec", classname + ".testSpec"); 37 cfg.addIncludePattern(classname); 38 cfg.addWriteAutolock("* " + classname + ".*(..)"); 39 } 40 41 private void println(String msg) { 42 System.out.println("TestStarter: " + msg); 43 } 44 45 private void execute() throws IOException , InterruptedException { 46 InetAddress host = InetAddress.getLocalHost(); 47 String hostName = host.getHostName(); 48 49 Collection procList = new ArrayList (); 50 51 int debugPortOffset = 0; 52 53 synchronized (testSpec) { 54 55 Collection containerSpecs = testSpec.getContainerSpecsFor(hostName); 56 57 if (containerSpecs.size() == 0) { 58 System.err.println("No containers setup for this host: " + hostName + ", " + testSpec); 59 return; 60 } 61 62 for (Iterator i = containerSpecs.iterator(); i.hasNext();) { 63 ContainerSpec containerSpec = (ContainerSpec) i.next(); 64 println("Found containerSpec: " + containerSpec); 65 LinkedJavaProcess proc = new LinkedJavaProcess(ContainerBuilder.class.getName(), new String [] { containerSpec 66 .getVmName() }); 67 String fileSeparator = System.getProperty("file.separator"); 68 69 File terracottaDist = new File (new File (containerSpec.getTestHome()).getAbsoluteFile(), "terracotta"); 70 File dsoJava = new File (terracottaDist.getAbsolutePath() + fileSeparator + "bin" + fileSeparator + "dso-java.sh"); 71 72 Collection jvmArgs = new HashSet (); 73 for (Iterator iter = containerSpec.getJvmOpts().iterator(); iter.hasNext();) { 74 String next = (String ) iter.next(); 75 if (!next.equals(ArgParser.getUndefinedString())) { 76 jvmArgs.add(next); 77 } 78 } 79 ServerSpec sSpec = (ServerSpec) testSpec.getServerSpecsFor(ServerSpec.TEST_SERVER).iterator().next(); 80 jvmArgs.add("-Dtc.config=" + sSpec.getHostName() + ":" + sSpec.getDsoPort()); 81 jvmArgs.add("-Dtc.classloader.writeToDisk=true"); 82 if (debug) { 83 jvmArgs.add("-Xdebug"); 84 jvmArgs.add("-Xrunjdwp:transport=dt_socket,address=" + (8000 + debugPortOffset) + ",server=y,suspend=y"); 85 debugPortOffset++; 86 } 87 Collection environment = new HashSet (); 88 if ("Mac OS X".equals(System.getProperty("os.name")) || "Linux".equals(System.getProperty("os.name"))) { 89 environment.add("TC_JAVA_HOME=" + System.getProperty("java.home")); 90 } 91 proc.setJavaExecutable(dsoJava); 92 File dir = new File (containerSpec.getTestHome(), containerSpec.getVmName()); 93 dir.mkdir(); 94 proc.setDirectory(dir); 95 proc.setJavaArguments((String []) jvmArgs.toArray(new String [jvmArgs.size()])); 96 proc.setEnvironment((String []) environment.toArray(new String [environment.size()])); 97 proc.start(); 98 proc.mergeSTDERR(); 99 proc.mergeSTDOUT(); 100 procList.add(proc); 101 102 } 103 104 } 105 106 for (Iterator i = procList.iterator(); i.hasNext();) { 107 ((LinkedJavaProcess) i.next()).waitFor(); 108 } 109 110 } 111 } | Popular Tags |