~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jdrmaa/test/org/ggf/drmaa/SimpleJobTemplateTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 *
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 *
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 *
 
9
 *
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 *
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 *
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 *
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
/*
 
33
 * SimpleJobTemplateTest.java
 
34
 * JUnit based test
 
35
 *
 
36
 * Created on November 13, 2004, 5:28 PM
 
37
 */
 
38
 
 
39
package org.ggf.drmaa;
 
40
 
 
41
import java.util.*;
 
42
import junit.framework.*;
 
43
 
 
44
/**
 
45
 *
 
46
 * @author dan.templeton@sun.com
 
47
 */
 
48
public class SimpleJobTemplateTest extends TestCase {
 
49
    private SimpleJobTemplate jt = null;
 
50
    
 
51
    public SimpleJobTemplateTest(java.lang.String testName) {
 
52
        super(testName);
 
53
    }
 
54
    
 
55
    public static Test suite() {
 
56
        TestSuite suite = new TestSuite(SimpleJobTemplateTest.class);
 
57
        return suite;
 
58
    }
 
59
    
 
60
    protected void setUp() {
 
61
        jt = new SimpleJobTemplate();
 
62
    }
 
63
    
 
64
    protected void tearDown() {
 
65
        jt = null;
 
66
    }
 
67
    
 
68
    /** Test of g|setRemoteCommand method, of class org.ggf.drmaa.JobTemplate. */
 
69
    public void testRemoteCommand() throws DrmaaException {
 
70
        System.out.println("testRemoteCommand");
 
71
        
 
72
        jt.setRemoteCommand("MyRemoteCommand");
 
73
        assertEquals("MyRemoteCommand", jt.getRemoteCommand());
 
74
    }
 
75
    
 
76
    /** Test of g|setArgs method, of class org.ggf.drmaa.JobTemplate. */
 
77
    public void testArgs() throws DrmaaException {
 
78
        System.out.println("testArgs");
 
79
        
 
80
        List args = Arrays.asList(new String[] {"arg1", "arg2", "arg3"});
 
81
        
 
82
        jt.setArgs(args);
 
83
        
 
84
        List retArgs = jt.getArgs();
 
85
        
 
86
        assertNotSame(args, retArgs);
 
87
        
 
88
        for (int count = 0; count < Math.min(args.size(), retArgs.size()); count++) {
 
89
            assertEquals(args.get(count), retArgs.get(count));
 
90
        }
 
91
    }
 
92
    
 
93
    /** Test of g|setJobSubmissionState method, of class org.ggf.drmaa.JobTemplate. */
 
94
    public void testJobSubmissionState() throws DrmaaException {
 
95
        System.out.println("testJobSubmissionState");
 
96
        
 
97
        jt.setJobSubmissionState(jt.HOLD_STATE);
 
98
        assertEquals(jt.HOLD_STATE, jt.getJobSubmissionState());
 
99
        jt.setJobSubmissionState(jt.ACTIVE_STATE);
 
100
        assertEquals(jt.ACTIVE_STATE, jt.getJobSubmissionState());
 
101
    }
 
102
    
 
103
    /** Test of g|setJobEnvironment method, of class org.ggf.drmaa.JobTemplate. */
 
104
    public void testJobEnvironment() throws DrmaaException {
 
105
        System.out.println("testJobEnvironment");
 
106
        
 
107
        Map env = new HashMap();
 
108
        env.put("PATH", "/usr/bin");
 
109
        env.put("LD_LIBRARY_PATH", "/usr/lib");
 
110
        
 
111
        jt.setJobEnvironment(env);
 
112
        
 
113
        Map retEnv = jt.getJobEnvironment();
 
114
        
 
115
        assertNotSame(env, retEnv);
 
116
        assertEquals(env, retEnv);
 
117
    }
 
118
    
 
119
    /** Test of g|setWorkingDirectory method, of class org.ggf.drmaa.JobTemplate. */
 
120
    public void testWorkingDirectory() throws DrmaaException {
 
121
        System.out.println("testWorkingDirectory");
 
122
        
 
123
        jt.setWorkingDirectory("/home/me");
 
124
        assertEquals("/home/me", jt.getWorkingDirectory());
 
125
    }
 
126
    
 
127
    /** Test of g|setJobCategory method, of class org.ggf.drmaa.JobTemplate. */
 
128
    public void testJobCategory() throws DrmaaException {
 
129
        System.out.println("testJobCategory");
 
130
        
 
131
        jt.setJobCategory("mycat");
 
132
        assertEquals("mycat", jt.getJobCategory());
 
133
    }
 
134
    
 
135
    /** Test of g|setNativeSpecification method, of class org.ggf.drmaa.JobTemplate. */
 
136
    public void testNativeSpecification() throws DrmaaException {
 
137
        System.out.println("testNativeSpecification");
 
138
        
 
139
        jt.setNativeSpecification("-shell yes");
 
140
        assertEquals("-shell yes", jt.getNativeSpecification());
 
141
    }
 
142
    
 
143
    /** Test of g|setEmail method, of class org.ggf.drmaa.JobTemplate. */
 
144
    public void testEmail() throws DrmaaException {
 
145
        System.out.println("testEmail");
 
146
        
 
147
        Set email = new HashSet(Arrays.asList(new String[] {"dant@germany", "admin"}));
 
148
        
 
149
        jt.setEmail(email);
 
150
        
 
151
        Set retEmail = jt.getEmail();
 
152
        
 
153
        assertNotSame(email, retEmail);
 
154
        assertEquals(email, retEmail);
 
155
    }
 
156
    
 
157
    /** Test of g|setBlockEmail method, of class org.ggf.drmaa.JobTemplate. */
 
158
    public void testBlockEmail() throws DrmaaException {
 
159
        System.out.println("testBlockEmail");
 
160
        
 
161
        jt.setBlockEmail(true);
 
162
        assertTrue(jt.getBlockEmail());
 
163
        jt.setBlockEmail(false);
 
164
        assertFalse(jt.getBlockEmail());
 
165
    }
 
166
    
 
167
    /** Test of g|setStartTime method, of class org.ggf.drmaa.JobTemplate. */
 
168
    public void testStartTime() throws DrmaaException {
 
169
        System.out.println("testStartTime");
 
170
        
 
171
        PartialTimestamp pt = new PartialTimestamp();
 
172
        Calendar cal = Calendar.getInstance();
 
173
        
 
174
        pt.set(pt.HOUR_OF_DAY, cal.get(cal.HOUR_OF_DAY) + 1);
 
175
        pt.set(pt.MINUTE, 0);
 
176
        
 
177
        jt.setStartTime(pt);
 
178
        
 
179
        PartialTimestamp retPt = jt.getStartTime();
 
180
        
 
181
        assertNotSame(pt, retPt);
 
182
        assertEquals(pt, retPt);
 
183
        
 
184
        pt.set(pt.HOUR_OF_DAY, cal.get(cal.HOUR_OF_DAY) - 1);
 
185
        
 
186
        jt.setStartTime(pt);
 
187
        
 
188
        retPt = jt.getStartTime();
 
189
        
 
190
        assertNotSame(pt, retPt);
 
191
        assertEquals(pt, retPt);
 
192
        
 
193
        pt.set(pt.CENTURY, 19);
 
194
        
 
195
        try {
 
196
            jt.setStartTime(pt);
 
197
            fail("Allowed start time in the past");
 
198
        } catch (IllegalArgumentException e) {
 
199
            /* Don't care. */
 
200
        }
 
201
    }
 
202
    
 
203
    /** Test of g|setJobName method, of class org.ggf.drmaa.JobTemplate. */
 
204
    public void testJobName() throws DrmaaException {
 
205
        System.out.println("testJobName");
 
206
        
 
207
        jt.setJobName("MyJob");
 
208
        assertEquals("MyJob", jt.getJobName());
 
209
    }
 
210
    
 
211
    /** Test of g|setInputPath method, of class org.ggf.drmaa.JobTemplate. */
 
212
    public void testInputPath() throws DrmaaException {
 
213
        System.out.println("testInputPath");
 
214
        
 
215
        jt.setInputPath("/tmp");
 
216
        assertEquals("/tmp", jt.getInputPath());
 
217
    }
 
218
    
 
219
    /** Test of g|setOutputPath method, of class org.ggf.drmaa.JobTemplate. */
 
220
    public void testOutputPath() throws DrmaaException {
 
221
        System.out.println("testOutputPath");
 
222
        
 
223
        jt.setOutputPath("/tmp");
 
224
        assertEquals("/tmp", jt.getOutputPath());
 
225
    }
 
226
    
 
227
    /** Test of g|setErrorPath method, of class org.ggf.drmaa.JobTemplate. */
 
228
    public void testErrorPath() throws DrmaaException {
 
229
        System.out.println("testErrorPath");
 
230
        
 
231
        jt.setErrorPath("/tmp");
 
232
        assertEquals("/tmp", jt.getErrorPath());
 
233
    }
 
234
    
 
235
    /** Test of g|setJoinFiles method, of class org.ggf.drmaa.JobTemplate. */
 
236
    public void testJoinFiles() throws DrmaaException {
 
237
        System.out.println("testJoinFiles");
 
238
        
 
239
        jt.setJoinFiles(true);
 
240
        assertTrue(jt.getJoinFiles());
 
241
        jt.setJoinFiles(false);
 
242
        assertFalse(jt.getJoinFiles());
 
243
    }
 
244
    
 
245
    /** Test of setTransferFiles method, of class org.ggf.drmaa.JobTemplate. */
 
246
    public void testTransferFiles() throws DrmaaException {
 
247
        System.out.println("testTransferFiles");
 
248
        
 
249
        FileTransferMode mode = new FileTransferMode(true, false, true);
 
250
        
 
251
        try {
 
252
            new SimpleJobTemplate().setTransferFiles(mode);
 
253
            fail("Allowed setting of unsupported transferFiles property");
 
254
        } catch (UnsupportedAttributeException e) {
 
255
            /* Don't care. */
 
256
        }
 
257
        
 
258
        try {
 
259
            new SimpleJobTemplate().getTransferFiles();
 
260
            fail("Allowed getting of unsupported transferFiles property");
 
261
        } catch (UnsupportedAttributeException e) {
 
262
            /* Don't care. */
 
263
        }
 
264
    }
 
265
    
 
266
    /** Test of g|setDeadlineTime method, of class org.ggf.drmaa.JobTemplate. */
 
267
    public void testDeadlineTime() throws DrmaaException {
 
268
        System.out.println("testDeadlineTime");
 
269
        
 
270
        PartialTimestamp pt = new PartialTimestamp();
 
271
        
 
272
        try {
 
273
            new SimpleJobTemplate().setDeadlineTime(pt);
 
274
            fail("Allowed setting of unsupported deadlineTime property");
 
275
        } catch (UnsupportedAttributeException e) {
 
276
            /* Don't care. */
 
277
        }
 
278
        
 
279
        try {
 
280
            new SimpleJobTemplate().getDeadlineTime();
 
281
            fail("Allowed getting of unsupported deadlineTime property");
 
282
        } catch (UnsupportedAttributeException e) {
 
283
            /* Don't care. */
 
284
        }
 
285
    }
 
286
    
 
287
    /** Test of g|setHardWallclockTimeLimit method, of class org.ggf.drmaa.JobTemplate. */
 
288
    public void testHardWallclockTimeLimit() throws DrmaaException {
 
289
        System.out.println("testHardWallclockTimeLimit");
 
290
        
 
291
        try {
 
292
            new SimpleJobTemplate().setHardWallclockTimeLimit(101L);
 
293
            fail("Allowed setting of unsupported hardWallclockTimeLimit property");
 
294
        } catch (UnsupportedAttributeException e) {
 
295
            /* Don't care. */
 
296
        }
 
297
        
 
298
        try {
 
299
            new SimpleJobTemplate().getHardWallclockTimeLimit();
 
300
            fail("Allowed getting of unsupported hardWallclockTimeLimit property");
 
301
        } catch (UnsupportedAttributeException e) {
 
302
            /* Don't care. */
 
303
        }
 
304
    }
 
305
    
 
306
    /** Test of g|setSoftWallclockTimeLimit method, of class org.ggf.drmaa.JobTemplate. */
 
307
    public void testSoftWallclockTimeLimit() throws DrmaaException {
 
308
        System.out.println("testSoftWallclockTimeLimit");
 
309
        
 
310
        try {
 
311
            new SimpleJobTemplate().setSoftWallclockTimeLimit(101L);
 
312
            fail("Allowed setting of unsupported softWallclockTimeLimit property");
 
313
        } catch (UnsupportedAttributeException e) {
 
314
            /* Don't care. */
 
315
        }
 
316
        
 
317
        try {
 
318
            new SimpleJobTemplate().getSoftWallclockTimeLimit();
 
319
            fail("Allowed getting of unsupported softWallclockTimeLimit property");
 
320
        } catch (UnsupportedAttributeException e) {
 
321
            /* Don't care. */
 
322
        }
 
323
    }
 
324
    
 
325
    /** Test of g|setHardRunDurationLimit method, of class org.ggf.drmaa.JobTemplate. */
 
326
    public void testHardRunDurationLimit() throws DrmaaException {
 
327
        System.out.println("testHardRunDurationLimit");
 
328
        
 
329
        try {
 
330
            new SimpleJobTemplate().setHardRunDurationLimit(101L);
 
331
            fail("Allowed setting of unsupported hardRunDurationLimit property");
 
332
        } catch (UnsupportedAttributeException e) {
 
333
            /* Don't care. */
 
334
        }
 
335
        
 
336
        try {
 
337
            new SimpleJobTemplate().getHardRunDurationLimit();
 
338
            fail("Allowed getting of unsupported hardRunDurationLimit property");
 
339
        } catch (UnsupportedAttributeException e) {
 
340
            /* Don't care. */
 
341
        }
 
342
    }
 
343
    
 
344
    /** Test of g|setSoftRunDurationLimit method, of class org.ggf.drmaa.JobTemplate. */
 
345
    public void testSoftRunDurationLimit() throws DrmaaException {
 
346
        System.out.println("testSoftRunDurationLimit");
 
347
        
 
348
        try {
 
349
            new SimpleJobTemplate().setSoftRunDurationLimit(101L);
 
350
            fail("Allowed setting of unsupported softRunDurationLimit property");
 
351
        } catch (UnsupportedAttributeException e) {
 
352
            /* Don't care. */
 
353
        }
 
354
        
 
355
        try {
 
356
            new SimpleJobTemplate().getSoftRunDurationLimit();
 
357
            fail("Allowed getting of unsupported softRunDurationLimit property");
 
358
        } catch (UnsupportedAttributeException e) {
 
359
            /* Don't care. */
 
360
        }
 
361
    }
 
362
    
 
363
    /** Test of getAttributeNames method, of class org.ggf.drmaa.JobTemplate. */
 
364
    public void testGetAttributeNames() throws DrmaaException {
 
365
        System.out.println("testGetAttributeNames");
 
366
        
 
367
        ArrayList names = new ArrayList(21);
 
368
        
 
369
        names.add("args");
 
370
        names.add("blockEmail");
 
371
        names.add("email");
 
372
        names.add("errorPath");
 
373
        names.add("inputPath");
 
374
        names.add("jobCategory");
 
375
        names.add("jobEnvironment");
 
376
        names.add("jobName");
 
377
        names.add("jobSubmissionState");
 
378
        names.add("joinFiles");
 
379
        names.add("nativeSpecification");
 
380
        names.add("outputPath");
 
381
        names.add("remoteCommand");
 
382
        names.add("startTime");
 
383
        names.add("workingDirectory");
 
384
        
 
385
        List retNames = new LinkedList(jt.getAttributeNames());
 
386
        
 
387
        Collections.sort(names);
 
388
        Collections.sort(retNames);
 
389
        
 
390
        assertEquals(names, retNames);
 
391
    }
 
392
    
 
393
    /** Test of getOptionalAttributeNames method, of class org.ggf.drmaa.JobTemplate. */
 
394
    public void testGetOptionalAttributeNames() {
 
395
        System.out.println("testGetOptionalAttributeNames");
 
396
        
 
397
        Set retNames = jt.getOptionalAttributeNames();
 
398
        
 
399
        assertEquals(Collections.EMPTY_SET, retNames);
 
400
    }
 
401
    
 
402
    /** Test of toString method, of class org.ggf.drmaa.JobTemplate. */
 
403
    public void testToString() throws DrmaaException {
 
404
        System.out.println("testToString");
 
405
        
 
406
        assertEquals("{blockEmail = false} {jobSubmissionState = ACTIVE_STATE} {joinFiles = false}",
 
407
                jt.toString());
 
408
        
 
409
        jt.setJobCategory("myCategory");
 
410
        
 
411
        assertEquals("{blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = ACTIVE_STATE} {joinFiles = false}",
 
412
                jt.toString());
 
413
        
 
414
        jt.setArgs(Arrays.asList(new String[] {"arg1", "arg2"}));
 
415
        
 
416
        assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = ACTIVE_STATE} {joinFiles = false}",
 
417
                jt.toString());
 
