01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.simulator.distrunner;
05:
06: import org.apache.commons.io.FileUtils;
07:
08: import com.tc.object.config.ConfigVisitor;
09: 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,
39: clientTestHome, vmCount, executionCount,
40: new ArrayList()));
41:
42: InetAddress host = InetAddress.getLocalHost();
43: String localHostName = host.getHostName();
44:
45: String serverHostname = localHostName;
46: String serverTestHome = getTempDirectory().getAbsolutePath();
47:
48: File licenseFile = new File(serverTestHome, LICENSE_FILENAME);
49: FileUtils.touch(licenseFile);
50:
51: ServerSpec serverSpec = new ServerSpecImpl(serverHostname,
52: serverTestHome, -1, -1, -1, new ArrayList(),
53: ServerSpec.TEST_SERVER);
54:
55: String testAppClassName = TestApp.class.getName();
56: /* Setup setup = */new Setup(new String[] {}, serverSpec,
57: testAppClassName, clientSpecs, intensity, false);
58:
59: Sandbox sandbox = new Sandbox(new File(serverTestHome),
60: Sandbox.TEST_SERVER);
61:
62: File configFile = new File(serverTestHome, sandbox
63: .getConfigFile().getName());
64: assertFalse(configFile.exists());
65: assertNull(TestApp.visitCalls.poll(0));
66:
67: Collection classesToVisit = new ArrayList();
68: classesToVisit.add(TestApp.class);
69: ConfigWriter configWriter = new ConfigWriter(serverSpec,
70: classesToVisit, sandbox);
71: configWriter.writeConfigFile();
72:
73: assertNotNull(TestApp.visitCalls.poll(0));
74: assertTrue(configFile.exists());
75: dumpConfigFile(configFile);
76:
77: }
78:
79: private void dumpConfigFile(File configFile) throws IOException {
80: BufferedReader reader = new BufferedReader(
81: new InputStreamReader(new FileInputStream(configFile)));
82: String line;
83: while ((line = reader.readLine()) != null) {
84: System.out.println(line);
85: }
86: }
87:
88: private static final class TestApp {
89: public static final NoExceptionLinkedQueue visitCalls = new NoExceptionLinkedQueue();
90:
91: public static void visitDSOApplicationConfig(
92: ConfigVisitor visitor, DSOApplicationConfig cfg) {
93: visitCalls.put(new Object[] { visitor, cfg });
94: }
95: }
96:
97: }
|