Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test suite infrastructure is taking shape, see service/service/java/t…

…ests/suites/common/README.txt
  • Loading branch information...
commit 8ee8980a7eb1e641915914c1438e0839c4107b45 1 parent 4a24811
@timf timf authored
Showing with 1,527 additions and 64 deletions.
  1. +2 −0  .gitignore
  2. +2 −3 .idea-modules/service-suites/tests-common.iml
  3. +2 −0  .idea/libraries/workspace_service_libs.xml
  4. BIN  lib/services/commons-collections-3.2.1.jar
  5. BIN  lib/services/commons-io-1.4.jar
  6. +8 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/acctdb-delete.sh
  7. +8 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/acctdb-reset.sh
  8. +8 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/full-delete.sh
  9. +8 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/full-reset.sh
  10. +336 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/db-mgmt.xml
  11. +87 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/notifications
  12. +89 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/pilotnotifications
  13. +3 −0  .../service/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_accounting_dump.sql
  14. +30 −0 ...ervice/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_accounting_schema.sql
  15. +23 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_dump.sql
  16. +216 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_schema.sql
  17. +8 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/servicedb-delete.sh
  18. +8 −0 service/service/java/tests/suites/basic/home/services/share/nimbus/servicedb-reset.sh
  19. +64 −12 service/service/java/tests/suites/basic/src/org/globus/workspace/testing/suites/basic/BasicSuite.java
  20. +121 −0 service/service/java/tests/suites/common/README.txt
  21. +33 −0 service/service/java/tests/suites/common/src/org/globus/workspace/testing/FakeLog.java
  22. +362 −5 service/service/java/tests/suites/common/src/org/globus/workspace/testing/NimbusTestBase.java
  23. +0 −44 service/service/java/tests/suites/common/src/org/globus/workspace/testing/utils/DefaultRequestFactory.java
  24. +102 −0 service/service/java/tests/suites/common/src/org/globus/workspace/testing/utils/ReprPopulator.java
  25. +7 −0 service/service/java/tests/suites/common/suites.log4j.properties
View
2  .gitignore
@@ -18,3 +18,5 @@ web/var/
control/var/workspace-control/logs/wclog*
derby.log
bin/tmp/
+workspace.persistence.conf
+
View
5 .idea-modules/service-suites/tests-common.iml
@@ -9,9 +9,8 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="rm-api" exported="" />
<orderEntry type="module" module-name="workspace-service" exported="" />
- <orderEntry type="library" name="test-libs" level="project" />
- <orderEntry type="library" name="workspace-service-libs" level="project" />
- <orderEntry type="library" name="rm-api-libs" level="project" />
+ <orderEntry type="library" exported="" name="test-libs" level="project" />
+ <orderEntry type="library" exported="" name="workspace-service-libs" level="project" />
</component>
</module>
View
2  .idea/libraries/workspace_service_libs.xml
@@ -14,6 +14,8 @@
<root url="jar://$PROJECT_DIR$/lib/services/ehcache-1.5.0.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/services/jetty-util-6.1.21.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/services/jug-2.0.0.jar!/" />
+ <root url="jar://$PROJECT_DIR$/lib/services/commons-collections-3.2.1.jar!/" />
+ <root url="jar://$PROJECT_DIR$/lib/services/commons-io-1.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
View
BIN  lib/services/commons-collections-3.2.1.jar
Binary file not shown
View
BIN  lib/services/commons-io-1.4.jar
Binary file not shown
View
8 service/service/java/tests/suites/basic/home/services/share/nimbus/acctdb-delete.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+BASEDIR_REL="`dirname $0`"
+BASEDIR=`cd $BASEDIR_REL; pwd`
+
+BUILDFILE=$BASEDIR/lib/db-mgmt.xml
+
+ant -q -f $BUILDFILE deleteAccountingDB $*
View
8 service/service/java/tests/suites/basic/home/services/share/nimbus/acctdb-reset.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+BASEDIR_REL="`dirname $0`"
+BASEDIR=`cd $BASEDIR_REL; pwd`
+
+BUILDFILE=$BASEDIR/lib/db-mgmt.xml
+
+ant -q -f $BUILDFILE resetAccountingDB $*
View
8 service/service/java/tests/suites/basic/home/services/share/nimbus/full-delete.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+BASEDIR_REL="`dirname $0`"
+BASEDIR=`cd $BASEDIR_REL; pwd`
+
+BUILDFILE=$BASEDIR/lib/db-mgmt.xml
+
+ant -q -f $BUILDFILE deleteAllPersistentData $*
View
8 service/service/java/tests/suites/basic/home/services/share/nimbus/full-reset.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+BASEDIR_REL="`dirname $0`"
+BASEDIR=`cd $BASEDIR_REL; pwd`
+
+BUILDFILE=$BASEDIR/lib/db-mgmt.xml
+
+ant -q -f $BUILDFILE deleteAllPersistentData setupWorkspacePersistence $*
View
336 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/db-mgmt.xml
@@ -0,0 +1,336 @@
+<?xml version="1.0"?>
+
+<project default="dbprobe"
+ basedir="."
+ name="Workspace Service DB build/management">
+
+ <description>Workspace Service DB build/management
+
+ Must be called with these properties set:
+
+ workspace.dbdir.prop - toplevel dir to create under
+ workspace.sqldir.prop - dir with SQL database definition files
+ workspace.notifdir.prop - dir with source of notification executables
+ derby.system.home.prop - derby home dir to call IJ with
+ derby.relative.dir.prop - relative path from homedir where our dir is
+ derby.classpath.dir.prop - path to dir with derby jars
+ pwGen.path.prop - path to password generation comd
+ </description>
+
+ <property file="../workspace.persistence.conf" />
+
+ <path id="derby.classpath">
+ <fileset dir="${derby.classpath.dir.prop}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+
+ <!-- ***********************************************************************
+ DEFAULT SETUP TARGET
+ ******************************************************************* -->
+
+ <target name="setupWorkspacePersistence">
+
+ <echo>Setting up Workspace Service persistence:</echo>
+ <antcall target="createDerbyDB" />
+ <antcall target="createAccountingDB" />
+ <echo>Set up Workspace Service persistence.</echo>
+
+ </target>
+
+
+ <!-- ***********************************************************************
+ WIPE ALL STATE
+ ******************************************************************* -->
+
+ <target name="deleteAllPersistentData">
+ <fail message="Must specify 'workspace.dbdir.prop' to delete"
+ unless="workspace.dbdir.prop"/>
+ <echo message="Deleting everything persisted under ${workspace.dbdir.prop}"/>
+ <delete dir="${workspace.dbdir.prop}" />
+ </target>
+
+
+ <!-- ***********************************************************************
+ PERSISTENCE DATABASE FOR CONFIGURATION AND RUNNING WORKSPACES
+ ******************************************************************* -->
+
+ <target name="createDerbyDB"
+ depends="allparamscheck, Main DB action"
+ unless="mainDB.present">
+
+ <antcall target="make.persistence.dir" />
+
+ <java classname="org.apache.derby.tools.ij" fork="true">
+ <jvmarg value="-Dderby.system.home=${derby.system.home.prop}"/>
+ <jvmarg value="-Dderby.infolog.append=true"/>
+ <jvmarg value="-Dij.protocol=jdbc:derby:directory:${derby.system.home.prop}/"/>
+ <jvmarg value="-Dij.database=${derby.relative.dir.prop}/WorkspacePersistenceDB;create=true;user=nimbus;password=${derby.user.pass}"/>
+ <classpath refid="derby.classpath" />
+ <arg value="${workspace.sqldir.prop}/workspace_service_derby_schema.sql"/>
+ </java>
+ </target>
+
+ <target name="Main DB action" depends="dbprobe">
+ <echo message="${mainDB.msg}"/>
+ </target>
+
+ <!-- resetDB is a convenience target in place so that
+ the entire service does need to be redeployed to
+ wipe the database.
+ -->
+ <target name="resetDB">
+ <antcall target="deleteDerbyDB"/>
+ <antcall target="createDerbyDB"/>
+ </target>
+
+ <target name="deleteDB" depends="deleteDerbyDB" />
+ <target name="dumpDB" depends="dumpDerbyDB" />
+
+ <target name="deleteDerbyDB">
+ <fail message="Must specify 'workspace.dbdir.prop' to delete"
+ unless="workspace.dbdir.prop"/>
+ <echo message="Deleting Derby database for the Workspace Service"/>
+ <delete dir="${workspace.dbdir.prop}/WorkspacePersistenceDB"/>
+
+ <!-- consistency of these things are tied to the service DB so they
+ also need a reset -->
+ <echo message="Deleting disk-caches for the Workspace Service"/>
+ <delete dir="${workspace.dbdir.prop}/caches" />
+ <echo message="Deleting notification msgs for the Workspace Service"/>
+ <delete dir="${workspace.dbdir.prop}/msg-sinks" />
+ </target>
+
+ <target name="dumpDerbyDB" depends="allparamscheck" >
+ <echo message="Dumping Derby database to stdout"/>
+ <java classname="org.apache.derby.tools.ij" fork="true" >
+ <jvmarg value="-Dderby.system.home=${derby.system.home.prop}"/>
+ <jvmarg value="-Dderby.infolog.append=true"/>
+ <jvmarg value="-Dij.protocol=jdbc:derby:directory:${derby.system.home.prop}/"/>
+ <jvmarg value="-Dij.database=${derby.relative.dir.prop}/WorkspacePersistenceDB;create=false;user=nimbus;password=${derby.user.pass}"/>
+ <classpath refid="derby.classpath" />
+ <arg value="${workspace.sqldir.prop}/workspace_service_derby_dump.sql"/>
+ </java>
+ </target>
+
+
+ <!-- ***********************************************************************
+ ACCOUNTING DATABASE
+ ******************************************************************* -->
+
+ <!-- separate database for long term accounting, even over workspace
+ service version changes or configuration resets -->
+
+ <target name="createAccountingDB"
+ depends="allparamscheck, Accounting DB action"
+ unless="accountingDB.present">
+
+ <antcall target="make.persistence.dir" />
+
+ <java classname="org.apache.derby.tools.ij" fork="true" >
+ <jvmarg value="-Dderby.system.home.prop=${derby.system.home.prop}"/>
+ <jvmarg value="-Dderby.infolog.append=true"/>
+ <jvmarg value="-Dij.protocol=jdbc:derby:directory:${derby.system.home.prop}/"/>
+ <jvmarg value="-Dij.database=${derby.relative.dir.prop}/WorkspaceAccountingDB;create=true;user=nimbus;password=${derby.user.pass}"/>
+ <classpath refid="derby.classpath" />
+ <arg value="${workspace.sqldir.prop}/workspace_service_derby_accounting_schema.sql"/>
+ </java>
+ </target>
+
+ <target name="Accounting DB action" depends="dbprobe">
+ <echo message="${accountingDB.msg}"/>
+ </target>
+
+ <!-- resetAccountingDB is a convenience target in place so that
+ the entire service does need to be redeployed to
+ wipe the database. -->
+
+ <target name="resetAccountingDB">
+ <antcall target="deleteAccountingDB"/>
+ <antcall target="createAccountingDB"/>
+ </target>
+
+ <target name="deleteAccountingDB">
+ <fail message="Must specify 'workspace.dbdir.prop' to delete"
+ unless="workspace.dbdir.prop"/>
+ <echo message="Deleting database for workspace accounting module"/>
+ <delete dir="${workspace.dbdir.prop}/WorkspaceAccountingDB"/>
+ </target>
+
+ <target name="dumpAccountingDB" depends="allparamscheck" >
+ <echo message="Dumping accounting database to stdout"/>
+ <java classname="org.apache.derby.tools.ij" fork="true" >
+ <jvmarg value="-Dderby.system.home.prop=${derby.system.home.prop}"/>
+ <jvmarg value="-Dderby.infolog.append=true"/>
+ <jvmarg value="-Dij.protocol=jdbc:derby:directory:${derby.system.home.prop}/"/>
+ <jvmarg value="-Dij.database=${derby.relative.dir.prop}/WorkspaceAccountingDB;create=false;user=nimbus;password=${derby.user.pass}"/>
+ <classpath refid="derby.classpath" />
+ <arg value="${workspace.sqldir.prop}/workspace_service_derby_accounting_dump.sql"/>
+ </java>
+ </target>
+
+
+ <!-- ***********************************************************************
+ "SUBROUTINES"
+ ******************************************************************* -->
+
+ <target name="assureDerbyProps"
+ depends="checkDerbyProps, createDerbyProps, readDerbyProps" />
+ <target name="checkDerbyProps">
+ <available file="${derby.system.home.prop}/derby.properties"
+ property="derbyProps.exist"/>
+ <antcall target="createDerbyProps"/>
+ <antcall target="readDerbyProps"/>
+ </target>
+
+ <target name="readDerbyProps" if="derbyProps.exist">
+ <loadproperties srcfile="${derby.system.home.prop}/derby.properties">
+ <filterchain>
+ <linecontains>
+ <contains value="derby.user.nimbus"/>
+ </linecontains>
+ </filterchain>
+ </loadproperties>
+ <property name="derby.user.pass" value="${derby.user.nimbus}" />
+ </target>
+
+ <target name="createDerbyProps" unless="derbyProps.exist">
+
+ <fail message="must specify 'pwGen.path.prop' (path to password generation command)"
+ unless="pwGen.path.prop"/>
+
+ <antcall target="make.persistence.dir" />
+
+ <exec executable="${pwGen.path.prop}" outputproperty="derby.user.pass"/>
+ <exec executable="${pwGen.path.prop}" outputproperty="derby.guest.pass"/>
+
+ <propertyfile file="${derby.system.home.prop}/derby.properties"
+ comment="Generated by db-mgmt.xml script">
+ <entry key="derby.user.nimbus" value="${derby.user.pass}"/>
+ <entry key="derby.user.guest" value="${derby.guest.pass}"/>
+
+ <entry key="derby.authentication.provider" value="BUILTIN"/>
+ <entry key="derby.connection.requireAuthentication" value="true"/>
+ <entry key="derby.database.propertiesOnly" value="true"/>
+ <entry key="derby.database.defaultConnectionMode" value="noAccess"/>
+ <entry key="derby.database.fullAccessUsers" value="nimbus"/>
+ <entry key="derby.database.readOnlyAccessUsers" value="guest"/>
+
+ <entry key="derby.drda.startNetworkServer" value="false"/>
+ <entry key="derby.drda.keepAlive" value="true"/>
+ <entry key="derby.drda.securityMechanism"
+ value="STRONG_PASSWORD_SUBSTITUTE_SECURITY"/>
+
+ </propertyfile>
+
+ <chmod file="${derby.system.home.prop}/derby.properties" perm="600" />
+
+ </target>
+
+
+ <target name="allparamscheck" depends="assureDerbyProps">
+
+ <fail message="Must specify 'workspace.dbdir.prop' for this"
+ unless="workspace.dbdir.prop"/>
+
+ <fail message="Must specify 'workspace.sqldir.prop' for this"
+ unless="workspace.sqldir.prop"/>
+
+ <fail message="Must specify 'workspace.notifdir.prop' for this"
+ unless="workspace.notifdir.prop"/>
+
+ <fail message="Must specify 'derby.system.home.prop' for this"
+ unless="derby.system.home.prop"/>
+
+ <fail message="Must specify 'derby.relative.dir.prop' for this"
+ unless="derby.relative.dir.prop"/>
+
+ <fail message="Must specify 'derby.classpath.dir.prop' for this"
+ unless="derby.classpath.dir.prop"/>
+
+ <fail message="Must specify 'derby.user.pass' for this"
+ unless="derby.user.pass"/>
+
+ </target>
+
+ <target name="make.persistence.dir">
+
+ <fail message="Must specify 'workspace.notifdir.prop' to make persistence directory"
+ unless="workspace.dbdir.prop"/>
+
+ <fail message="Must specify 'workspace.notifdir.prop' to make persistence directory"
+ unless="workspace.notifdir.prop"/>
+
+ <mkdir dir="${workspace.dbdir.prop}" />
+
+ <mkdir dir="${workspace.dbdir.prop}/pilot-logs" />
+
+ <mkdir dir="${workspace.dbdir.prop}/caches" />
+
+ <mkdir dir="${workspace.dbdir.prop}/tmpfiles" />
+
+ <mkdir dir="${workspace.dbdir.prop}/msg-sinks" />
+
+ <!-- chmod ant target does not work on directories... -->
+ <exec executable="chmod">
+ <arg value="700"/>
+ <arg value="${workspace.dbdir.prop}"/>
+ </exec>
+
+ <echo message="Ensured owner-only rwx permissions on persistence directory"/>
+
+ <copy file="${workspace.notifdir.prop}/notifications"
+ tofile="${workspace.dbdir.prop}/msg-sinks/notifications"/>
+
+ <chmod file="${workspace.dbdir.prop}/msg-sinks/notifications"
+ perm="500"/>
+
+ <copy file="${workspace.notifdir.prop}/pilotnotifications"
+ tofile="${workspace.dbdir.prop}/msg-sinks/pilotnotifications"/>
+
+ <chmod file="${workspace.dbdir.prop}/msg-sinks/pilotnotifications"
+ perm="500"/>
+
+ </target>
+
+ <target name="dbprobe">
+
+ <fail message="Must specify 'workspace.dbdir.prop' to probe for databases"
+ unless="workspace.dbdir.prop"/>
+
+ <available file="${workspace.dbdir.prop}/WorkspacePersistenceDB"
+ type="dir"
+ property="mainDB.present" />
+
+ <available file="${workspace.dbdir.prop}/WorkspaceAccountingDB"
+ type="dir"
+ property="accountingDB.present" />
+
+ <condition property="mainDB.msg"
+ value="Creating an embedded database for the Workspace Service">
+ <not>
+ <isset property="mainDB.present" />
+ </not>
+ </condition>
+
+ <condition property="mainDB.msg"
+ value="DB already present: not creating an embedded database for the workspace service">
+ <isset property="mainDB.present" />
+ </condition>
+
+ <condition property="accountingDB.msg"
+ value="Creating an embedded database for workspace service accounting">
+ <not>
+ <isset property="accountingDB.present" />
+ </not>
+ </condition>
+
+ <condition property="accountingDB.msg"
+ value="DB already present: not creating an embedded database for workspace accounting module">
+ <isset property="accountingDB.present" />
+ </condition>
+ </target>
+
+
+</project>
View
87 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/notifications
@@ -0,0 +1,87 @@
+#!/bin/bash
+
+# NOTE: Will go away when reliable messaging is introduced.
+
+# This is currently set up to accomodate the scheme where the account used
+# to call this script and write information to NOTIFICATION_FILE (the account
+# configured in jndi-config.xml) is the same account reading and deleting
+# entries from NOTIFICATION_FILE (the service container)
+
+# To accomodate a different scheme, you could use a UNIX group common to the
+# service container and the account used for notifications. You would need
+# to set this script to chmod 550 instead of 500 and also alter the umask line
+# below from 177 to 117, this controls the permissions on NOTIFICATION_FILE
+
+NOTIFICATION_FILE="$0.txt"
+TEMPFILE="$0.$$"
+LOCKFILE="$0.lock"
+
+set +e
+
+function my_lockfile ()
+{
+ echo $$ > $TEMPFILE || {
+ echo "You don't have permission to access `dirname $TEMPFILE`"
+ return 1
+ }
+
+ ln $TEMPFILE $LOCKFILE && {
+ rm -f $TEMPFILE
+ return 0
+ }
+
+ rm -f $TEMPFILE
+ return 1
+}
+
+function stale_check ()
+{
+ PID=""
+ PID=`cat $LOCKFILE`
+ if [ "X$PID" != "X" ]; then
+ echo "checking if LOCKFILE pid $PID is stale"
+ kill -0 $PID
+ if [ $? != 0 ]; then
+ echo "pid $PID does not exist, removing lockfile"
+ rm -f $LOCKFILE
+ fi
+ fi
+}
+
+# wait for a lock
+num=5
+until my_lockfile ; do
+ sleep 0.1
+
+ num=`expr $num - 1`
+ if [ $num = 0 ]; then
+ stale_check
+ num=5
+ fi
+done
+
+if test ! -e $NOTIFICATION_FILE ;
+then
+ umask 177
+ touch $NOTIFICATION_FILE
+fi
+
+line=''
+if [ "$1" == "readanddelete" ]
+then
+ cat $NOTIFICATION_FILE
+ rm $NOTIFICATION_FILE
+elif [ "$1" == "write" ];
+then
+ shift
+ for str in $* ;
+ do
+ line="$line$str::"
+ done
+ line="$line<eon>"
+
+ echo $line >> $NOTIFICATION_FILE
+fi
+
+rm -f $LOCKFILE
+
View
89 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/pilotnotifications
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+# NOTE: using the default HTTP based notification scheme is better, this is
+# only here to accomodate backup messages when the service is down.
+# Will go away when reliable messaging is introduced.
+
+# This is currently set up to accomodate the scheme where the account used
+# to call this script and write information to NOTIFICATION_FILE (the account
+# configured in jndi-config.xml) is the same account reading and deleting
+# entries from NOTIFICATION_FILE (the service container)
+
+# To accomodate a different scheme, you could use a UNIX group common to the
+# service container and the account used for notifications. You would need
+# to set this script to chmod 550 instead of 500 and also alter the umask line
+# below from 177 to 117, this controls the permissions on NOTIFICATION_FILE
+
+NOTIFICATION_FILE="$0.txt"
+TEMPFILE="$0.$$"
+LOCKFILE="$0.lock"
+
+set +e
+
+function my_lockfile ()
+{
+ echo $$ > $TEMPFILE || {
+ echo "You don't have permission to access `dirname $TEMPFILE`"
+ return 1
+ }
+
+ ln $TEMPFILE $LOCKFILE && {
+ rm -f $TEMPFILE
+ return 0
+ }
+
+ rm -f $TEMPFILE
+ return 1
+}
+
+function stale_check ()
+{
+ PID=""
+ PID=`cat $LOCKFILE`
+ if [ "X$PID" != "X" ]; then
+ echo "checking if LOCKFILE pid $PID is stale"
+ kill -0 $PID
+ if [ $? != 0 ]; then
+ echo "pid $PID does not exist, removing lockfile"
+ rm -f $LOCKFILE
+ fi
+ fi
+}
+
+# wait for a lock
+num=5
+until my_lockfile ; do
+ sleep 0.1
+
+ num=`expr $num - 1`
+ if [ $num = 0 ]; then
+ stale_check
+ num=5
+ fi
+done
+
+if test ! -e $NOTIFICATION_FILE ;
+then
+ umask 177
+ touch $NOTIFICATION_FILE
+fi
+
+line=''
+if [ "$1" == "readanddelete" ]
+then
+ cat $NOTIFICATION_FILE
+ rm $NOTIFICATION_FILE
+elif [ "$1" == "write" ];
+then
+ shift
+ for str in $* ;
+ do
+ line="$line$str::"
+ done
+ line="$line<eon>"
+
+ echo $line >> $NOTIFICATION_FILE
+fi
+
+rm -f $LOCKFILE
+
View
3  ...rvice/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_accounting_dump.sql
@@ -0,0 +1,3 @@
+select * from deployments;
+disconnect;
+exit;
View
30 ...ice/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_accounting_schema.sql
@@ -0,0 +1,30 @@
+-- Copyright 1999-2007 University of Chicago
+--
+-- Licensed under the Apache License, Version 2.0 (the "License"); you may not
+-- use this file except in compliance with the License. You may obtain a copy
+-- of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+-- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+-- License for the specific language governing permissions and limitations
+-- under the License.
+
+-- connect 'jdbc:derby:workspace_service/WorkspaceAccountingDB;create=true';
+
+-- workspaceid does not need to be unique (allows this data to persist beyond
+-- one service deployment, service version, or configuration)
+
+CREATE TABLE deployments
+(
+uuid CHAR(36) NOT NULL PRIMARY KEY,
+workspaceid INT NOT NULL,
+creator_dn VARCHAR(512) NOT NULL,
+creation_time FLOAT NOT NULL,
+requested_duration INT NOT NULL,
+active SMALLINT NOT NULL,
+elapsed_minutes FLOAT
+);
+
View
23 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_dump.sql
@@ -0,0 +1,23 @@
+-- uncomment what is of interest
+
+-- select * from resources;
+-- select * from staging;
+-- select * from vms;
+-- select * from groupresources;
+-- select * from vm_partitions;
+-- select * from vm_deployment;
+-- select * from associations;
+-- select * from association_entries;
+-- select * from resourcepools;
+-- select * from resourcepool_entries;
+-- select * from default_scheduler_current_tasks;
+-- select * from default_scheduler_workspid;
+-- select * from pilot_slots;
+-- select * from pilot_groups;
+-- select * from pilot_notification_position;
+-- select * from counter;
+-- select * from notification_position;
+
+
+disconnect;
+exit;
View
216 service/service/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_schema.sql
@@ -0,0 +1,216 @@
+-- Copyright 1999-2008 University of Chicago
+--
+-- Licensed under the Apache License, Version 2.0 (the "License"); you may not
+-- use this file except in compliance with the License. You may obtain a copy
+-- of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+-- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+-- License for the specific language governing permissions and limitations
+-- under the License.
+
+-- connect 'jdbc:derby:workspace_service/WorkspacePersistenceDB;create=true';
+
+--
+-- Persistence for WorkspaceResource:
+
+CREATE TABLE resources
+(
+id INT NOT NULL PRIMARY KEY,
+name VARCHAR(100) NOT NULL,
+state SMALLINT NOT NULL,
+target_state SMALLINT NOT NULL,
+term_time BIGINT NOT NULL,
+ops_enabled SMALLINT NOT NULL,
+creator_dn VARCHAR(512),
+start_time BIGINT NOT NULL,
+vmm_access_ok SMALLINT NOT NULL,
+ensembleid CHAR(36),
+groupid CHAR(36),
+groupsize INT,
+last_in_group SMALLINT,
+launch_index INT,
+error_fault BLOB
+);
+
+--
+-- Persistence for GroupResource/CoschedResource:
+
+CREATE TABLE groupresources
+(
+groupid CHAR(36) NOT NULL PRIMARY KEY,
+creator_dn VARCHAR(512)
+);
+
+
+--
+-- Persistence for virtual machines:
+
+CREATE TABLE vms
+(
+id INT NOT NULL PRIMARY KEY,
+name VARCHAR(128) NOT NULL,
+node VARCHAR(128),
+prop_required SMALLINT NOT NULL,
+unprop_required SMALLINT NOT NULL,
+network VARCHAR(1024),
+kernel_parameters VARCHAR(128),
+vmm VARCHAR(32),
+vmm_version VARCHAR(32),
+assocs_needed VARCHAR(256),
+md_user_data VARCHAR(30720)
+);
+
+--
+-- VM partitions
+
+CREATE TABLE vm_partitions
+(
+vmid INT NOT NULL,
+image VARCHAR(128) NOT NULL,
+imagemount VARCHAR(128) NOT NULL,
+readwrite SMALLINT NOT NULL,
+rootdisk SMALLINT NOT NULL,
+blankspace INT NOT NULL,
+prop_required SMALLINT NOT NULL,
+unprop_required SMALLINT NOT NULL,
+alternate_unprop VARCHAR(128)
+);
+
+--
+-- Persistence for vm deployment-time data:
+
+CREATE TABLE vm_deployment
+(
+vmid INT NOT NULL,
+requested_state SMALLINT,
+requested_shutdown SMALLINT,
+min_duration INT,
+ind_physmem INT
+);
+
+--
+-- Persistence for association tracking:
+
+CREATE TABLE associations
+(
+association VARCHAR(128) NOT NULL PRIMARY KEY,
+dns VARCHAR(32),
+file_time BIGINT NOT NULL
+);
+
+CREATE TABLE association_entries
+(
+association VARCHAR(128) NOT NULL,
+ipaddress VARCHAR(32) NOT NULL,
+mac VARCHAR(32),
+hostname VARCHAR(128),
+gateway VARCHAR(32),
+broadcast VARCHAR(32),
+subnetmask VARCHAR(32),
+used SMALLINT,
+PRIMARY KEY(association,ipaddress)
+);
+
+--
+-- Persistence for file customization tasks
+
+CREATE TABLE vm_customization
+(
+vmid INT NOT NULL,
+sourcepath VARCHAR(32) NOT NULL,
+destpath VARCHAR(512) NOT NULL,
+sent SMALLINT NOT NULL
+);
+
+--
+-- For DefaultSchedulerAdapter
+
+CREATE TABLE default_scheduler_current_tasks
+(
+id INT NOT NULL,
+shutdown_time BIGINT NOT NULL,
+shutdown SMALLINT NOT NULL
+);
+
+CREATE TABLE default_scheduler_workspid
+(
+id INT NOT NULL PRIMARY KEY DEFAULT 0
+);
+
+CREATE TABLE default_scheduler_pending_ensemb
+(
+coschedid CHAR(36) NOT NULL,
+groupid CHAR(36),
+id INT,
+min_duration INT NOT NULL,
+ind_physmem INT NOT NULL,
+assocs_needed VARCHAR(256)
+);
+
+CREATE TABLE default_scheduler_done_ensemb
+(
+coschedid CHAR(36) NOT NULL
+);
+
+--
+-- Persistence for default resource pool:
+
+CREATE TABLE resourcepools
+(
+resourcepool VARCHAR(128) NOT NULL PRIMARY KEY,
+file_time BIGINT NOT NULL
+);
+
+CREATE TABLE resourcepool_entries
+(
+resourcepool VARCHAR(128) NOT NULL,
+hostname VARCHAR(128) NOT NULL,
+associations VARCHAR(512) NOT NULL,
+maximum_memory INT,
+available_memory INT
+);
+
+--
+-- Pilot:
+
+CREATE TABLE pilot_slots
+(
+id CHAR(36) NOT NULL,
+vmid INT NOT NULL,
+pending SMALLINT NOT NULL,
+terminal SMALLINT NOT NULL,
+lrmhandle VARCHAR(128) NOT NULL,
+duration BIGINT NOT NULL,
+partofgroup SMALLINT NOT NULL,
+pendingremove SMALLINT NOT NULL,
+nodename VARCHAR(128)
+);
+
+CREATE TABLE pilot_groups
+(
+groupid CHAR(36) NOT NULL,
+vmid INT NOT NULL
+);
+
+CREATE TABLE pilot_notification_position
+(
+position BIGINT
+);
+
+--
+-- Other:
+
+CREATE TABLE counter
+(
+id SMALLINT,
+pending INT
+);
+
+CREATE TABLE notification_position
+(
+position BIGINT
+);
View
8 service/service/java/tests/suites/basic/home/services/share/nimbus/servicedb-delete.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+BASEDIR_REL="`dirname $0`"
+BASEDIR=`cd $BASEDIR_REL; pwd`
+
+BUILDFILE=$BASEDIR/lib/db-mgmt.xml
+
+ant -q -f $BUILDFILE deleteDB $*
View
8 service/service/java/tests/suites/basic/home/services/share/nimbus/servicedb-reset.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+BASEDIR_REL="`dirname $0`"
+BASEDIR=`cd $BASEDIR_REL; pwd`
+
+BUILDFILE=$BASEDIR/lib/db-mgmt.xml
+
+ant -q -f $BUILDFILE resetDB $*
View
76 service/service/java/tests/suites/basic/src/org/globus/workspace/testing/suites/basic/BasicSuite.java
@@ -16,30 +16,82 @@
package org.globus.workspace.testing.suites.basic;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.globus.workspace.testing.NimbusTestBase;
+import org.nimbustools.api.repr.CreateResult;
+import org.nimbustools.api.repr.vm.VM;
+import org.nimbustools.api.services.rm.Manager;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.io.File;
public class BasicSuite extends NimbusTestBase {
// -----------------------------------------------------------------------------------------
- // STATIC VARIABLES
+ // extends NimbusTestBase
// -----------------------------------------------------------------------------------------
- private static final Log logger =
- LogFactory.getLog(BasicSuite.class.getName());
+ @BeforeSuite
+ @Override
+ public void suiteSetup() throws Exception {
+ super.suiteSetup();
+ }
+ @AfterSuite
+ @Override
+ public void suiteTeardown() throws Exception {
+ super.suiteTeardown();
+ }
- // -----------------------------------------------------------------------------------------
- // INSTANCE VARIABLES
- // -----------------------------------------------------------------------------------------
+ /**
+ * This is how coordinate your Java test suite code with the conf files to use.
+ * @return absolute path to the value that should be set for $NIMBUS_HOME
+ * @throws Exception if $NIMBUS_HOME cannot be determined
+ */
+ @Override
+ protected String getNimbusHome() throws Exception {
+ return this.determineSuitesPath() + File.separator + "basic/home";
+ }
- // -----------------------------------------------------------------------------------------
- // CONSTRUCTORS
- // -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
- // GET/SET
+ // PREREQ TESTS (if any of these fail, nothing else will work at all)
// -----------------------------------------------------------------------------------------
+ /**
+ * Check if ModuleLocator can be retrieved and used at all.
+ * @throws Exception problem
+ */
+ @Test(groups="prereqs")
+ public void retrieveModuleLocator() throws Exception {
+ logger.debug("retrieveModuleLocator");
+ final Manager rm = this.locator.getManager();
+ final VM[] vms = rm.getGlobalAll();
+
+ // we know there are zero so far because it is in group 'prereqs'
+ assertEquals(0, vms.length);
+ }
+
+ /**
+ * Lease a VM and then destroy it.
+ * @throws Exception problem
+ */
+ @Test(dependsOnGroups="prereqs")
+ public void leaseOne() throws Exception {
+ logger.debug("leaseOne");
+ final Manager rm = this.locator.getManager();
+
+ final CreateResult result =
+ rm.create(this.populator().getCreateRequest("suite:basic:leaseOne"),
+ this.populator().getCaller());
+
+ final VM[] vms = result.getVMs();
+ assertEquals(1, vms.length);
+ for (VM vm : vms) {
+ logger.info("Leased vm '" + vm.getID() + '\'');
+ }
+ }
}
View
121 service/service/java/tests/suites/common/README.txt
@@ -0,0 +1,121 @@
+====================================
+RM API and Workspace Service Testing
+====================================
+
+
+This testing infrastructure allows tests from the RM-API level down. An entire Spring context
+is instantiated with real components.
+
+The "service/service/java/tests/suites/" directory is broken up into separate directories,
+each one (except "common") is a test suite.
+
+A "test suite" is simply a collection of tests (currently TestNG) that run in the same Spring
+context and can all run with one setup of the system.
+
+You would want to change the Spring context around in order to:
+
+ * write tests that need alternative configuration settings (there are many configurations
+ that are only set and validated at initialization time)
+
+ * introduce an alternative class implementation for a Spring bean
+
+ * introduce mocks
+
+ * develop code to begin with (use the test system as a way to quickly see your changes)
+
+
+A Spring context is loaded by finding a mock NIMBUS_HOME.
+
+ * Each suite has its own home directory which has a copy (but modified where necessary)
+ of the Nimbus 'services/etc' and 'services/share' directories that show up in a
+ deployment.
+
+ * NOTE: The environment variable NIMBUS_HOME should *not* be set in your testing
+ environment, it is determined and set programmatically for each suite.
+
+
+Setup
+
+ * When each suite is set up, a new var directory is created under the NIMBUS_HOME and
+ the databases are created.
+
+ * Ant is required to be on your PATH in order for the setup routine to work, it is calling
+ a shell script which needs ant ("full-reset.sh").
+
+
+Teardown
+
+ * The entire var directory is removed on teardown. You can disable that behavior via JVM
+ system property if you want to analyze something etc. (see the code).
+
+
+Fake mode
+
+ * Most of the suites are probably configured to be in "fake mode" which is where the
+ workspace service "pretends" to tell the VMM to do things but actually only logs
+ what "would have" happened at various points in time.
+ (See: "services/etc/nimbus/workspace-service/other/common.conf")
+
+ * During development (or if you are dealing with 'real live' acceptance tests), you can
+ turn off your fake mode and drive real events which could be very useful for testing
+ how your changes are working with other Nimbus components.
+
+
+Running the test suites in IntelliJ IDEA
+---------------------------------------
+
+ To get started quickly, find the "BasicSuite" class in the "basic" module. Right-click
+ it and choose the "Run BasicSuite" option.
+
+ That works because the "src" directory is labelled as a "test classes" directory in the
+ module configuration. It creates a run configuration called "BasicSuite" on the fly
+ which (if you "edit configurations" in the Run/Debug configuration drop-down) is just
+ running this one class in the package.
+
+ But in general the intent is that anything in the whole suite package that has a @Test
+ annotation should be run.
+
+ * To fix, choose the "All in package" radio button instead of "Class" and make sure
+ it is the right value ("org.globus.workspace.testing.suites.basic" now instead of
+ "org.globus.workspace.testing.suites.basic.BasicSuite").
+
+ * While you are there, make sure "Use classpath and JDK of module" is set to the
+ current module (e.g. "basic").
+
+ *Any* manual configurations should not be necessary in the future, there will be testng.xml
+ files, for example, which will let scripts drive the tests (as well as making it more
+ convenient to "just do the right thing" for other IDEs).
+
+
+Creating a new suite of your own
+--------------------------------
+
+To start, just copy the structure of a current suite.
+
+ * See BasicSuite.getNimbusHome() for what to do.
+
+ * To discover how this all works and how to be flexible, look at the code (later!).
+
+
+
+Adding a new IntelliJ IDEA module
+---------------------------------
+
+ Note that the .idea/ directory has been updated with a new group of modules, the
+ "service-suites" group. Each suite should be its own module (e.g. "basic") so that it can
+ house its own Spring facet and in general to keep things organized cleanly:
+
+ * One unique Java package that only relies on the "tests-common" module (and that
+ module's own dependencies).
+
+ * One module directory per suite so that we can expand the module in the hierarchical
+ view and see the "home" and "src" directories... and then make them go away.
+
+ To create a new module for your suite, make it look like the others. The "dependencies"
+ tab should only need to rely on the other module "tests-common" which "exports" all the
+ necessary 3rd party libraries and source code that are in play.
+
+ Anything touching the .idea directory is reviewed closely before it can be merged into
+ master, so don't worry too much...
+
+
View
33 service/service/java/tests/suites/common/src/org/globus/workspace/testing/FakeLog.java
@@ -0,0 +1,33 @@
+package org.globus.workspace.testing;
+
+import org.apache.commons.logging.Log;
+
+/**
+ * The NimbusTestBase logger should be used only after suite setup, this class prevents
+ * NPEs beforehand.
+ */
+public class FakeLog implements Log {
+
+ public boolean isDebugEnabled() {return false;}
+ public boolean isErrorEnabled() {return false;}
+ public boolean isFatalEnabled() {return false;}
+ public boolean isInfoEnabled() {return false;}
+ public boolean isTraceEnabled() {return false;}
+ public boolean isWarnEnabled() {return false;}
+ public void trace(Object o) {dontuse();}
+ public void trace(Object o, Throwable throwable) {dontuse();}
+ public void debug(Object o) {dontuse();}
+ public void debug(Object o, Throwable throwable) {dontuse();}
+ public void info(Object o) {dontuse();}
+ public void info(Object o, Throwable throwable) {dontuse();}
+ public void warn(Object o) {dontuse();}
+ public void warn(Object o, Throwable throwable) {dontuse();}
+ public void error(Object o) {dontuse();}
+ public void error(Object o, Throwable throwable) {dontuse();}
+ public void fatal(Object o) {dontuse();}
+ public void fatal(Object o, Throwable throwable) {dontuse();}
+
+ private static void dontuse() {
+ System.err.println("\n* Don't use this logger.\n");
+ }
+}
View
367 service/service/java/tests/suites/common/src/org/globus/workspace/testing/NimbusTestBase.java
@@ -16,29 +16,386 @@
package org.globus.workspace.testing;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.PropertyConfigurator;
+import org.globus.workspace.WorkspaceUtil;
+import org.globus.workspace.testing.utils.ReprPopulator;
+import org.nimbustools.api.brain.BreathOfLife;
+import org.nimbustools.api.brain.ModuleLocator;
+import org.nimbustools.api.brain.NimbusFileSystemXmlApplicationContext;
-public class NimbusTestBase {
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Class to extend from to use the spring-loaded Nimbus Workspace Service environment in tests.
+ * Will be helpful to look at an example subclass to see how it's done.
+ */
+public abstract class NimbusTestBase {
// -----------------------------------------------------------------------------------------
// STATIC VARIABLES
// -----------------------------------------------------------------------------------------
- private static final Log logger =
- LogFactory.getLog(NimbusTestBase.class.getName());
+ public static final String FORCE_SUITES_DIR_PATH = "nimbus.servicetestsuites.abspath";
+ public static final String NO_TEARDOWN = "nimbus.servicetestsuites.noteardown";
+ private static final String LOG_SEP =
+ "\n-----------------------------------------------------------------------";
// -----------------------------------------------------------------------------------------
// INSTANCE VARIABLES
// -----------------------------------------------------------------------------------------
+ // How tests get a reference into the system that NimbusTestBase bootstraps, it is the
+ // same object (via interface) that the protocol layers use (it is "the RM API").
+ protected ModuleLocator locator;
+
+ // 'logger' should be used only after suite setup, this class prevents NPEs beforehand
+ protected Log logger = new FakeLog();
+
+
// -----------------------------------------------------------------------------------------
- // CONSTRUCTORS
+ // ABSTRACT METHODS
// -----------------------------------------------------------------------------------------
+ /**
+ * This is how coordinate your Java test suite code with the conf files to use.
+ * @return absolute path to the value that should be set for $NIMBUS_HOME
+ * @throws Exception if $NIMBUS_HOME cannot be determined
+ */
+ protected abstract String getNimbusHome() throws Exception;
+
+
// -----------------------------------------------------------------------------------------
- // GET/SET
+ // TEST SETUP / TEARDOWN
// -----------------------------------------------------------------------------------------
+ /**
+ * Set up logger and var directory for this test suite. Intended to be called from
+ * your subclass's @BeforeSuite method.
+ *
+ * Configures NIMBUS_HOME via system property.
+ *
+ * Should not use logger until this setup happens.
+ *
+ * @throws Exception problem setting up var dir
+ */
+ public void suiteSetup() throws Exception {
+
+ logger = this.setUpLogger();
+ logger.debug(LOG_SEP + "\n*** SUITE SETUP: " +
+ this.getClass().getSimpleName() + LOG_SEP);
+
+ final String nimbusHome = this.getNimbusHome();
+ logger.info("NIMBUS_HOME: " + nimbusHome);
+
+ System.setProperty(NimbusFileSystemXmlApplicationContext.NIMBUS_HOME_ENV_NAME,
+ nimbusHome);
+
+ final File vardir = new File(nimbusHome, "services/var");
+ if (vardir.exists()) {
+ // teardown was not invoked or developer is trying something 'tricky'
+ logger.error("Generated directory exists, cowardly refusing to remove it; " +
+ "leaving it alone: " + vardir.getAbsolutePath());
+ } else {
+ this.setUpShareDir(nimbusHome);
+ final File setupExe =
+ new File(nimbusHome,
+ "services/share/nimbus/full-reset.sh"); // requires ant on PATH
+ this.setUpVarDir(vardir, setupExe);
+ }
+
+ final File conf = new File(nimbusHome, this.getRelativeSpringConf());
+ // spring wants extra leading / for absolute paths
+ final String springPath = '/' + conf.getAbsolutePath();
+ this.locator = new BreathOfLife().breathe(springPath);
+
+ logger.debug(LOG_SEP + "\n*** SUITE SETUP DONE (tests will begin): " +
+ this.getClass().getSimpleName() + LOG_SEP);
+ }
+
+ /**
+ * Remove var directory used in this test suite. Intended to be called from
+ * your subclass's @AfterSuite method.
+ *
+ * Requires NIMBUS_HOME is set as a system property.
+ *
+ * @throws Exception problem removing var dir
+ */
+ public void suiteTeardown() throws Exception {
+
+ final Properties props = System.getProperties();
+ final String override = props.getProperty(NO_TEARDOWN);
+ if (override != null) {
+ logger.warn(LOG_SEP + "\n*** TESTS DONE, BUT NOT TEARING DOWN: " +
+ this.getClass().getSimpleName() + LOG_SEP);
+ return;
+ }
+
+ logger.debug(LOG_SEP + "\n*** TESTS DONE (beginning teardown): " +
+ this.getClass().getSimpleName() + LOG_SEP);
+
+
+ final String nh = System.getProperty(
+ NimbusFileSystemXmlApplicationContext.NIMBUS_HOME_ENV_NAME);
+ if (nh == null) {
+ throw new Exception("Could not tear down, no NIMBUS_HOME is set");
+ }
+ final File vardir = new File(nh, "services/var");
+ if (!vardir.exists()) {
+ throw new Exception("Could not tear down, var dir " +
+ "does not exist: " + vardir.getAbsolutePath());
+ }
+
+ FileUtils.deleteDirectory(vardir);
+ logger.info("Deleted test suite var dir '" + vardir.getAbsolutePath() + '\'');
+ logger.debug(LOG_SEP + "\n*** TEARDOWN DONE: " +
+ this.getClass().getSimpleName() + LOG_SEP);
+ }
+
+ // -----------------------------------------------------------------------------------------
+ // HELPER METHODS
+ // -----------------------------------------------------------------------------------------
+
+ /**
+ * Returns ReprPopulator instance, a class that helps a test populate RM API
+ * requests easily.
+ *
+ * @see org.globus.workspace.testing.utils.ReprPopulator
+ * @return ReprPopulator
+ */
+ protected ReprPopulator populator() {
+ return new ReprPopulator(this.locator.getReprFactory());
+ }
+
+ /**
+ * Return the path to the spring xml configuration to instantiate for this suite of tests.
+ *
+ * It must be a relative path starting from $NIMBUS_HOME
+ *
+ * A valid value is usually going to be the default but this method is here in case a
+ * suite needs to change it.
+ *
+ * Default: "services/etc/nimbus/workspace-service/other/main.xml"
+ *
+ * @return relative path to spring conf
+ */
+ protected String getRelativeSpringConf() {
+ return "services/etc/nimbus/workspace-service/other/main.xml";
+ }
+
+ /**
+ * Helper for you to implement #getNimbusHome() (see 'basic' example).
+ *
+ * Determine the path to the "service/service/java/tests/suites" directory so
+ * that paths can be conveniently (systematically) constructed to conf files.
+ *
+ * This can be rigged by setting the "nimbus.servicetestsuites.abspath" system property
+ * if you find that necessary (to invoke from ant, for example).
+ *
+ * @return the "service/service/java/tests/suites" directory, never null
+ * @throws Exception if the path can not be determined
+ */
+ public File determineSuitesPath() throws Exception {
+
+ final Properties props = System.getProperties();
+ final String override = props.getProperty(FORCE_SUITES_DIR_PATH);
+ if (override != null) {
+ return new File(override);
+ }
+
+ final String token = "lib" + File.separator + "services" + File.separator;
+ final String classpath = props.getProperty("java.class.path");
+ if (classpath == null) {
+ throw new Exception("java.class.path property was deleted?");
+ }
+
+ final String[] parts = classpath.split(File.pathSeparator);
+ for (String part : parts) {
+ final int idx = part.indexOf(token);
+ if (idx > 0) {
+ if (part.contains(token)) {
+ final File candidate =
+ candidate(part.substring(0,idx), "service/service/java/tests/suites/");
+ if (candidate != null && suitesSubdirsPresent(candidate)) {
+ return candidate;
+ }
+ }
+ }
+ }
+
+ // as a last resort, try analyzing cwd and all of its parent directories
+ // to find repo topdir
+ final File cwd = new File(props.getProperty("user.dir"));
+
+ final String bail = "Adjust CWD or consider using the '" + FORCE_SUITES_DIR_PATH + "' property";
+
+ if (!okdir(cwd)) {
+ throw new Exception(bail);
+ }
+
+ String apath = cwd.getAbsolutePath();
+ while (apath != null) {
+ final File candidate = candidate(apath, "service/service/java/tests/suites/");
+ if (candidate != null && suitesSubdirsPresent(candidate)) {
+ return candidate;
+ }
+ apath = new File(apath).getParent();
+ }
+
+ throw new Exception(bail);
+ }
+
+ protected Log setUpLogger() {
+ final String log4jPropKey = "log4j.configuration";
+
+ // allow test runner to override
+ final String config = System.getProperty(log4jPropKey);
+ if (config != null) {
+ return LogFactory.getLog(NimbusTestBase.class.getName());
+ }
+
+ final String propPath;
+ try {
+ final File suites = this.determineSuitesPath();
+ final File common = new File(suites, "common");
+ if (!okdir(common)) {
+ throw new Exception("could not find common dir");
+ }
+ final File props = new File(common, "suites.log4j.properties");
+ if (!props.exists()) {
+ throw new Exception("file does not exist: " + props.getAbsolutePath());
+ }
+ propPath = props.getAbsolutePath();
+
+ } catch (Exception e) {
+ System.err.println("Warning, could not find any logger configuration: " + e.getMessage());
+ return LogFactory.getLog(NimbusTestBase.class.getName());
+ }
+
+ PropertyConfigurator.configure(propPath);
+ return LogFactory.getLog(NimbusTestBase.class.getName());
+ }
+
+ // candidate repo topdir
+ private static File candidate(String dirString, String append) {
+ final File dir = new File(dirString);
+ if (!okdir(dir)) {
+ return null;
+ }
+ final File testdir = new File(dir, append);
+ if (!okdir(testdir)) {
+ return null;
+ }
+ return testdir;
+ }
+
+ // look for "common" and "basic" subdirs as a sanity check
+ private static boolean suitesSubdirsPresent(File suitedirCandidate) {
+ final File common = new File(suitedirCandidate, "common");
+ if (!okdir(common)) {
+ return false;
+ }
+ final File basic = new File(suitedirCandidate, "basic");
+ return okdir(basic);
+ }
+
+ private static boolean okdir(File dir) {
+ return dir.isAbsolute() && dir.exists() && dir.isDirectory();
+ }
+
+ // set up a fresh var directory, initialize databases etc. using exe
+ protected void setUpVarDir(File vardir, File exe) throws Exception {
+ if (vardir == null) {
+ throw new IllegalArgumentException("vardir is missing");
+ }
+ if (exe == null) {
+ throw new IllegalArgumentException("sharedir is missing");
+ }
+
+ if (!exe.exists()) {
+ throw new IllegalArgumentException(
+ "setup exe does not exist: " + exe.getAbsolutePath());
+ }
+ if (vardir.exists()) {
+ throw new IllegalArgumentException("directory exists: " + vardir.getAbsolutePath());
+ }
+
+ final boolean created = vardir.mkdir();
+ if (!created) {
+ throw new IOException("directory couldn't be created: " + vardir.getAbsolutePath());
+ }
+
+ final String[] cmd = {exe.getAbsolutePath()};
+ WorkspaceUtil.runCommand(cmd, true, false);
+
+ }
+
+ // overwrite "workspace.persistence.conf" to match path
+ protected void setUpShareDir(String nimbusHome) throws Exception {
+ if (nimbusHome == null) {
+ throw new IllegalArgumentException("nimbusHome is missing");
+ }
+ final File nh = new File(nimbusHome);
+ if (!nh.exists()) {
+ throw new IllegalArgumentException(
+ "directory does not exist: " + nh.getAbsolutePath());
+ }
+
+ final File targetdir = new File(nh, "services/share/nimbus");
+ if (!targetdir.exists()) {
+ throw new IllegalArgumentException(
+ "directory does not exist: " + targetdir.getAbsolutePath());
+ }
+ final File targetpath = new File(targetdir, "workspace.persistence.conf");
+
+
+ final Properties conf = new Properties();
+ conf.setProperty("derby.relative.dir.prop", "nimbus");
+ conf.setProperty("workspace.sqldir.prop",
+ new File(nh, "services/share/nimbus/lib").getAbsolutePath());
+ conf.setProperty("derby.system.home.prop",
+ new File(nh, "services/var").getAbsolutePath());
+ conf.setProperty("pwGen.path.prop",
+ new File(nh, "services/etc/nimbus/workspace-service/other/shared-secret-suggestion.py").getAbsolutePath());
+ conf.setProperty("workspace.dbdir.prop",
+ new File(nh, "services/var/nimbus").getAbsolutePath());
+ conf.setProperty("workspace.notifdir.prop",
+ new File(nh, "services/share/nimbus/lib").getAbsolutePath());
+
+ // guess where lib/services is for derby classpath setting
+ String libdir = null;
+ String apath = nh.getAbsolutePath();
+ while (apath != null) {
+ final File candidate = candidate(apath, "lib/services/");
+ if (candidate != null) {
+ libdir = candidate.getAbsolutePath();
+ }
+ apath = new File(apath).getParent();
+ }
+ if (libdir == null) {
+ throw new Exception("could not determine proper lib/services directory, " +
+ "is your nimbus home somewhere outside of the repository");
+ }
+ final File sanityCheck = new File(libdir, "derby.jar");
+ if (!sanityCheck.exists()) {
+ throw new Exception("could not determine proper lib/services directory, " +
+ "is your nimbus home somewhere outside of the repository (derby.jar not found)");
+ }
+ conf.setProperty("derby.classpath.dir.prop", libdir);
+
+
+ final FileOutputStream fos = new FileOutputStream(targetpath);
+ try {
+ conf.store(fos, null);
+ } finally {
+ fos.close();
+ }
+ }
+
}
View
44 service/service/java/tests/suites/common/src/org/globus/workspace/testing/utils/DefaultRequestFactory.java
@@ -1,44 +0,0 @@
-/*
- * Copyright 1999-2010 University of Chicago
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy
- * of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-package org.globus.workspace.testing.utils;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class DefaultRequestFactory {
-
- // -----------------------------------------------------------------------------------------
- // STATIC VARIABLES
- // -----------------------------------------------------------------------------------------
-
- private static final Log logger =
- LogFactory.getLog(DefaultRequestFactory.class.getName());
-
-
- // -----------------------------------------------------------------------------------------
- // INSTANCE VARIABLES
- // -----------------------------------------------------------------------------------------
-
- // -----------------------------------------------------------------------------------------
- // CONSTRUCTORS
- // -----------------------------------------------------------------------------------------
-
- // -----------------------------------------------------------------------------------------
- // GET/SET
- // -----------------------------------------------------------------------------------------
-
-}
View
102 service/service/java/tests/suites/common/src/org/globus/workspace/testing/utils/ReprPopulator.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 1999-2010 University of Chicago
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.globus.workspace.testing.utils;
+
+import org.nimbustools.api._repr._Caller;
+import org.nimbustools.api._repr._CreateRequest;
+import org.nimbustools.api._repr.vm._NIC;
+import org.nimbustools.api._repr.vm._RequiredVMM;
+import org.nimbustools.api._repr.vm._ResourceAllocation;
+import org.nimbustools.api._repr.vm._Schedule;
+import org.nimbustools.api._repr.vm._VMFile;
+import org.nimbustools.api.repr.Caller;
+import org.nimbustools.api.repr.CreateRequest;
+import org.nimbustools.api.repr.ReprFactory;
+import org.nimbustools.api.repr.vm.NIC;
+import org.nimbustools.api.repr.vm.ResourceAllocation;
+import org.nimbustools.api.repr.vm.VMFile;
+
+import java.net.URI;
+
+/**
+ * Non-static to allow suites to easily override defaults for their own situation.
+ * @see org.globus.workspace.testing.NimbusTestBase#populator()
+ */
+public class ReprPopulator {
+
+ protected ReprFactory repr;
+
+ public ReprPopulator(ReprFactory repr) {
+ if (repr == null) {
+ throw new IllegalArgumentException("repr is missing");
+ }
+ this.repr = repr;
+ }
+
+ /**
+ * @param name used for logging
+ * @return simple, populated CreateRequest to send into RM API
+ * @throws Exception problem
+ */
+ public CreateRequest getCreateRequest(String name) throws Exception {
+ final _CreateRequest req = this.repr._newCreateRequest();
+ req.setName(name);
+
+ final _NIC nic = this.repr._newNIC();
+ nic.setNetworkName("public");
+ nic.setAcquisitionMethod(NIC.ACQUISITION_AllocateAndConfigure);
+ req.setRequestedNics(new _NIC[]{nic});
+
+ final _ResourceAllocation ra = this.repr._newResourceAllocation();
+ req.setRequestedRA(ra);
+ final _Schedule schedule = this.repr._newSchedule();
+ schedule.setDurationSeconds(240);
+ req.setRequestedSchedule(schedule);
+ ra.setNodeNumber(1);
+ ra.setMemory(64);
+ req.setShutdownType(CreateRequest.SHUTDOWN_TYPE_TRASH);
+ req.setInitialStateRequest(CreateRequest.INITIAL_STATE_RUNNING);
+
+ ra.setArchitecture(ResourceAllocation.ARCH_x86);
+ final _RequiredVMM reqVMM = this.repr._newRequiredVMM();
+ reqVMM.setType("Xen");
+ reqVMM.setVersions(new String[]{"3"});
+ req.setRequiredVMM(reqVMM);
+
+ final _VMFile file = this.repr._newVMFile();
+ file.setRootFile(true);
+ file.setBlankSpaceName(null);
+ file.setBlankSpaceSize(-1);
+ file.setURI(new URI("file:///tmp/nothing"));
+ file.setMountAs("sda1");
+ file.setDiskPerms(VMFile.DISKPERMS_ReadWrite);
+ req.setVMFiles(new _VMFile[]{file});
+
+ return req;
+ }
+
+ public Caller getCaller() {
+ final _Caller caller = this.repr._newCaller();
+ caller.setIdentity("TEST_RUNNER");
+ return caller;
+ }
+
+ public Caller getSuperuserCaller() {
+ // workspace-service is currently broken with superuser
+ return this.repr._newCaller();
+ }
+}
View
7 service/service/java/tests/suites/common/suites.log4j.properties
@@ -0,0 +1,7 @@
+log4j.rootCategory=ERROR, A1
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} [%t,%M:%L] %m%n
+log4j.category.org.nimbustools=DEBUG
+log4j.category.org.globus.workspace=DEBUG
+
Please sign in to comment.
Something went wrong with that request. Please try again.