418
        
 
419
        jt.setJoinFiles(true);
 
420
        
 
421
        assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = ACTIVE_STATE} {joinFiles = true}",
 
422
                jt.toString());
 
423
        
 
424
        jt.setJobSubmissionState(jt.HOLD_STATE);
 
425
        
 
426
        assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = HOLD_STATE} {joinFiles = true}",
 
427
                jt.toString());
 
428
        
 
429
        jt.setNativeSpecification("-l arch=sol-sparc64");
 
430
        
 
431
        assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobSubmissionState = HOLD_STATE} {joinFiles = true} {nativeSpecification = \"-l arch=sol-sparc64\"}",
 
432
                jt.toString());
 
433
        
 
434
        Properties env = new Properties();
 
435
        env.setProperty("PATH", "/tmp:/usr/bin");
 
436
        env.setProperty("SHELL", "/usr/bin/csh");
 
437
        jt.setJobEnvironment(env);
 
438
        
 
439
        assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobEnvironment = [\"SHELL\" = \"/usr/bin/csh\"], [\"PATH\" = \"/tmp:/usr/bin\"]} {jobSubmissionState = HOLD_STATE} {joinFiles = true} {nativeSpecification = \"-l arch=sol-sparc64\"}",
 
440
                jt.toString());
 
441
        
 
442
        jt.setStartTime(new PartialTimestamp(19, 10, 49));
 
443
        
 
444
        assertEquals("{args = \"arg1\", \"arg2\"} {blockEmail = false} {jobCategory = myCategory} {jobEnvironment = [\"SHELL\" = \"/usr/bin/csh\"], [\"PATH\" = \"/tmp:/usr/bin\"]} {jobSubmissionState = HOLD_STATE} {joinFiles = true} {nativeSpecification = \"-l arch=sol-sparc64\"} {startTime = \"19:10:49\"}",
 
445
                jt.toString());
 
446
    }
 
447
}