001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tcsimulator;
005:
006: import com.tc.object.config.ConfigVisitor;
007: import com.tc.object.config.DSOApplicationConfig;
008: import com.tc.simulator.app.ApplicationConfig;
009: import com.tcsimulator.distrunner.ServerSpec;
010:
011: import java.util.ArrayList;
012: import java.util.Collection;
013: import java.util.HashMap;
014: import java.util.Iterator;
015: import java.util.List;
016: import java.util.Map;
017:
018: public class TestSpec {
019: // this is the Impl, not the interface because the portability restrictions are on the field type, not the
020: // instance type.
021: private ApplicationConfigImpl appConfig;
022: private Map containerSpecsByHostname;
023: private Map containerSpecsByVmName;
024: private int globalVmCount;
025: private Map serverSpecsByHostName;
026: private Map serverSpecsByType;
027:
028: public static void visitDSOApplicationConfig(ConfigVisitor visitor,
029: DSOApplicationConfig config) {
030: String classname = TestSpec.class.getName();
031: config.addIncludePattern(classname);
032: config.addIncludePattern(ContainerSpec.class.getName());
033: config.addWriteAutolock("* " + classname + ".*(..)");
034: visitor.visitDSOApplicationConfig(config,
035: ApplicationConfigImpl.class);
036: }
037:
038: public TestSpec(String className, int intensity, Collection cSpecs,
039: Collection sSpecs) {
040: containerSpecsByHostname = new HashMap();
041: containerSpecsByVmName = new HashMap();
042: serverSpecsByHostName = new HashMap();
043: serverSpecsByType = new HashMap();
044: GlobalVmNameGenerator vmNameGenerator = new GlobalVmNameGenerator();
045: int globalParticipantCount = 0;
046:
047: for (Iterator i = cSpecs.iterator(); i.hasNext();) {
048: ClientSpec cSpec = (ClientSpec) i.next();
049: String hostName = cSpec.getHostName();
050:
051: int vmCount = cSpec.getVMCount();
052: globalVmCount += vmCount;
053: int executionCount = cSpec.getExecutionCount();
054: List jvmArgs = cSpec.getJvmOpts();
055: globalParticipantCount += (vmCount * executionCount);
056:
057: Collection specList = (Collection) containerSpecsByHostname
058: .get(hostName);
059: if (specList == null) {
060: specList = new ArrayList();
061: this .containerSpecsByHostname.put(hostName, specList);
062: }
063:
064: for (int j = 0; j < vmCount; j++) {
065: String vmName = vmNameGenerator.nextVmName();
066: ContainerSpec newSpec = new ContainerSpec(vmName, cSpec
067: .getTestHome(), executionCount, jvmArgs);
068: specList.add(newSpec);
069: containerSpecsByVmName.put(vmName, newSpec);
070: }
071: }
072:
073: for (Iterator i = sSpecs.iterator(); i.hasNext();) {
074: ServerSpec sSpec = (ServerSpec) i.next();
075: String hostName = sSpec.getHostName();
076: int type = sSpec.getType();
077:
078: Collection specList = (Collection) serverSpecsByHostName
079: .get(hostName);
080: if (specList == null) {
081: specList = new ArrayList();
082: this .serverSpecsByHostName.put(hostName, specList);
083: }
084: specList.add(sSpec);
085:
086: specList = (Collection) serverSpecsByType.get(new Integer(
087: type));
088: if (specList == null) {
089: specList = new ArrayList();
090: this .serverSpecsByType.put(new Integer(type), specList);
091: }
092: specList.add(sSpec);
093: }
094:
095: this .appConfig = new ApplicationConfigImpl(className,
096: intensity, globalParticipantCount);
097: }
098:
099: public TestSpec() {
100: // Use this only after DSO object TestSpec has been created.
101: }
102:
103: public synchronized ApplicationConfig getTestConfig() {
104: return appConfig.copy();
105: }
106:
107: public Collection getContainerSpecsFor(String hostname) {
108: Collection rv = new ArrayList();
109: Collection containerSpecsByHostName = (Collection) containerSpecsByHostname
110: .get(hostname);
111: if (containerSpecsByHostName != null) {
112: for (Iterator i = ((Collection) containerSpecsByHostname
113: .get(hostname)).iterator(); i.hasNext();) {
114: rv.add(((ContainerSpec) i.next()).copy());
115: }
116: }
117: return rv;
118: }
119:
120: public Collection getServerSpecsFor(String hostname) {
121: Collection rv = new ArrayList();
122: Collection serverSpecs = (Collection) serverSpecsByHostName
123: .get(hostname);
124: if (serverSpecs != null) {
125: for (Iterator i = serverSpecs.iterator(); i.hasNext();) {
126: rv.add(((ServerSpec) i.next()).copy());
127: }
128: }
129: return rv;
130: }
131:
132: public Collection getServerSpecsFor(int type) {
133: Collection rv = new ArrayList();
134: Collection serverSpecs = (Collection) serverSpecsByType
135: .get(new Integer(type));
136: if (serverSpecs != null) {
137: for (Iterator i = serverSpecs.iterator(); i.hasNext();) {
138: rv.add(((ServerSpec) i.next()).copy());
139: }
140: }
141: return rv;
142: }
143:
144: public ContainerSpec getContainerSpecFor(String vmName) {
145: return ((ContainerSpec) containerSpecsByVmName.get(vmName))
146: .copy();
147: }
148:
149: public synchronized int getGlobalVmCount() {
150: return globalVmCount;
151: }
152:
153: public long getAppExecutionTimeout() {
154: return 1000 * 60 * 24 * 365 * 10;
155: }
156:
157: public synchronized String toString() {
158: StringBuffer result = new StringBuffer();
159: result.append(getClass().getName()
160: + " [containerSpecsByVmName: ");
161: result.append(containerSpecsByVmName);
162: result.append(", containerSpecsByHostname: ");
163: result.append(containerSpecsByHostname);
164: result.append(", globalVmCount: ");
165: result.append(globalVmCount + "]");
166: return result.toString();
167: }
168:
169: }
|