bug 8529: propagated to master. Added junit test support to ant

This commit is contained in:
Alex Huang 2011-02-16 17:39:57 -08:00
parent b85ecec646
commit 6b0d4947ed
13 changed files with 139 additions and 29 deletions

1
.gitignore vendored
View File

@ -19,4 +19,5 @@ cloud-*.tar.bz2
build.number
api.log.*.gz
cloud.log.*.*
unittest
deps/cloud.userlibraries

View File

@ -587,6 +587,7 @@
<delete dir="${classes.dir}" />
<delete dir="${jar.dir}" />
<delete dir="${dist.dir}" />
<delete dir="${unittest.dir}"/>
</target>
<target name="clean-all" depends="clean" description="Clean all of the generated files, including dependency cache and javadoc">

View File

@ -26,6 +26,7 @@
<property name="target.dir" location="${base.dir}/target"/>
<property name="classes.dir" location="${target.dir}/classes"/>
<property name="tests.dir" location="${target.dir}/tests"/>
<property name="jar.dir" location="${target.dir}/jar"/>
<property name="dep.cache.dir" location="${target.dir}/dep-cache"/>
<property name="debug" value="true"/>
@ -52,7 +53,7 @@
<classpath refid="@{classpath}" />
<exclude-files/>
</javac>
<jar jarfile="${jar.dir}/@{jar.name}" basedir="${classes.dir}/@{jar.name}">
<jar jarfile="${jar.dir}/@{jar.name}" basedir="${classes.dir}/@{jar.name}" update="true">
<manifest>
<attribute name="Class-Path" value="" />
<attribute name="Built-By" value="${built.by}" />

View File

@ -8,15 +8,41 @@
generally developer targets that has nothing to do with compiling.
</description>
<dirname property="base.dir" file="${ant.file.Cloud.com Developer Targets}"/>
<dirname property="base.dir" file="${ant.file.Cloud.com Developer Targets}/.."/>
<property name="build.dir" location="${base.dir}/build"/>
<property name="tomcat.home" location="${env.CATALINA_HOME}"/>
<property name="assertion" value="-ea"/>
<property name="dist.dir" location="${base.dir}"/>
<property name="dist.dir" location="${base.dir}/dist"/>
<property name="deploy.work.dir" location="${dist.dir}"/>
<property name="server.deploy.to.dir" location="${tomcat.home}"/>
<property name="unittest.dir" location="${base.dir}/unittest"/>
<property name="unittest.target.dir" location="${unittest.dir}/classes"/>
<property name="unittest.jar.dir" location="${unittest.dir}/jar"/>
<macrodef name="compile-test">
<attribute name="top.dir" description="Top Directory of the source. We will add src to this to get the source code."/>
<attribute name="jar.name" description="Name of the jar file"/>
<attribute name="classpath" description="class path to use"/>
<element name="include-files" optional="true"/>
<element name="exclude-files" optional="true"/>
<sequential>
<mkdir dir="${unittest.target.dir}/@{jar.name}"/>
<depend srcdir="@{top.dir}/test" destdir="${unittest.target.dir}/@{jar.name}" cache="${dep.cache.dir}" />
<echo message="Compiling @{top.dir}/test"/>
<javac srcdir="@{top.dir}/test" debug="${debug}" debuglevel="${debuglevel}" deprecation="${deprecation}" destdir="${unittest.target.dir}/@{jar.name}" source="${source.compat.version}" target="${target.compat.version}" includeantruntime="false" compiler="javac1.6">
<compilerarg line="-Xlint:-path"/>
<classpath refid="@{classpath}" />
<exclude-files/>
</javac>
<jar jarfile="${unittest.jar.dir}/@{jar.name}" basedir="${unittest.target.dir}/@{jar.name}" update="true"/>
</sequential>
</macrodef>
<target name="clean-edits" description="Delete all the editor backup files in the source tree.">
<delete>
@ -173,5 +199,76 @@
<env key="CATALINA_HOME" value="${tomcat.home}"/>
</exec>
</target>
<path id="test.classpath">
<path refid="deps.classpath" />
<path refid="dist.classpath"/>
<fileset dir="${unittest.jar.dir}">
<include name="*.jar"/>
</fileset>
<fileset dir="${tools.dir}">
<include name="**/junit-4.8.1.jar"/>
</fileset>
</path>
<target name="compile-tests" depends="build-all">
<mkdir dir="${unittest.dir}"/>
<mkdir dir="${unittest.target.dir}"/>
<mkdir dir="${unittest.jar.dir}"/>
<compile-test jar.name="utils-test.jar" top.dir="${utils.dir}" classpath="test.classpath"/>
<compile-test jar.name="server-test.jar" top.dir="${server.dir}" classpath="test.classpath"/>
</target>
<target name="unittest" description="Execute unit tests" depends="compile-tests">
<junit printsummary="true" failureproperty="junit.failure">
<!-- N.b. use failureproperty instead of haltonfailure, because if we use
the former, we will get no detailed report about the failure.
If the test fails, the fail element below will still assure that
the Ant run will exit with error status.
-->
<classpath refid="test.classpath"/>
<batchtest todir="${unittest.dir}">
<formatter type="xml"/>
<fileset dir="${utils.test.dir}">
<include name="**/*Test.java"/>
</fileset>
<fileset dir="${server.test.dir}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${unittest.dir}">
<fileset dir="${unittest.dir}"/>
<report todir="test-reports"/>
</junitreport>
<fail if="junit.failure" message="Unit test(s) failed. See reports!"/>
</target>
<target name="test" description="Execute one unit test" depends="compile-tests">
<junit printsummary="true" failureproperty="junit.failure">
<!-- N.b. use failureproperty instead of haltonfailure, because if we use
the former, we will get no detailed report about the failure.
If the test fails, the fail element below will still assure that
the Ant run will exit with error status.
-->
<classpath refid="test.classpath"/>
<batchtest todir="${unittest.dir}">
<formatter type="xml"/>
<fileset dir="${utils.test.dir}">
<include name="**/${test}.java"/>
</fileset>
<fileset dir="${server.test.dir}">
<include name="**/${test}.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${unittest.dir}">
<fileset dir="${unittest.dir}"/>
<report todir="test-reports"/>
</junitreport>
<fail if="junit.failure" message="Unit test(s) failed. See reports!"/>
</target>
</project>

