1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2001 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
/*
* SessionImplTest.java
* JUnit based test
*
* Created on November 15, 2004, 10:41 AM
*/
package com.sun.grid.drmaa;
import junit.framework.*;
import org.ggf.drmaa.*;
import com.sun.grid.Settings;
/**
* Test class for SessionImpl class.
*/
public class SessionImplTest extends TestCase {
private Session session = null;
public SessionImplTest(java.lang.String testName) {
super(testName);
}
public static Test suite() {
TestSuite suite = new TestSuite(SessionImplTest.class);
return suite;
}
public void setUp() {
session = SessionFactory.getFactory().getSession();
}
public void tearDown() {
session = null;
}
/** Test of init & exit methods, of class com.sun.grid.drmaa.SessionImpl. */
public void testInitExit() {
System.out.println("testInitExit");
this.initSession();
this.exitSession();
}
private void initSession() {
try {
session.init(null);
} catch (DrmaaException e) {
fail("Unable to initialize session: " + e.getMessage());
}
}
private void exitSession() {
try {
session.exit();
} catch (DrmaaException e) {
fail("Unable to exit session: " + e.getMessage());
}
}
/** Test of getContact method, of class com.sun.grid.drmaa.SessionImpl. */
public void testGetContact() {
System.out.println("testGetContact");
assertEquals("", session.getContact());
this.initSession();
try {
assertNotNull(session.getContact());
assertTrue(session.getContact().startsWith("session="));
} finally {
this.exitSession();
}
}
/** Test of getDRMSystem method, of class com.sun.grid.drmaa.SessionImpl. */
public void testGetDrmSystem() {
System.out.println("testGetDrmSystem");
/* structure: "version name (builddate)" */
String version = getVersionWithoutBuildNumber(Settings.get(Settings.VERSION));
String drmVersion = getVersionWithoutBuildNumber(session.getDrmSystem());
/**
* In some rare cases the version strings can differ
* if some binaries are recompiled and others not.
*/
assertEquals("DRM version does not match Gridengine version",
version, drmVersion);
this.initSession();
try {
drmVersion = getVersionWithoutBuildNumber(session.getDrmSystem());
assertEquals("Session version does not match Gridengine version",
version, drmVersion);
} finally {
this.exitSession();
}
}
/** Removes the appended build number if necessary */
private String getVersionWithoutBuildNumber(final String version) {
int index = version.lastIndexOf("(");
if (index > 0) {
return version.substring(0, index - 1);
} else {
return version;
}
}
/** Test of getDRMAAImplementation method, of class
* com.sun.grid.drmaa.SessionImpl. */
public void testGetDrmaaImplementation() {
System.out.println("testGetDrmaaImplementation");
/**
* In some rare cases the version strings can differ
* if some binaries are recompiled and others not.
*/
String version = getVersionWithoutBuildNumber(
Settings.get(Settings.VERSION));
String drmaa_version = getVersionWithoutBuildNumber(
session.getDrmaaImplementation());
assertEquals(version, drmaa_version);
this.initSession();
drmaa_version = getVersionWithoutBuildNumber(
session.getDrmaaImplementation());
try {
assertEquals(version, drmaa_version);
} finally {
this.exitSession();
}
}
/** Test of getVersion method, of class com.sun.grid.drmaa.SessionImpl. */
public void testGetVersion() {
System.out.println("testGetVersion");
Version v_0_5 = new Version(0, 5);
Version v_1_0 = new Version(1, 0);
this.initSession();
try {
// get running drmaaj-wrapper version: 0.5 or 1.0
Version current_version = session.getVersion();
assertTrue(current_version.equals(v_0_5)
|| current_version.equals(v_1_0));
} finally {
this.exitSession();
}
}
/** Test of create|deleteJobTemplate method, of class
* com.sun.grid.drmaa.SessionImpl. */
public void testJobTemplate() {
System.out.println("testJobTemplate");
JobTemplate jt = null;
this.initSession();
try {
try {
jt = session.createJobTemplate();
} catch (DrmaaException e) {
fail("Unable to create job template: " + e.getMessage());
}
assertNotNull(jt);
assertTrue(jt instanceof JobTemplateImpl);
try {
session.deleteJobTemplate(jt);
} catch (InvalidJobTemplateException e) {
fail("Unable to delete job template: " + e.getMessage());
} catch (DrmaaException e) {
fail("Unable to create job template: " + e.getMessage());
}
try {
session.deleteJobTemplate(jt);
fail("Able to delete job template twice");
} catch (InvalidJobTemplateException e) {
/* Don't care */
} catch (DrmaaException e) {
fail("Unable to delete job template: " + e.getMessage());
}
} finally {
this.exitSession();
}
}
}
|