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__*/
32
package com.sun.grid.jgdi.event;
34
import com.sun.grid.jgdi.BaseTestCase;
35
import com.sun.grid.jgdi.JGDI;
36
import com.sun.grid.jgdi.EventClient;
37
import com.sun.grid.jgdi.JobSubmitter;
38
import java.util.HashMap;
40
import junit.framework.Test;
41
import junit.framework.TestSuite;
46
public class JobTaskEventTestCase extends BaseTestCase {
49
private EventClient evc;
51
/** Creates a new instance of SpecialEventTestCase */
52
public JobTaskEventTestCase(String testName) {
56
protected void setUp() throws Exception {
59
evc = createEventClient(0);
61
logger.fine("SetUp done");
64
protected void tearDown() throws Exception {
73
public void testJobTaskEvents() throws Exception {
76
jgdi.disableQueues(new String[]{"*"}, false);
78
int numberOfTasks = 10;
80
int jobid = JobSubmitter.submitJob(getCurrentCluster(), new String[]{"-t", "1-" + numberOfTasks, "$SGE_ROOT/examples/jobs/sleeper.sh", "1"});
82
Map<EventTypeEnum,Integer> map = new HashMap<EventTypeEnum,Integer>();
83
map.put(EventTypeEnum.JobTaskAdd, 1);
84
map.put(EventTypeEnum.JobTaskDel, 1);
85
map.put(EventTypeEnum.JobDel, 1);
87
evc.subscribe(map.keySet());
90
JobTaskEventListener lis = new JobTaskEventListener(jobid);
91
evc.addEventListener(lis);
97
jgdi.enableQueues(new String[]{"*"}, false);
100
assertTrue("timeout while waiting for job finish event", lis.waitForJobFinish(timeout));
101
assertEquals("too few job task add events", numberOfTasks, lis.getAddEventCount());
102
assertEquals("too few job task del events", numberOfTasks - 1, lis.getDelEventCount());
106
class JobTaskEventListener implements EventListener {
108
private final Object syncObj = new Object();
109
private int addEventCount = 0;
110
private int delEventCount = 0;
111
private boolean finished = false;
114
public JobTaskEventListener(int jobid) {
118
public void eventOccured(Event evt) {
120
if (evt instanceof JobTaskAddEvent) {
121
JobTaskAddEvent jte = (JobTaskAddEvent) evt;
122
if (jte.getJobId() == jobid) {
124
logger.info("task " + jte.getJobId() + "." + jte.getTaskNumber() + " started");
126
} else if (evt instanceof JobTaskDelEvent) {
127
JobTaskDelEvent tde = (JobTaskDelEvent) evt;
128
if (tde.getJobId() == jobid) {
130
logger.info("task " + tde.getJobId() + "." + tde.getTaskNumber() + " deleted");
132
} else if (evt instanceof JobDelEvent) {
133
JobDelEvent jde = (JobDelEvent) evt;
134
if (jde.getJobNumber() == jobid) {
135
logger.info("got job delete event: " + jde);
136
synchronized (syncObj) {
144
public boolean waitForJobFinish(int timeout) throws InterruptedException {
145
long end = System.currentTimeMillis() + (timeout * 1000);
146
synchronized (syncObj) {
148
long waittime = end - System.currentTimeMillis();
150
logger.info("timeout while waiting for final usage event");
153
syncObj.wait(waittime);
159
public int getAddEventCount() {
160
return addEventCount;
163
public int getDelEventCount() {
164
return delEventCount;
168
public static Test suite() {
169
TestSuite suite = new TestSuite(JobTaskEventTestCase.class);