View File

@ -145,7 +145,7 @@
<target name="build-war-oss" depends="-init-package" description="Compile the GWT client UI and builds WAR file.">
<mkdir dir="${client.dist.dir}" />
<war destfile="${client.dist.dir}/client.war" webxml="${client.dir}/WEB-INF/web.xml">
<war destfile="${client.dist.dir}/client.war" webxml="${client.dir}/WEB-INF/web.xml" update="true">
<fileset dir="${client.target.dir}">
<include name="**/*" />
<exclude name="**/*.properties" />

Binary file not shown.

View File

@ -7,5 +7,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -356,38 +356,40 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
while (en.hasMoreElements()) {
investigator = en.nextElement();
alive = investigator.isVmAlive(vm, host);
s_logger.info(investigator.getName() + " found " + vm + "to be alive? " + alive);
if (alive != null) {
s_logger.debug(investigator.getName() + " found VM " + vm.getName() + "to be alive? " + alive);
break;
}
}
if (alive != null && alive) {
boolean fenced = false;
if (alive == null) {
s_logger.debug("Fencing off VM that we don't know the state of");
Enumeration<FenceBuilder> enfb = _fenceBuilders.enumeration();
while (enfb.hasMoreElements()) {
FenceBuilder fb = enfb.nextElement();
Boolean result = fb.fenceOff(vm, host);
s_logger.info("Fencer " + fb.getName() + " returned " + result);
if (result != null && result) {
fenced = true;
break;
}
}
} else if (!alive) {
fenced = true;
} else {
s_logger.debug("VM " + vm.getName() + " is found to be alive by " + investigator.getName());
if (host.getStatus() == Status.Up) {
s_logger.info(vm + " is alive and host is up. No need to restart it.");
return null;
return null;
} else {
s_logger.debug("Rescheduling because the host is not up but the vm is alive");
return (System.currentTimeMillis() >> 10) + _investigateRetryInterval;
}
}
boolean fenced = false;
if (alive == null || !alive) {
fenced = true;
s_logger.debug("Fencing off VM that we don't know the state of");
Enumeration<FenceBuilder> enfb = _fenceBuilders.enumeration();
while (enfb.hasMoreElements()) {
final FenceBuilder fb = enfb.nextElement();
Boolean result = fb.fenceOff(vm, host);
if (result != null && !result) {
fenced = false;
}
}
}
if (alive== null && !fenced) {
s_logger.debug("We were unable to fence off the VM " + vm.toString());
if (!fenced) {
s_logger.debug("We were unable to fence off the VM " + vm);
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getName() + " which was running on host " + hostDesc, "Insufficient capacity to restart VM, name: " + vm.getName() + ", id: " + vmId + " which was running on host " + hostDesc);
return (System.currentTimeMillis() >> 10) + _restartRetryInterval;
}
@ -446,7 +448,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
if (s_logger.isDebugEnabled()) {
s_logger.debug("Rescheduling VM " + vm.toString() + " to try again in " + _restartRetryInterval);
}
} catch (final InsufficientCapacityException e) {
s_logger.warn("Unable to restart " + vm.toString() + " due to " + e.getMessage());
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodId(), "Unable to restart " + vm.getName() + " which was running on host " + hostDesc, "Insufficient capacity to restart VM, name: " + vm.getName() + ", id: " + vmId + " which was running on host " + hostDesc);

