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

« back to all changes in this revision

Viewing changes to source/libs/jgdi/test/com/sun/grid/jgdi/ClusterQueueJobSlotTestCase.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
package com.sun.grid.jgdi;
 
33
 
 
34
import com.sun.grid.jgdi.configuration.ClusterQueue;
 
35
import java.util.Set;
 
36
import java.util.logging.Level;
 
37
import java.util.logging.Logger;
 
38
import junit.framework.Test;
 
39
import junit.framework.TestSuite;
 
40
 
 
41
/**
 
42
 *
 
43
 */
 
44
public class ClusterQueueJobSlotTestCase extends BaseTestCase {
 
45
    
 
46
    private ClusterQueue testClusterQueue;
 
47
    
 
48
    /**
 
49
     * Creates a new instance of ClusterQueueJobSlotTestCase
 
50
     */
 
51
    public ClusterQueueJobSlotTestCase(String name) {
 
52
        super(name);
 
53
    }
 
54
    
 
55
    public static Test suite() {
 
56
        TestSuite suite = new TestSuite( ClusterQueueJobSlotTestCase.class);
 
57
        return suite;
 
58
    }
 
59
    
 
60
    public void testUpdateJobSlots() throws Exception {
 
61
        
 
62
        JGDI jgdi = super.createJGDI();
 
63
        try {
 
64
            
 
65
            ClusterQueue testObj = jgdi.getClusterQueue("all.q");
 
66
            
 
67
            testObj.setName("new.q");
 
68
            
 
69
            jgdi.addClusterQueue(testObj);
 
70
            try {
 
71
                ClusterQueue retObj = jgdi.getClusterQueue(testObj.getName());
 
72
                
 
73
                String host = TestValueFactory.getNextHostname();
 
74
                retObj.putJobSlots(host, 10);
 
75
                
 
76
                jgdi.updateClusterQueue(retObj);
 
77
                
 
78
                ClusterQueue updatedObj = jgdi.getClusterQueue(testObj.getName());
 
79
                
 
80
                // TODO: problem with short/long hostnames as keys -> failure of test even for correct result
 
81
                //       workaround is correct hostname in Testvalues*.properties
 
82
                // System.out.println("retObj.getJobSlots(host) " + retObj.getJobSlots(host) + "(" + host + ")");
 
83
                // System.out.println("updateObj.getJobSlots(host) " + updatedObj.getJobSlots(host) + "(" + host + ")");
 
84
                // System.out.println("updateObj.getJobSlotsKeys() " + updatedObj.getJobSlotsKeys());
 
85
                assertEquals(retObj.getJobSlots(host), updatedObj.getJobSlots(host));
 
86
                
 
87
                retObj.removeJobSlots(host);
 
88
                Logger logger = Logger.getLogger("com.sun.grid.jgdi");
 
89
                Level orgLevel = logger.getLevel();
 
90
                logger.setLevel(Level.FINE);
 
91
                jgdi.updateClusterQueue(retObj);
 
92
                
 
93
                updatedObj = jgdi.getClusterQueue(testObj.getName());
 
94
                logger.setLevel(orgLevel);
 
95
                
 
96
                Set hostnames = updatedObj.getJobSlotsKeys();
 
97
                assertFalse(hostnames.contains(host));
 
98
                
 
99
            } finally {
 
100
                jgdi.deleteClusterQueue(testObj);
 
101
            }
 
102
            
 
103
        } finally {
 
104
            jgdi.close();
 
105
        }
 
106
        
 
107
        
 
108
    }
 
109
    
 
110
//   public void testWriteXML() throws Exception {
 
111
//      String[] clusterNames = getClusterNames();
 
112
//
 
113
//      for (int i=0; i<clusterNames.length;i++) {
 
114
//         JGDI gdi = createJGDI();
 
115
//         try {
 
116
//            for (ClusterQueue cq : gdi.getClusterQueueList()) {
 
117
//               logger.fine("ClusterQueue " + cq.getName() + "----------");
 
118
//               File file = File.createTempFile("cq_" + cq.getName(), ".xml" );
 
119
//               XMLUtil.write(cq, file);
 
120
//               logger.fine("cq " + cq.getName() + " -> " + file.getAbsolutePath());
 
121
//               ClusterQueue cq1 = (ClusterQueue)XMLUtil.read(file);
 
122
//               assertTrue("cq1 is not equals to cq2", cq.equalsCompletely(cq1));
 
123
//            }
 
124
//         } finally {
 
125
//            gdi.close();
 
126
//         }
 
127
//      }
 
128
//
 
129
//
 
130
//   }
 
131
//   public void testAdd() throws Exception {
 
132
//
 
133
//      JGDI gdi = createJGDI();
 
134
//      try {
 
135
//         ClassDescriptor cd = Util.getDescriptor(testClusterQueue.getClass());
 
136
//
 
137
//         cd.validate(testClusterQueue);
 
138
//
 
139
//         gdi.addClusterQueue(testClusterQueue);
 
140
//
 
141
//
 
142
//         gdi.deleteClusterQueue(testClusterQueue);
 
143
//      } finally {
 
144
//         gdi.close();
 
145
//      }
 
146
//   }
 
147
//
 
148
//   public void testAddProject() throws Exception {
 
149
//
 
150
//      JGDI gdi = createJGDI();
 
151
//      try {
 
152
//
 
153
//         Project p = new Project();
 
154
//         p.setName("testName");
 
155
//         gdi.addProject(p);
 
156
//
 
157
//         try {
 
158
//            ClusterQueue cq = gdi.getClusterQueue("all.q");
 
159
//
 
160
//
 
161
//            cq.addProjects("@allhosts", p );
 
162
//
 
163
//            List projectList = cq.getProjectsList("@allhosts");
 
164
//
 
165
//            boolean found = false;
 
166
//
 
167
//            for(int ii = 0; ii < projectList.size(); ii++) {
 
168
//
 
169
//               Project tmpPrj = (Project)projectList.get(ii);
 
170
//               logger.fine("project " + tmpPrj.getName());
 
171
//               if(tmpPrj.getName().equals(p.getName())) {
 
172
//                  found = true;
 
173
//                  break;
 
174
//               }
 
175
//            }
 
176
//
 
177
//            assertTrue("project " + p.getName() + " not found in cluster queue" + cq.getName(), found);
 
178
//
 
179
//         } finally {
 
180
//            gdi.deleteProject(p);
 
181
//         }
 
182
//      } finally {
 
183
//         gdi.close();
 
184
//      }
 
185
//
 
186
//   }
 
187
//
 
188
    
 
189
    
 
190
}