1 4 package com.tc.simulator.distrunner; 5 6 import org.apache.commons.io.FileUtils; 7 8 import com.tc.object.config.ConfigVisitor; 9 import com.tc.object.config.DSOApplicationConfig; 10 import com.tc.test.TCTestCase; 11 import com.tc.util.concurrent.NoExceptionLinkedQueue; 12 import com.tcsimulator.ClientSpecImpl; 13 import com.tcsimulator.ConfigWriter; 14 import com.tcsimulator.Sandbox; 15 import com.tcsimulator.Setup; 16 import com.tcsimulator.distrunner.ServerSpec; 17 import com.tcsimulator.distrunner.ServerSpecImpl; 18 19 import java.io.BufferedReader ; 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.IOException ; 23 import java.io.InputStreamReader ; 24 import java.net.InetAddress ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 28 public class SetupTest extends TCTestCase { 29 private static final String LICENSE_FILENAME = "license.lic"; 30 31 public void testBasic() throws Throwable { 32 Collection clientSpecs = new ArrayList (); 33 String clientHostname = "myClientHostname"; 34 String clientTestHome = getTempDirectory().getAbsolutePath(); 35 int vmCount = 0; 36 int executionCount = 0; 37 int intensity = 1; 38 clientSpecs.add(new ClientSpecImpl(clientHostname, clientTestHome, vmCount, executionCount, new ArrayList ())); 39 40 InetAddress host = InetAddress.getLocalHost(); 41 String localHostName = host.getHostName(); 42 43 String serverHostname = localHostName; 44 String serverTestHome = getTempDirectory().getAbsolutePath(); 45 46 File licenseFile = new File (serverTestHome, LICENSE_FILENAME); 47 FileUtils.touch(licenseFile); 48 49 ServerSpec serverSpec = new ServerSpecImpl(serverHostname, serverTestHome, -1, -1, -1, new ArrayList (), 50 ServerSpec.TEST_SERVER); 51 52 String testAppClassName = TestApp.class.getName(); 53 new Setup(new String [] {}, serverSpec, testAppClassName, clientSpecs, intensity, false); 54 55 Sandbox sandbox = new Sandbox(new File (serverTestHome), Sandbox.TEST_SERVER); 56 57 File configFile = new File (serverTestHome, sandbox.getConfigFile().getName()); 58 assertFalse(configFile.exists()); 59 assertNull(TestApp.visitCalls.poll(0)); 60 61 Collection classesToVisit = new ArrayList (); 62 classesToVisit.add(TestApp.class); 63 ConfigWriter configWriter = new ConfigWriter(serverSpec, classesToVisit, sandbox); 64 configWriter.writeConfigFile(); 65 66 assertNotNull(TestApp.visitCalls.poll(0)); 67 assertTrue(configFile.exists()); 68 dumpConfigFile(configFile); 69 70 } 71 72 private void dumpConfigFile(File configFile) throws IOException { 73 BufferedReader reader = new BufferedReader (new InputStreamReader (new FileInputStream (configFile))); 74 String line; 75 while ((line = reader.readLine()) != null) { 76 System.out.println(line); 77 } 78 } 79 80 private static final class TestApp { 81 public static final NoExceptionLinkedQueue visitCalls = new NoExceptionLinkedQueue(); 82 83 public static void visitDSOApplicationConfig(ConfigVisitor visitor, DSOApplicationConfig cfg) { 84 visitCalls.put(new Object [] { visitor, cfg }); 85 } 86 } 87 88 } 89 | Popular Tags |