View File

@ -90,6 +90,17 @@ DROP TABLE IF EXISTS `cloud`.`firewall_rules`;
DROP TABLE IF EXISTS `cloud`.`ssh_keypairs`;
DROP TABLE IF EXISTS `cloud`.`usage_event`;
DROP TABLE IF EXISTS `cloud`.`host_tags`;
DROP TABLE IF EXISTS `cloud`.`version`;
CREATE TABLE `cloud`.`version` (
`id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id',
`version` char(40) NOT NULL UNIQUE COMMENT 'version',
`updated` datetime NOT NULL COMMENT 'Date this version table was updated`,
`step` char(32) NOT NULL COMMENT 'Step in the upgrade to this version',
`dump_path` char(255) NOT NULL COMMENT `path to the dump of the database before upgrade`,
PRIMARY KEY (`id`),
INDEX `i_version__version`(`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`op_it_work` (
`id` char(40) COMMENT 'reservation id',
@ -739,7 +750,6 @@ CREATE TABLE `cloud`.`vm_instance` (
`proxy_assign_time` DATETIME NULL COMMENT 'time when console proxy was assigned',
`vnc_password` varchar(255) NOT NULL COMMENT 'vnc password',
`ha_enabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Should HA be enabled for this VM',
`mirrored_vols` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Are the volumes mirrored',
`update_count` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'date state was updated',
`update_time` datetime COMMENT 'date the destroy was requested',
`created` datetime NOT NULL COMMENT 'date created',
@ -864,7 +874,6 @@ CREATE TABLE `cloud`.`console_proxy` (
`public_mac_address` varchar(17) unique COMMENT 'mac address of the public facing network card',
`public_ip_address` varchar(15) UNIQUE COMMENT 'public ip address for the console proxy',
`public_netmask` varchar(15) COMMENT 'public netmask used for the console proxy',
`ram_size` int(10) unsigned NOT NULL DEFAULT 512 COMMENT 'memory to use in mb',
`active_session` int(10) NOT NULL DEFAULT 0 COMMENT 'active session number',
`last_update` DATETIME NULL COMMENT 'Last session update time',
`session_details` BLOB NULL COMMENT 'session detail info',
@ -877,7 +886,6 @@ CREATE TABLE `cloud`.`secondary_storage_vm` (
`public_mac_address` varchar(17) unique COMMENT 'mac address of the public facing network card',
`public_ip_address` varchar(15) UNIQUE COMMENT 'public ip address for the sec storage vm',
`public_netmask` varchar(15) COMMENT 'public netmask used for the sec storage vm',
`ram_size` int(10) unsigned NOT NULL DEFAULT 512 COMMENT 'memory to use in mb',
`guid` varchar(255) COMMENT 'copied from guid of secondary storage host',
`nfs_share` varchar(255) COMMENT 'server and path exported by the nfs server ',
`last_update` DATETIME NULL COMMENT 'Last session update time',
@ -907,7 +915,6 @@ CREATE TABLE `cloud`.`account` (
`state` varchar(10) NOT NULL default 'enabled',
`removed` datetime COMMENT 'date removed',
`cleanup_needed` tinyint(1) NOT NULL default '0',
-- `network_domain` varchar(100) COMMENT 'Network domain name of the Vms of the account',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -69,7 +70,7 @@ public class Adapters<T> implements Iterable<T> {
}
protected void set(List<ComponentInfo<Adapter>> adapters) {
HashMap<String, T> map = new HashMap<String, T>(adapters.size());
HashMap<String, T> map = new LinkedHashMap<String, T>(adapters.size());
for (ComponentInfo<Adapter> adapter : adapters) {
@SuppressWarnings("unchecked")
T t = (T)adapter.instance;