Line | Hits | Source |
---|---|---|
1 | package umich.cac.data.test; | |
2 | ||
3 | import java.util.logging.Level; | |
4 | import java.util.logging.Logger; | |
5 | ||
6 | import junit.framework.Test; | |
7 | import junit.framework.TestCase; | |
8 | import junit.framework.TestSuite; | |
9 | import umich.cac.data.FieldName; | |
10 | import umich.cac.data.NodesField; | |
11 | ||
12 | /** | |
13 | * Tests for NodesField class. | |
14 | * | |
15 | * @author rmach@umich.edu | |
16 | * @version $Header: /cvsroot/pbsaccounting/pbsaccounting/src/umich/cac/data/test/NodesFieldTest.java,v 1.3 2003/10/21 19:08:00 rodmach Exp $ | |
17 | */ | |
18 | ||
19 | public class NodesFieldTest extends TestCase { | |
20 | ||
21 | /** The new line seperator for this system */ | |
22 | 24 | private String nl = System.getProperty("line.separator"); |
23 | ||
24 | /** Logger */ | |
25 | 27 | private Logger logger = Logger.getLogger(NodesFieldTest.class.getName()); |
26 | ||
27 | /** | |
28 | * Constructor | |
29 | * | |
30 | * @param testName | |
31 | * name of test suite | |
32 | */ | |
33 | ||
34 | public NodesFieldTest(java.lang.String testName) { | |
35 | 24 | super(testName); |
36 | 24 | } |
37 | ||
38 | /** | |
39 | * Main - for running stand-alone test | |
40 | * | |
41 | * @param args | |
42 | * command line arguments | |
43 | */ | |
44 | ||
45 | public static void main(java.lang.String[] args) { | |
46 | 0 | junit.textui.TestRunner.run(suite()); |
47 | ||
48 | 0 | } |
49 | ||
50 | /** | |
51 | * Return a new test suite | |
52 | * | |
53 | * @return a new test suite | |
54 | */ | |
55 | ||
56 | public static Test suite() { | |
57 | 3 | TestSuite suite = new TestSuite(NodesFieldTest.class); |
58 | 3 | return suite; |
59 | } | |
60 | ||
61 | /** | |
62 | * Test with the nodes=comma separated list of nodes | |
63 | */ | |
64 | ||
65 | public void testSingleNode() { | |
66 | ||
67 | 3 | String inputLine = "tg-c091"; |
68 | ||
69 | 3 | String expectedOutput = |
70 | "<nodes>" | |
71 | + nl | |
72 | + "<nodegroup numnodes=\"1\">" | |
73 | + nl | |
74 | + "<nodename>tg-c091</nodename>" | |
75 | + nl | |
76 | + "</nodegroup>" | |
77 | + nl | |
78 | + "</nodes>" | |
79 | + nl; | |
80 | ||
81 | 3 | testExample(inputLine, expectedOutput); |
82 | ||
83 | 3 | } |
84 | ||
85 | /** | |
86 | * Test with the PPN property, which is converted to attribute | |
87 | */ | |
88 | ||
89 | public void testNodesFieldWithPPN() { | |
90 | ||
91 | 3 | String inputLine = "2:ppn=2"; |
92 | ||
93 | 3 | String expectedOutput = |
94 | "<nodes>" | |
95 | + nl | |
96 | + "<nodegroup numnodes=\"2\" ppn=\"2\"></nodegroup>" | |
97 | + nl | |
98 | + "</nodes>" | |
99 | + nl; | |
100 | ||
101 | 3 | testExample(inputLine, expectedOutput); |
102 | ||
103 | 3 | } |
104 | ||
105 | /** | |
106 | * Test with a shared global property | |
107 | */ | |
108 | ||
109 | public void testNodesWithShared() { | |
110 | ||
111 | 3 | String inputLine = "9#shared"; |
112 | ||
113 | 3 | String expectedOutput = |
114 | "<nodes>" | |
115 | + nl | |
116 | + "<globalproperty>shared</globalproperty>" | |
117 | + nl | |
118 | + "<nodegroup numnodes=\"9\"></nodegroup>" | |
119 | + nl | |
120 | + "</nodes>" | |
121 | + nl; | |
122 | ||
123 | 3 | testExample(inputLine, expectedOutput); |
124 | ||
125 | 3 | } |
126 | ||
127 | /** | |
128 | * Test just plain node number | |
129 | */ | |
130 | ||
131 | public void testNodes() { | |
132 | ||
133 | 3 | String inputLine = "9"; |
134 | ||
135 | 3 | String expectedOutput = |
136 | "<nodes>" | |
137 | + nl | |
138 | + "<nodegroup numnodes=\"9\"></nodegroup>" | |
139 | + nl | |
140 | + "</nodes>" | |
141 | + nl; | |
142 | ||
143 | 3 | testExample(inputLine, expectedOutput); |
144 | ||
145 | 3 | } |
146 | ||
147 | /** | |
148 | * hosts are separated by +'s in the accounting file | |
149 | */ | |
150 | public void testPlusSeparatedListOfHosts() { | |
151 | 3 | String inputLine = "tg-c065+tg-c066"; |
152 | ||
153 | 3 | String expectedOutput = |
154 | "<nodes>" | |
155 | + nl | |
156 | + "<nodegroup numnodes=\"1\">" | |
157 | + nl | |
158 | + "<nodename>tg-c065</nodename>" | |
159 | + nl | |
160 | + "</nodegroup>" | |
161 | + nl | |
162 | + "<nodegroup numnodes=\"1\">" | |
163 | + nl | |
164 | + "<nodename>tg-c066</nodename>" | |
165 | + nl | |
166 | + "</nodegroup>" | |
167 | + nl | |
168 | + "</nodes>" | |
169 | + nl; | |
170 | ||
171 | 3 | testExample(inputLine, expectedOutput); |
172 | ||
173 | 3 | } |
174 | ||
175 | /** | |
176 | * Test a complicated example that has hosts with various properties | |
177 | */ | |
178 | ||
179 | public void testExampleInput() { | |
180 | ||
181 | 3 | String inputLine = "4:large+5:fast:large+2:compute:large"; |
182 | ||
183 | 3 | String expectedOutput = |
184 | "<nodes>" | |
185 | + nl | |
186 | + "<nodegroup numnodes=\"4\">" | |
187 | + nl | |
188 | + "<property>large</property>" | |
189 | + nl | |
190 | + "</nodegroup>" | |
191 | + nl | |
192 | + "<nodegroup numnodes=\"5\">" | |
193 | + nl | |
194 | + "<property>fast</property>" | |
195 | + nl | |
196 | + "<property>large</property>" | |
197 | + nl | |
198 | + "</nodegroup>" | |
199 | + nl | |
200 | + "<nodegroup numnodes=\"2\">" | |
201 | + nl | |
202 | + "<property>compute</property>" | |
203 | + nl | |
204 | + "<property>large</property>" | |
205 | + nl | |
206 | + "</nodegroup>" | |
207 | + nl | |
208 | + "</nodes>" | |
209 | + nl; | |
210 | ||
211 | 3 | testExample(inputLine, expectedOutput); |
212 | ||
213 | 3 | } |
214 | ||
215 | /** | |
216 | * I have found this case in an accounting example sent to me that has the | |
217 | * host:ppn=number of nodes instead of 2:ppn=2 | |
218 | */ | |
219 | public void testHostnameWithPPN() { | |
220 | 3 | String inputLine = "tg-c128:ppn=2"; |
221 | ||
222 | 3 | String expectedOutput = |
223 | "<nodes>" | |
224 | + nl | |
225 | + "<nodegroup numnodes=\"1\" ppn=\"2\">" | |
226 | + nl | |
227 | + "<nodename>tg-c128</nodename>" | |
228 | + nl | |
229 | + "</nodegroup>" | |
230 | + nl | |
231 | + "</nodes>" | |
232 | + nl; | |
233 | ||
234 | 3 | testExample(inputLine, expectedOutput); |
235 | ||
236 | 3 | } |
237 | ||
238 | /* | |
239 | * Test the example input | |
240 | * | |
241 | * @param inputLine input line to test @param expectedOutput the expected | |
242 | * output | |
243 | */ | |
244 | private void testExample(String inputLine, String expectedOutput) { | |
245 | ||
246 | try { | |
247 | ||
248 | 24 | NodesField userField = new NodesField(FieldName.NODES, inputLine); |
249 | 24 | String output = userField.toXML(); |
250 | ||
251 | 24 | if (logger.isLoggable(Level.INFO)) { |
252 | 24 | StringBuffer outputBuffer = new StringBuffer(); |
253 | 24 | outputBuffer.append(nl); |
254 | 24 | outputBuffer.append("CALCULATED"); |
255 | 24 | outputBuffer.append(nl); |
256 | 24 | outputBuffer.append(output); |
257 | 24 | outputBuffer.append(nl); |
258 | 24 | outputBuffer.append("EXPECTED"); |
259 | 24 | outputBuffer.append(nl); |
260 | 24 | outputBuffer.append(expectedOutput); |
261 | 24 | outputBuffer.append(nl); |
262 | ||
263 | //Use system.out because logger buffers, and mixes with junit | |
264 | // out on error | |
265 | 24 | System.out.println(outputBuffer.toString()); |
266 | ||
267 | } | |
268 | ||
269 | 24 | assertTrue(output.equals(expectedOutput)); |
270 | ||
271 | 0 | } catch (Exception e) { |
272 | 0 | fail(); |
273 | 24 | } |
274 | ||
275 | 24 | } |
276 | ||
277 | /** | |
278 | * Test that the User field properly renders XML | |
279 | */ | |
280 | ||
281 | public void testNodesFieldWithGlobalPropertiesAndProperties() { | |
282 | ||
283 | 3 | String inputLine = "4+2:ppn=2:fatdisk:bigscratch#shared"; |
284 | ||
285 | 3 | String expectedOutput = |
286 | "<nodes>" | |
287 | + nl | |
288 | + "<globalproperty>shared</globalproperty>" | |
289 | + nl | |
290 | + "<nodegroup numnodes=\"4\"></nodegroup>" | |
291 | + nl | |
292 | + "<nodegroup numnodes=\"2\" ppn=\"2\">" | |
293 | + nl | |
294 | + "<property>fatdisk</property>" | |
295 | + nl | |
296 | + "<property>bigscratch</property>" | |
297 | + nl | |
298 | + "</nodegroup>" | |
299 | + nl | |
300 | + "</nodes>" | |
301 | + nl; | |
302 | ||
303 | 3 | testExample(inputLine, expectedOutput); |
304 | 3 | } |
305 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |