1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
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
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.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
33
* SessionImplJobTest.java
36
* Created on November 15, 2004, 10:41 AM
39
package com.sun.grid.drmaa;
42
import junit.framework.*;
43
import org.ggf.drmaa.*;
44
import com.sun.grid.Settings;
48
* @author dan.templeton@sun.com
50
public class SessionImplJobTest extends TestCase {
51
private static final String SLEEPER;
52
private Session session = null;
55
SLEEPER = Settings.get(Settings.SCRIPTS_DIR) + "/suspendable_sleeper.sh";
58
public SessionImplJobTest(java.lang.String testName) {
62
public static Test suite() {
63
TestSuite suite = new TestSuite(SessionImplJobTest.class);
67
public void setUp() throws DrmaaException {
68
session = SessionFactory.getFactory().getSession();
72
public void tearDown() throws DrmaaException {
75
} catch (NoActiveSessionException ex) {
82
/** Test of runJob method, of class com.sun.grid.drmaa.SessionImpl. */
83
public void testBadJobTemplate() {
84
System.out.println("testBadJobTemplate");
86
JobTemplate jt = new BadJobTemplate();
91
fail("Allowed bad job template");
92
} catch (InvalidJobTemplateException e) {
97
session.runBulkJobs(jt, 1, 3, 1);
98
fail("Allowed bad job template");
99
} catch (InvalidJobTemplateException e) {
104
session.deleteJobTemplate(jt);
105
fail("Allowed bad job template");
106
} catch (InvalidJobTemplateException e) {
109
} catch (DrmaaException e) {
110
fail("Exception while trying to run job: " + e.getMessage());
114
/** Test of runJob method, of class com.sun.grid.drmaa.SessionImpl. */
115
public void testBadRunJob() {
116
System.out.println("testBadRunJob");
119
session.runJob(null);
120
fail("Allowed null job template");
121
} catch (NullPointerException e) {
123
} catch (DrmaaException e) {
124
fail("Exception while trying to run job: " + e.getMessage());
128
public void testRunJob() {
129
System.out.println("testRunJob");
132
JobTemplate jt = this.createSleeperTemplate(5);
134
String jobId = session.runJob(jt);
136
assertNotNull(jobId);
138
session.deleteJobTemplate(jt);
139
} catch (DrmaaException e) {
140
fail("Exception while trying to run a job: " + e.getMessage());
144
/** Test of runBulkJobs method, of class com.sun.grid.drmaa.SessionImpl. */
145
public void testBadRunBulkJobs() {
146
System.out.println("testBadRunBulkJobs");
149
JobTemplate jt = this.createSleeperTemplate(5);
152
session.runBulkJobs(null, 1, 2, 1);
153
fail("Allowed null job template");
154
} catch (NullPointerException e) {
159
session.runBulkJobs(jt, -1, 2, 1);
160
fail("Allowed invalid start id");
161
} catch (IllegalArgumentException e) {
166
session.runBulkJobs(jt, 1, -2, 1);
167
fail("Allowed invalid end id");
168
} catch (IllegalArgumentException e) {
173
session.runBulkJobs(jt, 1, 2, -1);
174
fail("Allowed negative step when end > start");
175
} catch (IllegalArgumentException e) {
180
session.runBulkJobs(jt, 3, 2, 1);
181
fail("Allowed end < start");
182
} catch (IllegalArgumentException e) {
186
session.deleteJobTemplate(jt);
187
} catch (DrmaaException e) {
188
fail("Exception while trying to run jobs: " + e.getMessage());
192
public void testRunMonoBulkJobs() {
193
System.out.println("testRunMonoBulkJobs");
196
JobTemplate jt = this.createSleeperTemplate(5);
198
List jobIds = session.runBulkJobs(jt, 1, 1, 1);
200
assertNotNull(jobIds);
201
assertEquals(1, jobIds.size());
203
session.deleteJobTemplate(jt);
204
} catch (DrmaaException e) {
205
fail("Exception while trying to run jobs: " + e.getMessage());
209
public void testRunDualBulkJobs() {
210
System.out.println("testRunDualBulkJobs");
213
JobTemplate jt = this.createSleeperTemplate(5);
215
List jobIds = session.runBulkJobs(jt, 1, 2, 1);
217
assertNotNull(jobIds);
218
assertEquals(2, jobIds.size());
220
session.deleteJobTemplate(jt);
221
} catch (DrmaaException e) {
222
fail("Exception while trying to run jobs: " + e.getMessage());
226
public void testRunBulkJobs() {
227
System.out.println("testRunBulkJobs");
230
JobTemplate jt = this.createSleeperTemplate(5);
232
List jobIds = session.runBulkJobs(jt, 2, 6, 2);
234
assertNotNull(jobIds);
235
assertEquals(3, jobIds.size());
237
session.deleteJobTemplate(jt);
238
} catch (DrmaaException e) {
239
fail("Exception while trying to run jobs: " + e.getMessage());
243
/** Test of wait method, of class com.sun.grid.drmaa.SessionImpl. */
244
public void testBadWait() {
245
System.out.println("testBadWait");
248
JobTemplate jt = this.createSleeperTemplate(5);
250
String jobId = session.runJob(jt);
252
/* Test bad parameters */
254
session.wait(null, 0L);
255
fail("Allowed null job id");
256
} catch (NullPointerException e) {
261
session.wait("asdf", 0L);
262
fail("Allowed invalid job id");
263
} catch (IllegalArgumentException e) {
268
session.wait(jobId, -3L);
269
fail("Allowed negative timeout");
270
} catch (IllegalArgumentException e) {
274
session.deleteJobTemplate(jt);
275
} catch (DrmaaException e) {
276
fail("Exception while trying to wait for a job: " + e.getMessage());
280
public void testWaitForever() {
281
System.out.println("testWaitForever");
284
JobTemplate jt = this.createSleeperTemplate(5);
286
String jobId = session.runJob(jt);
288
/* Test wait forever */
289
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
292
assertEquals(jobId, info.getJobId());
294
/* There's no reason that this job should exit prematurely. */
295
assertTrue(info.hasExited());
296
assertEquals(0, info.getExitStatus());
298
/* Make sure that the previous wait worked. */
300
session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
301
fail("First wait didn't reap job exit info");
302
} catch (InvalidJobException e) {
306
/* Eventually I need to build a libtestjdrmaa.so with some utilities in
307
* it, like sendSignal() and causeException(), so that I can test some
310
session.deleteJobTemplate(jt);
311
} catch (DrmaaException e) {
312
fail("Exception while trying to wait for a job: " + e.getMessage());
316
public void testNoWait() {
317
System.out.println("testNoWait");
320
JobTemplate jt = this.createSleeperTemplate(5);
323
String jobId = session.runJob(jt);
324
long now = System.currentTimeMillis();
328
info = session.wait(jobId, session.TIMEOUT_NO_WAIT);
329
fail("Waited for job to finish; ignored 0s timeout");
330
} catch (ExitTimeoutException e) {
334
long later = System.currentTimeMillis();
336
/* I assume that 1 second is more than enough time to check the cache
338
assertTrue((later - now) < 1000L);
340
/* Make sure that the previous wait didn't disrupt anything. */
341
info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
344
assertEquals(jobId, info.getJobId());
346
/* There's no reason that this job should exit prematurely. */
347
assertTrue(info.hasExited());
348
assertEquals(0, info.getExitStatus());
350
/* Make sure that the previous wait worked. */
352
session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
353
fail("Second wait didn't reap job exit info");
354
} catch (InvalidJobException e) {
358
session.deleteJobTemplate(jt);
359
} catch (DrmaaException e) {
360
fail("Exception while trying to wait for a job: " + e.getMessage());
364
public void testWaitTimeout() {
365
System.out.println("testWaitTimeout");
368
JobTemplate jt = this.createSleeperTemplate(5);
370
/* Test timed wait */
371
String jobId = session.runJob(jt);
372
long now = System.currentTimeMillis();
373
/* I'm assuming that 3 seconds is not long enough for the job to be
374
* scheduled and run. */
378
info = session.wait(jobId, 3L);
379
fail("Waited for job to finish; ignored 3s timeout");
380
} catch (ExitTimeoutException e) {
384
long later = System.currentTimeMillis();
386
/* I'm assuming that there's no more than 1 second overhead in making
388
assertTrue((later - now) < 4000L);
390
/* Make sure that the previous wait didn't disrupt anything. */
391
info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
394
assertEquals(jobId, info.getJobId());
396
/* There's no reason that this job should exit prematurely. */
397
assertTrue(info.hasExited());
398
assertEquals(0, info.getExitStatus());
400
/* Make sure that the previous wait worked. */
402
session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
403
fail("Second wait didn't reap job exit info");
404
} catch (InvalidJobException e) {
408
session.deleteJobTemplate(jt);
409
} catch (DrmaaException e) {
410
fail("Exception while trying to wait for a job: " + e.getMessage());
414
public void testWait() {
415
System.out.println("testWait");
418
JobTemplate jt = this.createSleeperTemplate(5);
420
/* Test timed wait */
421
String jobId = session.runJob(jt);
422
JobInfo info = session.wait(jobId, 30L);
425
assertEquals(jobId, info.getJobId());
427
/* There's no reason that this job should exit prematurely. */
428
assertTrue(info.hasExited());
429
assertEquals(0, info.getExitStatus());
431
/* Make sure that the previous wait worked. */
433
session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
434
fail("First wait didn't reap job exit info");
435
} catch (InvalidJobException e) {
439
session.deleteJobTemplate(jt);
440
} catch (DrmaaException e) {
441
fail("Exception while trying to wait for a job: " + e.getMessage());
445
public void testWaitForeverAny() {
446
System.out.println("testWaitForeverAny");
449
JobTemplate jt = this.createSleeperTemplate(5);
451
String jobId = session.runJob(jt);
453
/* Test wait forever */
454
JobInfo info = session.wait(session.JOB_IDS_SESSION_ANY, session.TIMEOUT_WAIT_FOREVER);
457
assertEquals(jobId, info.getJobId());
459
/* There's no reason that this job should exit prematurely. */
460
assertTrue(info.hasExited());
461
assertEquals(0, info.getExitStatus());
463
/* Make sure that the previous wait worked. */
465
session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
466
fail("First wait didn't reap job exit info");
467
} catch (InvalidJobException e) {
471
/* Eventually I need to build a libtestjdrmaa.so with some utilities in
472
* it, like sendSignal() and causeException(), so that I can test some
475
session.deleteJobTemplate(jt);
476
} catch (DrmaaException e) {
477
fail("Exception while trying to wait for a job: " + e.getMessage());
481
public void testNoWaitAny() {
482
System.out.println("testNoWaitAny");
485
JobTemplate jt = this.createSleeperTemplate(5);
488
String jobId = session.runJob(jt);
489
long now = System.currentTimeMillis();
493
info = session.wait(session.JOB_IDS_SESSION_ANY, session.TIMEOUT_NO_WAIT);
494
fail("Waited for job to finish; ignored 0s timeout");
495
} catch (ExitTimeoutException e) {
499
long later = System.currentTimeMillis();
501
/* I assume that 1 second is more than enough time to check the cache
503
assertTrue((later - now) < 1000L);
505
/* Make sure that the previous wait didn't disrupt anything. */
506
info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
509
assertEquals(jobId, info.getJobId());
511
/* There's no reason that this job should exit prematurely. */
512
assertTrue(info.hasExited());
513
assertEquals(0, info.getExitStatus());
515
/* Make sure that the previous wait worked. */
517
session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
518
fail("Second wait didn't reap job exit info");
519
} catch (InvalidJobException e) {
523
session.deleteJobTemplate(jt);
524
} catch (DrmaaException e) {
525
fail("Exception while trying to wait for a job: " + e.getMessage());
529
public void testWaitTimeoutAny() {
530
System.out.println("testWaitTimeoutAny");
533
JobTemplate jt = this.createSleeperTemplate(5);
535
/* Test timed wait */
536
String jobId = session.runJob(jt);
537
long now = System.currentTimeMillis();
538
/* I'm assuming that 3 seconds is not long enough for the job to be
539
* scheduled and run. */
543
info = session.wait(session.JOB_IDS_SESSION_ANY, 3L);
544
fail("Waited for job to finish; ignored 3s timeout");
545
} catch (ExitTimeoutException e) {
549
long later = System.currentTimeMillis();
551
/* I'm assuming that there's no more than 1 second overhead in making
553
assertTrue((later - now) < 4000L);
555
/* Make sure that the previous wait didn't disrupt anything. */
556
info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
559
assertEquals(jobId, info.getJobId());
561
/* There's no reason that this job should exit prematurely. */
562
assertTrue(info.hasExited());
563
assertEquals(0, info.getExitStatus());
565
/* Make sure that the previous wait worked. */
567
session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
568
fail("Second wait didn't reap job exit info");
569
} catch (InvalidJobException e) {
573
session.deleteJobTemplate(jt);
574
} catch (DrmaaException e) {
575
fail("Exception while trying to wait for a job: " + e.getMessage());
579
public void testWaitAny() {
580
System.out.println("testWaitAny");
583
JobTemplate jt = this.createSleeperTemplate(5);
585
/* Test timed wait */
586
String jobId = session.runJob(jt);
587
JobInfo info = session.wait(session.JOB_IDS_SESSION_ANY, 30L);
590
assertEquals(jobId, info.getJobId());
592
/* There's no reason that this job should exit prematurely. */
593
assertTrue(info.hasExited());
594
assertEquals(0, info.getExitStatus());
596
/* Make sure that the previous wait worked. */
598
session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
599
fail("First wait didn't reap job exit info");
600
} catch (InvalidJobException e) {
604
session.deleteJobTemplate(jt);
605
} catch (DrmaaException e) {
606
fail("Exception while trying to wait for a job: " + e.getMessage());
610
/** Test of synchronize method, of class com.sun.grid.drmaa.SessionImpl. */
611
public void testBadSynchronize() {
612
System.out.println("testBadSynchronize");
615
JobTemplate jt = this.createSleeperTemplate(5);
617
List jobIds = session.runBulkJobs(jt, 1, 3, 1);
619
/* Test bad parameters */
621
session.synchronize(null, session.TIMEOUT_WAIT_FOREVER, true);
622
fail("Allowed null job id");
623
} catch (NullPointerException e) {
627
List badJobId = Arrays.asList(new String[] {"asdf"});
630
session.synchronize(badJobId, session.TIMEOUT_WAIT_FOREVER, true);
631
fail("Allowed invalid job id");
632
} catch (IllegalArgumentException e) {
637
session.synchronize(jobIds, -3, true);
638
fail("Allowed negative timeout");
639
} catch (IllegalArgumentException e) {
643
session.deleteJobTemplate(jt);
644
} catch (DrmaaException e) {
645
fail("Exception while trying to synchronize jobs: " + e.getMessage());
649
public void testSynchronizeForeverDispose() {
650
System.out.println("testSynchronizeForeverDispose");
653
JobTemplate jt = this.createSleeperTemplate(5);
655
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
657
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
658
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
660
/* Test wait forever, dispose */
661
session.synchronize(jobIds, session.TIMEOUT_WAIT_FOREVER, true);
663
Iterator i = jobIds.iterator();
665
while (i.hasNext()) {
667
session.wait((String)i.next(), session.TIMEOUT_NO_WAIT);
668
fail("Synchronize didn't reap exit information");
669
} catch (InvalidJobException e) {
674
session.deleteJobTemplate(jt);
675
} catch (DrmaaException e) {
676
fail("Exception while trying to synchronize jobs: " + e.getMessage());
680
public void testSynchronizeNoWaitDispose() {
681
System.out.println("testSynchronizeNoWaitDispose");
684
JobTemplate jt = this.createSleeperTemplate(5);
686
/* Test no wait, dispose */
687
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
689
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
690
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
692
long now = System.currentTimeMillis();
695
session.synchronize(jobIds, session.TIMEOUT_NO_WAIT, true);
696
fail("Waited for jobs to finish; ignored 0s timeout");
697
} catch (ExitTimeoutException e) {
701
long later = System.currentTimeMillis();
703
/* I assume that 1 second is more than enough time to check the cache
705
assertTrue((later - now) < 1000L);
707
/* Make sure that the previous synchronize didn't disrupt anything. */
708
Iterator i = jobIds.iterator();
710
while (i.hasNext()) {
711
String jobId = (String)i.next();
712
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
715
assertEquals(jobId, info.getJobId());
717
/* There's no reason that this job should exit prematurely. */
718
assertTrue(info.hasExited());
719
assertEquals(0, info.getExitStatus());
722
session.deleteJobTemplate(jt);
723
} catch (DrmaaException e) {
724
fail("Exception while trying to synchronize jobs: " + e.getMessage());
728
public void testSynchronizeTimeoutDispose() {
729
System.out.println("testSynchronizeTimeoutDispose");
732
JobTemplate jt = this.createSleeperTemplate(15);
734
/* Test timed wait (timeout), dispose */
735
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
737
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
738
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
740
long now = System.currentTimeMillis();
742
/* I'm assuming that 3 seconds won't be enough time for the job to be
743
* scheduled and run. */
745
session.synchronize(jobIds, 3L, true);
746
fail("Waited for jobs to finish; ignored 3s timeout");
747
} catch (ExitTimeoutException e) {
751
long later = System.currentTimeMillis();
753
/* I assume that there is less than 1 second overhead in making the
755
assertTrue((later - now) < 4000L);
757
/* Make sure that the previous synchronize didn't disrupt anything. */
758
Iterator i = jobIds.iterator();
760
while (i.hasNext()) {
761
String jobId = (String)i.next();
762
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
765
assertEquals(jobId, info.getJobId());
767
/* There's no reason that this job should exit prematurely. */
768
assertTrue(info.hasExited());
769
assertEquals(0, info.getExitStatus());
772
session.deleteJobTemplate(jt);
773
} catch (DrmaaException e) {
774
fail("Exception while trying to synchronize jobs: " + e.getMessage());
778
public void testSynchronizeDispose() {
779
System.out.println("testSynchronizeDispose");
782
JobTemplate jt = this.createSleeperTemplate(5);
784
/* Test timed wait, dispose */
785
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
787
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
788
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
790
session.synchronize(jobIds, 600L, true);
792
/* Make sure that the previous synchronize didn't disrupt anything. */
793
Iterator i = jobIds.iterator();
795
while (i.hasNext()) {
797
session.wait((String)i.next(), session.TIMEOUT_NO_WAIT);
798
fail("Synchronize didn't reap exit information");
799
} catch (InvalidJobException e) {
804
session.deleteJobTemplate(jt);
805
} catch (DrmaaException e) {
806
fail("Exception while trying to synchronize jobs: " + e.getMessage());
810
public void testSynchronizeForever() {
811
System.out.println("testSynchronizeForever");
814
JobTemplate jt = this.createSleeperTemplate(5);
816
/* Test wait forever, no dispose */
817
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
819
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
820
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
822
session.synchronize(jobIds, session.TIMEOUT_WAIT_FOREVER, false);
824
/* Make sure that the previous synchronize didn't disrupt anything. */
825
Iterator i = jobIds.iterator();
827
while (i.hasNext()) {
828
String jobId = (String)i.next();
829
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
832
assertEquals(jobId, info.getJobId());
834
/* There's no reason that this job should exit prematurely. */
835
assertTrue(info.hasExited());
836
assertEquals(0, info.getExitStatus());
839
session.deleteJobTemplate(jt);
840
} catch (DrmaaException e) {
841
fail("Exception while trying to synchronize jobs: " + e.getMessage());
845
public void testSynchronizeNoWait() {
846
System.out.println("testSynchronizeNoWait");
849
JobTemplate jt = this.createSleeperTemplate(5);
851
/* Test no wait, no dispose */
852
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
854
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
855
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
857
long now = System.currentTimeMillis();
860
session.synchronize(jobIds, session.TIMEOUT_NO_WAIT, false);
861
fail("Waited for jobs to finish; ignored 0s timeout");
862
} catch (ExitTimeoutException e) {
866
long later = System.currentTimeMillis();
868
/* I assume that there is less than 1 second overhead in making the
870
assertTrue((later - now) < 1000L);
872
/* Make sure that the previous synchronize didn't disrupt anything. */
873
Iterator i = jobIds.iterator();
875
while (i.hasNext()) {
876
String jobId = (String)i.next();
877
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
880
assertEquals(jobId, info.getJobId());
882
/* There's no reason that this job should exit prematurely. */
883
assertTrue(info.hasExited());
884
assertEquals(0, info.getExitStatus());
887
session.deleteJobTemplate(jt);
888
} catch (DrmaaException e) {
889
fail("Exception while trying to synchronize jobs: " + e.getMessage());
893
public void testSynchronizeTimeout() {
894
System.out.println("testSynchronizeTimeout");
897
JobTemplate jt = this.createSleeperTemplate(15);
899
/* Test timed wait (timeout), no dispose */
900
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
902
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
903
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
905
long now = System.currentTimeMillis();
907
/* I'm assuming that 3 seconds won't be enough time for the job to be
908
* scheduled and run. */
910
session.synchronize(jobIds, 3L, false);
911
fail("Waited for jobs to finish; ignored 3s timeout");
912
} catch (ExitTimeoutException e) {
916
long later = System.currentTimeMillis();
918
/* I assume that there is less than 1 second overhead in making the
920
assertTrue((later - now) < 4000L);
922
/* Make sure that the previous synchronize didn't disrupt anything. */
923
Iterator i = jobIds.iterator();
925
while (i.hasNext()) {
926
String jobId = (String)i.next();
927
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
930
assertEquals(jobId, info.getJobId());
932
/* There's no reason that this job should exit prematurely. */
933
assertTrue(info.hasExited());
934
assertEquals(0, info.getExitStatus());
937
session.deleteJobTemplate(jt);
938
} catch (DrmaaException e) {
939
fail("Exception while trying to synchronize jobs: " + e.getMessage());
943
public void testSynchronize() {
944
System.out.println("testSynchronize");
947
JobTemplate jt = this.createSleeperTemplate(5);
949
/* Test timed wait (timeout), no dispose */
950
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
952
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
953
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
955
session.synchronize(jobIds, 600L, false);
957
/* Make sure that the previous synchronize didn't disrupt anything. */
958
Iterator i = jobIds.iterator();
960
while (i.hasNext()) {
961
String jobId = (String)i.next();
962
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
965
assertEquals(jobId, info.getJobId());
967
/* There's no reason that this job should exit prematurely. */
968
assertTrue(info.hasExited());
969
assertEquals(0, info.getExitStatus());
972
session.deleteJobTemplate(jt);
973
} catch (DrmaaException e) {
974
fail("Exception while trying to synchronize jobs: " + e.getMessage());
978
public void testSynchronizeForeverDisposeAll() {
979
System.out.println("testSynchronizeForeverDisposeAll");
982
JobTemplate jt = this.createSleeperTemplate(5);
984
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
986
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
987
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
989
/* Test wait forever, dispose */
990
session.synchronize(Collections.singletonList(session.JOB_IDS_SESSION_ALL), session.TIMEOUT_WAIT_FOREVER, true);
992
Iterator i = jobIds.iterator();
994
while (i.hasNext()) {
996
session.wait((String)i.next(), session.TIMEOUT_NO_WAIT);
997
fail("Synchronize didn't reap exit information");
998
} catch (InvalidJobException e) {
1003
session.deleteJobTemplate(jt);
1004
} catch (DrmaaException e) {
1005
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1009
public void testSynchronizeNoWaitDisposeAll() {
1010
System.out.println("testSynchronizeNoWaitDisposeAll");
1013
JobTemplate jt = this.createSleeperTemplate(5);
1015
/* Test no wait, dispose */
1016
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
1018
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1019
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1021
long now = System.currentTimeMillis();
1024
session.synchronize(Collections.singletonList(session.JOB_IDS_SESSION_ALL), session.TIMEOUT_NO_WAIT, true);
1025
fail("Waited for jobs to finish; ignored 0s timeout");
1026
} catch (ExitTimeoutException e) {
1030
long later = System.currentTimeMillis();
1032
/* I assume that 1 second is more than enough time to check the cache
1034
assertTrue((later - now) < 1000L);
1036
/* Make sure that the previous synchronize didn't disrupt anything. */
1037
Iterator i = jobIds.iterator();
1039
while (i.hasNext()) {
1040
String jobId = (String)i.next();
1041
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
1043
assertNotNull(info);
1044
assertEquals(jobId, info.getJobId());
1046
/* There's no reason that this job should exit prematurely. */
1047
assertTrue(info.hasExited());
1048
assertEquals(0, info.getExitStatus());
1051
session.deleteJobTemplate(jt);
1052
} catch (DrmaaException e) {
1053
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1057
public void testSynchronizeTimeoutDisposeAll() {
1058
System.out.println("testSynchronizeTimeoutDisposeAll");
1061
JobTemplate jt = this.createSleeperTemplate(15);
1063
/* Test timed wait (timeout), dispose */
1064
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
1066
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1067
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1069
long now = System.currentTimeMillis();
1071
/* I'm assuming that 3 seconds won't be enough time for the job to be
1072
* scheduled and run. */
1074
session.synchronize(Collections.singletonList(session.JOB_IDS_SESSION_ALL), 3L, true);
1075
fail("Waited for jobs to finish; ignored 3s timeout");
1076
} catch (ExitTimeoutException e) {
1080
long later = System.currentTimeMillis();
1082
/* I assume that there is less than 1 second overhead in making the
1084
assertTrue((later - now) < 4000L);
1086
/* Make sure that the previous synchronize didn't disrupt anything. */
1087
Iterator i = jobIds.iterator();
1089
while (i.hasNext()) {
1090
String jobId = (String)i.next();
1091
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
1093
assertNotNull(info);
1094
assertEquals(jobId, info.getJobId());
1096
/* There's no reason that this job should exit prematurely. */
1097
assertTrue(info.hasExited());
1098
assertEquals(0, info.getExitStatus());
1101
session.deleteJobTemplate(jt);
1102
} catch (DrmaaException e) {
1103
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1107
public void testSynchronizeDisposeAll() {
1108
System.out.println("testSynchronizeDisposeAll");
1111
JobTemplate jt = this.createSleeperTemplate(5);
1113
/* Test timed wait, dispose */
1114
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
1116
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1117
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1119
session.synchronize(Collections.singletonList(session.JOB_IDS_SESSION_ALL), 600L, true);
1121
/* Make sure that the previous synchronize didn't disrupt anything. */
1122
Iterator i = jobIds.iterator();
1124
while (i.hasNext()) {
1126
JobInfo info = session.wait((String)i.next(), session.TIMEOUT_NO_WAIT);
1127
fail("Synchronize didn't reap exit information for " + info.getJobId());
1128
} catch (InvalidJobException e) {
1133
session.deleteJobTemplate(jt);
1134
} catch (DrmaaException e) {
1135
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1139
public void testSynchronizeForeverAll() {
1140
System.out.println("testSynchronizeForeverAll");
1143
JobTemplate jt = this.createSleeperTemplate(5);
1145
/* Test wait forever, no dispose */
1146
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
1148
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1149
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1151
session.synchronize(Collections.singletonList(session.JOB_IDS_SESSION_ALL), session.TIMEOUT_WAIT_FOREVER, false);
1153
/* Make sure that the previous synchronize didn't disrupt anything. */
1154
Iterator i = jobIds.iterator();
1156
while (i.hasNext()) {
1157
String jobId = (String)i.next();
1158
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
1160
assertNotNull(info);
1161
assertEquals(jobId, info.getJobId());
1163
/* There's no reason that this job should exit prematurely. */
1164
assertTrue(info.hasExited());
1165
assertEquals(0, info.getExitStatus());
1168
session.deleteJobTemplate(jt);
1169
} catch (DrmaaException e) {
1170
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1174
public void testSynchronizeNoWaitAll() {
1175
System.out.println("testSynchronizeNoWaitAll");
1178
JobTemplate jt = this.createSleeperTemplate(5);
1180
/* Test no wait, no dispose */
1181
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
1183
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1184
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1186
long now = System.currentTimeMillis();
1189
session.synchronize(Collections.singletonList(session.JOB_IDS_SESSION_ALL), session.TIMEOUT_NO_WAIT, false);
1190
fail("Waited for jobs to finish; ignored 0s timeout");
1191
} catch (ExitTimeoutException e) {
1195
long later = System.currentTimeMillis();
1197
/* I assume that there is less than 1 second overhead in making the
1199
assertTrue((later - now) < 1000L);
1201
/* Make sure that the previous synchronize didn't disrupt anything. */
1202
Iterator i = jobIds.iterator();
1204
while (i.hasNext()) {
1205
String jobId = (String)i.next();
1206
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
1208
assertNotNull(info);
1209
assertEquals(jobId, info.getJobId());
1211
/* There's no reason that this job should exit prematurely. */
1212
assertTrue(info.hasExited());
1213
assertEquals(0, info.getExitStatus());
1216
session.deleteJobTemplate(jt);
1217
} catch (DrmaaException e) {
1218
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1222
public void testSynchronizeTimeoutAll() {
1223
System.out.println("testSynchronizeTimeoutAll");
1226
JobTemplate jt = this.createSleeperTemplate(15);
1228
/* Test timed wait (timeout), no dispose */
1229
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
1231
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1232
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1234
long now = System.currentTimeMillis();
1236
/* I'm assuming that 3 seconds won't be enough time for the job to be
1237
* scheduled and run. */
1239
session.synchronize(Collections.singletonList(session.JOB_IDS_SESSION_ALL), 3L, false);
1240
fail("Waited for jobs to finish; ignored 3s timeout");
1241
} catch (ExitTimeoutException e) {
1245
long later = System.currentTimeMillis();
1247
/* I assume that there is less than 1 second overhead in making the
1249
assertTrue((later - now) < 4000L);
1251
/* Make sure that the previous synchronize didn't disrupt anything. */
1252
Iterator i = jobIds.iterator();
1254
while (i.hasNext()) {
1255
String jobId = (String)i.next();
1256
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
1258
assertNotNull(info);
1259
assertEquals(jobId, info.getJobId());
1261
/* There's no reason that this job should exit prematurely. */
1262
assertTrue(info.hasExited());
1263
assertEquals(0, info.getExitStatus());
1266
session.deleteJobTemplate(jt);
1267
} catch (DrmaaException e) {
1268
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1272
public void testSynchronizeAll() {
1273
System.out.println("testSynchronizeAll");
1276
JobTemplate jt = this.createSleeperTemplate(5);
1278
/* Test timed wait (timeout), no dispose */
1279
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
1281
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1282
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1284
session.synchronize(Collections.singletonList(session.JOB_IDS_SESSION_ALL), 600L, false);
1286
/* Make sure that the previous synchronize didn't disrupt anything. */
1287
Iterator i = jobIds.iterator();
1289
while (i.hasNext()) {
1290
String jobId = (String)i.next();
1291
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
1293
assertNotNull(info);
1294
assertEquals(jobId, info.getJobId());
1296
/* There's no reason that this job should exit prematurely. */
1297
assertTrue(info.hasExited());
1298
assertEquals(0, info.getExitStatus());
1301
session.deleteJobTemplate(jt);
1302
} catch (DrmaaException e) {
1303
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1307
public void testSynchronizeForeverDisposeMoreThanAll() {
1308
System.out.println("testSynchronizeDisposeMoreThanAll");
1311
JobTemplate jt = this.createSleeperTemplate(5);
1313
/* Test timed wait, dispose */
1314
List jobIds = new LinkedList(session.runBulkJobs(jt, 1, 3, 1));
1316
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1317
jobIds.addAll(session.runBulkJobs(jt, 1, 3, 1));
1319
List myJobIds = new ArrayList(2);
1321
myJobIds.add(jobIds.get(0));
1322
myJobIds.add(session.JOB_IDS_SESSION_ALL);
1323
session.synchronize(myJobIds, session.TIMEOUT_WAIT_FOREVER, true);
1325
/* Make sure that the previous synchronize reaped exit info. */
1326
Iterator i = jobIds.iterator();
1328
while (i.hasNext()) {
1330
session.wait((String)i.next(), session.TIMEOUT_NO_WAIT);
1331
fail("Synchronize didn't reap exit information");
1332
} catch (InvalidJobException e) {
1337
session.deleteJobTemplate(jt);
1338
} catch (DrmaaException e) {
1339
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1343
public void testSynchronizeNonexistant() {
1344
System.out.println("testSynchronizeNonexistant");
1347
JobTemplate jt = this.createSleeperTemplate(5);
1349
/* Test timed wait (timeout), no dispose */
1350
String jobId = session.runJob(jt);
1351
/* Create a valid, unknown id. */
1352
String nextId = Integer.toString(Integer.parseInt(jobId) + 1);
1353
List jobIds = Collections.singletonList(nextId);
1356
session.synchronize(jobIds, session.TIMEOUT_WAIT_FOREVER, false);
1358
} catch (InvalidJobException e) {
1359
fail("Synchronize on non-existant job id failed");
1362
/* Wait for the real job to end. */
1363
JobInfo info = session.wait(jobId, session.TIMEOUT_WAIT_FOREVER);
1365
assertNotNull(info);
1366
assertEquals(jobId, info.getJobId());
1368
/* There's no reason that this job should exit prematurely. */
1369
assertTrue(info.hasExited());
1370
assertEquals(0, info.getExitStatus());
1372
session.deleteJobTemplate(jt);
1373
} catch (DrmaaException e) {
1374
fail("Exception while trying to synchronize jobs: " + e.getMessage());
1378
/** Test of getJobProgramStatus method, of class com.sun.grid.drmaa.SessionImpl. */
1379
public void testBadGetJobProgramStatus() {
1380
System.out.println("testBadGetJobProgramStatus");
1384
session.getJobProgramStatus(null);
1385
fail("Allowed null job id");
1386
} catch (NullPointerException e) {
1391
session.getJobProgramStatus("asdf");
1392
fail("Allowed invalid job id");
1393
} catch (IllegalArgumentException e) {
1396
} catch (DrmaaException e) {
1397
fail("Exception while trying to get job status: " + e.getMessage());
1401
public void testGetJobProgramStatus() {
1402
System.out.println("testGetJobProgramStatus");
1405
JobTemplate jt = this.createSleeperTemplate(5);
1407
String jobId = session.runJob(jt);
1408
/* Make sure it doesn't throw an exception. We can't really be sure
1409
* what the state will be at this point. */
1410
session.getJobProgramStatus(jobId);
1411
/* We use synchronize so that we don't reap the job info. */
1412
session.synchronize(Collections.singletonList(jobId), session.TIMEOUT_WAIT_FOREVER, false);
1414
int status = session.getJobProgramStatus(jobId);
1416
/* No reason why this job should fail. */
1417
assertEquals(session.DONE, status);
1419
/* How do we test the other states??? */
1421
session.deleteJobTemplate(jt);
1422
} catch (DrmaaException e) {
1423
fail("Exception while trying to get job status: " + e.getMessage());
1427
/** Test of control method, of class com.sun.grid.drmaa.SessionImpl. */
1428
public void testBadControl() {
1429
System.out.println("testBadControl");
1432
JobTemplate jt = this.createSleeperTemplate(5);
1434
String jobId = session.runJob(jt);
1437
session.control(null, session.HOLD);
1438
fail("Allowed null job id");
1439
} catch (NullPointerException e) {
1444
session.control("asdf", session.HOLD);
1445
fail("Allowed invalid job id");
1446
} catch (IllegalArgumentException e) {
1451
session.control(jobId, -10);
1452
fail("Allowed invalid action");
1453
} catch (IllegalArgumentException e) {
1457
session.deleteJobTemplate(jt);
1458
} catch (DrmaaException e) {
1459
fail("Exception while trying to get job status: " + e.getMessage());
1463
public void testControl() {
1464
System.out.println("testControl");
1467
JobTemplate jt = this.createSleeperTemplate(60000);
1469
String jobId = session.runJob(jt);
1471
session.deleteJobTemplate(jt);
1473
/* Take a nap so that we give the job time to get scheduled. */
1475
Thread.sleep(30000);
1476
} catch (InterruptedException e) {
1477
fail("Sleep was interrupted");
1480
int status = session.getJobProgramStatus(jobId);
1482
/* Make sure the job is running. */
1483
assertEquals(session.RUNNING, status);
1485
session.control(jobId, session.HOLD);
1487
/* Take a nap so that we give the job time to held. */
1489
Thread.sleep(30000);
1490
} catch (InterruptedException e) {
1491
fail("Sleep was interrupted");
1494
status = session.getJobProgramStatus(jobId);
1495
assertEquals(session.USER_ON_HOLD, status);
1497
session.control(jobId, session.RELEASE);
1499
/* Take a nap so that we give the job time to released. */
1501
Thread.sleep(30000);
1502
} catch (InterruptedException e) {
1503
fail("Sleep was interrupted");
1506
status = session.getJobProgramStatus(jobId);
1507
assertEquals(session.RUNNING, status);
1509
session.control(jobId, session.SUSPEND);
1511
/* Take a nap so that we give the job time to suspended. */
1513
Thread.sleep(30000);
1514
} catch (InterruptedException e) {
1515
fail("Sleep was interrupted");
1518
status = session.getJobProgramStatus(jobId);
1519
assertEquals(session.USER_SUSPENDED, status);
1521
session.control(jobId, session.RESUME);
1523
/* Take a nap so that we give the job time to resumed. */
1525
Thread.sleep(30000);
1526
} catch (InterruptedException e) {
1527
fail("Sleep was interrupted");
1530
status = session.getJobProgramStatus(jobId);
1531
assertEquals(session.RUNNING, status);
1533
session.control(jobId, session.TERMINATE);
1535
/* Take a nap so that we give the job time to killed. */
1537
Thread.sleep(60000);
1538
} catch (InterruptedException e) {
1539
fail("Sleep was interrupted");
1542
status = session.getJobProgramStatus(jobId);
1543
assertEquals(session.FAILED, status);
1544
} catch (DrmaaException e) {
1545
fail("Exception while trying to get job status: " + e.getMessage());
1549
public void testControlAll() {
1550
System.out.println("testControlAll");
1553
JobTemplate jt = this.createSleeperTemplate(60000);
1555
String jobId1 = session.runJob(jt);
1556
String jobId2 = session.runJob(jt);
1557
String jobId3 = session.runJob(jt);
1559
session.deleteJobTemplate(jt);
1561
/* Take a nap so that we give the jobs time to get scheduled. */
1563
Thread.sleep(30000);
1564
} catch (InterruptedException e) {
1565
fail("Sleep was interrupted");
1568
/* Make sure the job is running. */
1569
assertEquals(session.RUNNING, session.getJobProgramStatus(jobId1));
1570
assertEquals(session.RUNNING, session.getJobProgramStatus(jobId2));
1571
assertEquals(session.RUNNING, session.getJobProgramStatus(jobId3));
1573
session.control(Session.JOB_IDS_SESSION_ALL, session.HOLD);
1575
/* Take a nap so that we give the jobs time to held. */
1577
Thread.sleep(30000);
1578
} catch (InterruptedException e) {
1579
fail("Sleep was interrupted");
1582
assertEquals(session.USER_ON_HOLD, session.getJobProgramStatus(jobId1));
1583
assertEquals(session.USER_ON_HOLD, session.getJobProgramStatus(jobId2));
1584
assertEquals(session.USER_ON_HOLD, session.getJobProgramStatus(jobId3));
1586
session.control(Session.JOB_IDS_SESSION_ALL, session.RELEASE);
1588
/* Take a nap so that we give the jobs time to released. */
1590
Thread.sleep(30000);
1591
} catch (InterruptedException e) {
1592
fail("Sleep was interrupted");
1595
assertEquals(session.RUNNING, session.getJobProgramStatus(jobId1));
1596
assertEquals(session.RUNNING, session.getJobProgramStatus(jobId2));
1597
assertEquals(session.RUNNING, session.getJobProgramStatus(jobId3));
1599
session.control(Session.JOB_IDS_SESSION_ALL, session.SUSPEND);
1601
/* Take a nap so that we give the jobs time to suspended. */
1603
Thread.sleep(30000);
1604
} catch (InterruptedException e) {
1605
fail("Sleep was interrupted");
1608
assertEquals(session.USER_SUSPENDED, session.getJobProgramStatus(jobId1));
1609
assertEquals(session.USER_SUSPENDED, session.getJobProgramStatus(jobId2));
1610
assertEquals(session.USER_SUSPENDED, session.getJobProgramStatus(jobId3));
1612
session.control(Session.JOB_IDS_SESSION_ALL, session.RESUME);
1614
/* Take a nap so that we give the jobs time to resumed. */
1616
Thread.sleep(30000);
1617
} catch (InterruptedException e) {
1618
fail("Sleep was interrupted");
1621
assertEquals(session.RUNNING, session.getJobProgramStatus(jobId1));
1622
assertEquals(session.RUNNING, session.getJobProgramStatus(jobId2));
1623
assertEquals(session.RUNNING, session.getJobProgramStatus(jobId3));
1625
session.control(Session.JOB_IDS_SESSION_ALL, session.TERMINATE);
1627
/* Take a nap so that we give the jobs time to killed. */
1629
Thread.sleep(60000);
1630
} catch (InterruptedException e) {
1631
fail("Sleep was interrupted");
1634
assertEquals(session.FAILED, session.getJobProgramStatus(jobId1));
1635
assertEquals(session.FAILED, session.getJobProgramStatus(jobId2));
1636
assertEquals(session.FAILED, session.getJobProgramStatus(jobId3));
1637
} catch (DrmaaException e) {
1638
fail("Exception while trying to get job status: " + e.getMessage());
1642
public void testRecoverableSession() throws DrmaaException {
1643
System.out.println("testRecoverableSession");
1645
String contact = session.getContact();
1647
JobTemplate jt = this.createSleeperTemplate(120);
1649
String jobId1 = session.runJob(jt);
1651
session.deleteJobTemplate(jt);
1653
jt = this.createSleeperTemplate(10);
1655
String jobId2 = session.runJob(jt);
1657
session.deleteJobTemplate(jt);
1659
jt = this.createSleeperTemplate(10);
1660
jt.setJobSubmissionState(jt.HOLD_STATE);
1662
List jobIds34 = session.runBulkJobs(jt, 1, 2, 1);
1664
session.deleteJobTemplate(jt);
1665
session.control((String)jobIds34.get(0), session.RELEASE);
1669
/* Take a nap so that we give the job time to get scheduled. */
1671
Thread.sleep(60000);
1672
} catch (InterruptedException e) {
1673
fail("Sleep was interrupted");
1676
session.init(contact);
1678
JobInfo ji = session.wait(jobId1, session.TIMEOUT_WAIT_FOREVER);
1680
assertEquals(true, ji.hasExited());
1681
assertEquals(0, ji.getExitStatus());
1682
assertEquals(jobId1, ji.getJobId());
1685
ji = session.wait(jobId2, session.TIMEOUT_WAIT_FOREVER);
1687
assertNull(ji.getResourceUsage());
1688
} catch (InvalidJobException e) {
1689
// Supposed to happen
1692
ji = session.wait((String)jobIds34.get(0), session.TIMEOUT_WAIT_FOREVER);
1693
assertNull(ji.getResourceUsage());
1696
session.wait((String)jobIds34.get(1), session.TIMEOUT_NO_WAIT);
1697
fail("Call to wait() did not time out as expect");
1698
} catch (ExitTimeoutException ex) {
1699
// Supposed to happen
1702
session.control((String)jobIds34.get(1), session.TERMINATE);
1705
private JobTemplate createSleeperTemplate(int sleep) throws DrmaaException {
1706
JobTemplate jt = session.createJobTemplate();
1708
jt.setRemoteCommand(SLEEPER);
1709
jt.setArgs(Collections.singletonList(Integer.toString(sleep)));
1710
jt.setOutputPath(":/dev/null");
1711
jt.setJoinFiles(true);
1716
private class BadJobTemplate extends SimpleJobTemplate {
1717
public BadJobTemplate() {