KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > simulator > distrunner > ArgParserTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.simulator.distrunner;
5
6 import com.tcsimulator.ClientSpec;
7 import com.tcsimulator.distrunner.ServerSpec;
8
9 import java.net.InetAddress JavaDoc;
10 import java.net.UnknownHostException JavaDoc;
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 JavaDoc {
43     InetAddress JavaDoc host = InetAddress.getLocalHost();
44     String JavaDoc hostName = host.getHostName();
45
46     String JavaDoc clientInfo = "client://" + hostName
47                         + "/test?vm.count=3&execution.count=5&jvm.args=-server,-Xms256m,-Xmx256m,-Xss128k";
48     SpecFactory specFactory = new SpecFactoryImpl();
49     ArgParser parser;
50     try {
51       parser = new ArgParser(new String JavaDoc[] { clientInfo }, specFactory, false, false);
52     } catch (ArgException e) {
53       throw new AssertionError JavaDoc(e);
54     }
55     assertEquals(clientInfo, ArgParser.getArgumentForClientSpec((ClientSpec) parser.getClientSpecs().iterator().next()));
56   }
57
58   public void testServerParsing() throws ArgException {
59     String JavaDoc[] cmdLine = new String JavaDoc[] { "server://cfisherpc.terracotta.lan/tmp/dso-sandbox?"
60                                       + "config.dso.http.port=3333&config.dso.jmx.port=2222&config.dso.dso.port=5555;"
61                                       + "control://cfisherpc.terracotta.lan/tmp/dso-sandbox" };
62
63     ArgParser parser = new ArgParser(cmdLine, new SpecFactoryImpl(), true, true);
64     ServerSpec controlServer = parser.getControlServerSpec();
65     System.out.println(controlServer.toString());
66     ServerSpec testServer = parser.getServerSpec();
67     System.out.println(testServer.toString());
68   }
69
70 }
71
Popular Tags