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 com.tcsimulator.ClientSpec;
07: import com.tcsimulator.distrunner.ServerSpec;
08:
09: import java.net.InetAddress;
10: import java.net.UnknownHostException;
11:
12: import junit.framework.TestCase;
13:
14: public class ArgParserTest extends TestCase {
15: /*
16: * public void testBasics() throws Throwable { String[] args = null; SpecFactory specFactory = new SpecFactoryImpl();
17: * String client1Host = "client1Host"; String client1TestHome = "/client1TestHome"; int clientIntensity = 2; int
18: * client1VMCount = 2; int client1ExecutionCount = 2; String client2Host = "client2Host"; String client2TestHome =
19: * "/client2TestHome"; String client1Description = "client://" + client1Host + client1TestHome + "?vm.count=" +
20: * client1VMCount + "&execution.count=" + client1ExecutionCount; String client2Description = "client://" + client2Host +
21: * client2TestHome; ClientSpec client1 = new ClientSpecImpl(client1Host, client1TestHome, client1VMCount,
22: * client1ExecutionCount); ClientSpec client2 = new ClientSpecImpl(client2Host, client2TestHome, 1, 1); Collection
23: * clientSpecs = new LinkedList(); clientSpecs.add(client1); clientSpecs.add(client2); String serverHostname =
24: * "myServer"; String serverTestHome = "/my/server/test/home"; ServerSpec server = new ServerSpecImpl(serverHostname,
25: * serverTestHome); String testClassname = "myTestClassname"; args = new String[] { "server://" + serverHostname +
26: * serverTestHome, client1Description, client2Description, "classname=" + testClassname }; ArgParser argParser = new
27: * ArgParser(args, specFactory, true); assertEquals(clientSpecs, argParser.getClientSpecs()); assertEquals(server,
28: * argParser.getServerSpec()); assertEquals(testClassname, argParser.getTestClassname()); }
29: */
30: /*
31: * public void testNoArguments() { String[] args = null; SpecFactory specFactory = new SpecFactoryImpl(); Collection
32: * clientSpecs = new LinkedList(); String serverHostname = "myServer"; String serverTestHome = "/my/server/test/home";
33: * ServerSpec server = new ServerSpecImpl(serverHostname, serverTestHome, ArgParser.DEFAULT_SERVER_CACHE,
34: * ArgParser.DEFAULT_HTTP_PORT, ArgParser.DEFAULT_JMX_PORT, ArgParser.DEFAULT_DSO_PORT, new ArrayList(),
35: * ServerSpec.TEST_SERVER); String testClassname = "undefined"; int intensity = -1; args = new String[] { "server://" +
36: * serverHostname + serverTestHome, "classname=" + testClassname }; ArgParser argParser; try { argParser = new
37: * ArgParser(args, specFactory, true, false); } catch (ArgException e) { throw new AssertionError(e); }
38: * assertEquals(clientSpecs, argParser.getClientSpecs()); assertEquals(server.toString(),
39: * argParser.getServerSpec().toString()); assertEquals(testClassname, argParser.getTestClassname());
40: * assertEquals(intensity, argParser.getIntensity()); }
41: */
42: public void testJvmOptParsing() throws UnknownHostException {
43: InetAddress host = InetAddress.getLocalHost();
44: String hostName = host.getHostName();
45:
46: String clientInfo = "client://"
47: + hostName
48: + "/test?vm.count=3&execution.count=5&jvm.args=-server,-Xms256m,-Xmx256m,-Xss128k";
49: SpecFactory specFactory = new SpecFactoryImpl();
50: ArgParser parser;
51: try {
52: parser = new ArgParser(new String[] { clientInfo },
53: specFactory, false, false);
54: } catch (ArgException e) {
55: throw new AssertionError(e);
56: }
57: assertEquals(clientInfo, ArgParser
58: .getArgumentForClientSpec((ClientSpec) parser
59: .getClientSpecs().iterator().next()));
60: }
61:
62: public void testServerParsing() throws ArgException {
63: String[] cmdLine = new String[] { "server://cfisherpc.terracotta.lan/tmp/dso-sandbox?"
64: + "config.dso.http.port=3333&config.dso.jmx.port=2222&config.dso.dso.port=5555;"
65: + "control://cfisherpc.terracotta.lan/tmp/dso-sandbox" };
66:
67: ArgParser parser = new ArgParser(cmdLine,
68: new SpecFactoryImpl(), true, true);
69: ServerSpec controlServer = parser.getControlServerSpec();
70: System.out.println(controlServer.toString());
71: ServerSpec testServer = parser.getServerSpec();
72: System.out.println(testServer.toString());
73: }
74:
75: }
|