Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added new suites module 'failure' and added a mock destruction task t…

…hat can be controlled from test suite
  • Loading branch information...
commit 101fbb6620e5053e6bd09d9ffaffc54ca1207311 1 parent de4b979
@timf timf authored
View
13 .idea-modules/service-suites/failure.iml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$/../../service/service/java/tests/suites/failure">
+ <sourceFolder url="file://$MODULE_DIR$/../../service/service/java/tests/suites/failure/src" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="tests-common" />
+ </component>
+</module>
+
View
11 .idea/misc.xml
@@ -6,6 +6,14 @@
<component name="FacetAutodetectingManager">
<autodetection-disabled>
<facet-type id="android" />
+ <facet-type id="Spring">
+ <modules>
+ <module name="basic" />
+ <module name="contextualization" />
+ <module name="failure" />
+ <module name="spotinstances" />
+ </modules>
+ </facet-type>
</autodetection-disabled>
</component>
<component name="IdProvider" IDEtalkID="31C23B711CCADF411B803EE1B405EEB0" />
@@ -26,6 +34,9 @@
<option name="LOCALE" />
<option name="OPEN_IN_BROWSER" value="true" />
</component>
+ <component name="ProjectResources">
+ <default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
+ </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
View
1  .idea/modules.xml
@@ -10,6 +10,7 @@
<module fileurl="file://$PROJECT_DIR$/.idea-modules/docs/docs.iml" filepath="$PROJECT_DIR$/.idea-modules/docs/docs.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea-modules/query/ec2query.iml" filepath="$PROJECT_DIR$/.idea-modules/query/ec2query.iml" group="protocols" />
<module fileurl="file://$PROJECT_DIR$/.idea-modules/ec2soap/ec2soap.iml" filepath="$PROJECT_DIR$/.idea-modules/ec2soap/ec2soap.iml" group="protocols" />
+ <module fileurl="file://$PROJECT_DIR$/.idea-modules/service-suites/failure.iml" filepath="$PROJECT_DIR$/.idea-modules/service-suites/failure.iml" group="service-suites" />
<module fileurl="file://$PROJECT_DIR$/.idea-modules/installer/installer.iml" filepath="$PROJECT_DIR$/.idea-modules/installer/installer.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea-modules/rm-api/rm-api.iml" filepath="$PROJECT_DIR$/.idea-modules/rm-api/rm-api.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea-modules/service-suites//spotinstances.iml" filepath="$PROJECT_DIR$/.idea-modules/service-suites//spotinstances.iml" group="service-suites" />
View
26 service/service/java/source/src/org/globus/workspace/service/impls/async/RequestFactoryImpl.java
@@ -73,6 +73,7 @@
public static final String XEN_LOCAL = "xenlocal";
public static final String XEN_SSH = "xenssh";
+ public static final String FAILURE_COMMANDS = "failure_commands"; // for test suites only
private static final String sshP =
"org.globus.workspace.xen.xenssh";
@@ -423,6 +424,9 @@ protected boolean init(String keyword) {
} else if (keyword.trim().equalsIgnoreCase(XEN_LOCAL)) {
result = loadLocal();
this.commandSet = XEN_LOCAL;
+ } else if (keyword.trim().equalsIgnoreCase(FAILURE_COMMANDS)) {
+ result = loadFailureCommands();
+ this.commandSet = FAILURE_COMMANDS;
}
// addressed Bug 6998 until Bug 7063 can be fixed
@@ -451,6 +455,18 @@ private boolean loadLocal() {
}
}
+ private boolean loadFailureCommands() {
+ try {
+ final String prefix = sshP;
+ loadXenCommon(prefix);
+ testingReplaceShutdownTrash(prefix);
+ return true;
+ } catch (Throwable e) {
+ logger.fatal("",e);
+ return false;
+ }
+ }
+
private void loadXenCommon(String pre) throws Throwable {
impls.put(cancelUnpropagated, null);
@@ -483,4 +499,14 @@ private void loadXenCommon(String pre) throws Throwable {
this.impls.put(cancelReadyForTr, null);
}
+
+ // See the MockShutdownTrash notes.
+ private void testingReplaceShutdownTrash(String pre) throws Throwable {
+ this.impls.put(cancelPropagating, Class.forName(pre + ".MockShutdownTrash"));
+ this.impls.put(cancelPropToStart, Class.forName(pre + ".MockShutdownTrash"));
+ this.impls.put(cancelPropToPause, Class.forName(pre + ".MockShutdownTrash"));
+ this.impls.put(shutdownTrash, Class.forName(pre + ".MockShutdownTrash"));
+ this.impls.put(cancelAllAtVMM, Class.forName(pre + ".MockShutdownTrash"));
+ this.impls.put(cancelReadyingForTr, Class.forName(pre + ".MockShutdownTrash"));
+ }
}
View
12 service/service/java/source/src/org/globus/workspace/xen/XenTask.java
@@ -37,6 +37,7 @@
protected String name;
protected boolean doFakeLag;
+ protected boolean doFakeFail;
protected String[] cmd;
// if success just means another asynchronous task was started
@@ -112,7 +113,7 @@ public void execute() {
}
} else {
if (event) {
- logger.info(Lager.ev(ctx.getId()) + this.name + " failed");
+ logger.error(Lager.ev(ctx.getId()) + this.name + " failed");
} else if (trace) {
logger.trace(Lager.id(ctx.getId()) + ": " +
this.name + " failed");
@@ -168,6 +169,12 @@ private Exception _execute(boolean fake) {
}
}
+ // For testing with mock task system
+ if (this.doFakeFail) {
+ return XenUtil.translateReturnException(
+ new ReturnException(1, "Instructed to fail."));
+ }
+
if (eventLog) {
logger.info(Lager.ev(id) + "banner:" +
@@ -231,11 +238,12 @@ private Exception _execute(boolean fake) {
// before it is implemented (i.e., make just this one thing fake
// for the timebeing without using the fakeness infrastructure
// for other commands...).
-
if (this.cmd != null) {
WorkspaceUtil.runCommand(this.cmd, eventLog, traceLog, id);
}
+
return null;
+
} catch (ReturnException e) {
return XenUtil.translateReturnException(e);
} catch (WorkspaceException e) {
View
66 service/service/java/source/src/org/globus/workspace/xen/xenssh/MockShutdownTrash.java
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+package org.globus.workspace.xen.xenssh;
+
+import org.globus.workspace.WorkspaceException;
+import org.globus.workspace.cmdutils.SSHUtil;
+import org.globus.workspace.service.binding.vm.VirtualMachine;
+import org.globus.workspace.xen.XenTask;
+import org.globus.workspace.xen.XenUtil;
+
+import java.util.ArrayList;
+
+/**
+ * We don't have Spring based task configuration, but rather "command sets" in the
+ * {@link org.globus.workspace.service.impls.async.RequestFactoryImpl} class (also see
+ * {@link org.globus.workspace.service.impls.async.RequestFactory}). So instead of
+ * reworking that to use IoC for easy mocking, we added this mock implementation to
+ * a special command set.
+ */
+public class MockShutdownTrash extends XenTask {
+
+ private static boolean fail = false;
+
+ // Point of control from tests, ANY created task object will respect this static field
+ // when the init() method is called -- so creating a number of instances simultaneously
+ // where only a few of them fail is not possible.
+ public static void setFail(boolean doFail) {
+ fail = doFail;
+ }
+
+ protected void init() throws WorkspaceException {
+ this.name = "MOCK-Shutdown-Trash";
+ this.doFakeLag = true;
+
+ final VirtualMachine vm = this.ctx.getVm();
+ if (vm == null) {
+ throw new WorkspaceException("no VirtualMachine in request " +
+ "context, can not " + this.name);
+ }
+
+ final ArrayList ssh = SSHUtil.constructSshCommand(vm.getNode());
+ final ArrayList exe = XenUtil.constructRemoveCommand(vm, true);
+ ssh.addAll(exe);
+
+ if (fail) {
+ this.doFakeFail = true;
+ logger.warn(this.name + " forced to fail.");
+ }
+
+ this.cmd = (String[]) ssh.toArray(new String[ssh.size()]);
+ }
+}
View
108 ...ce/service/java/tests/suites/failure/src/org/globus/workspace/testing/suites/failure/TerminateSuite.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 1999-2011 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.suites.failure;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+import org.globus.workspace.testing.NimbusTestBase;
+import org.globus.workspace.testing.NimbusTestContextLoader;
+import org.globus.workspace.xen.xenssh.MockShutdownTrash;
+import org.nimbustools.api.repr.Caller;
+import org.nimbustools.api.repr.CreateResult;
+import org.nimbustools.api.repr.vm.VM;
+import org.nimbustools.api.services.rm.Manager;
+import org.springframework.test.context.ContextConfiguration;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.Test;
+
+@ContextConfiguration(
+ locations={"file:./service/service/java/tests/suites/failure/home/services/etc/nimbus/workspace-service/other/main.xml"},
+ loader=NimbusTestContextLoader.class)
+public class TerminateSuite extends NimbusTestBase {
+
+ // -----------------------------------------------------------------------------------------
+ // extends NimbusTestBase
+ // -----------------------------------------------------------------------------------------
+
+ @AfterSuite(alwaysRun=true)
+ @Override
+ public void suiteTeardown() throws Exception {
+ super.suiteTeardown();
+ }
+
+ /**
+ * 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() + "/failure/home";
+ }
+
+
+ // -----------------------------------------------------------------------------------------
+ // 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 Caller caller = this.populator().getCaller();
+ final CreateResult result =
+ rm.create(this.populator().getCreateRequest("suite:basic:leaseOne"),
+ caller);
+
+ final VM[] vms = result.getVMs();
+ assertEquals(1, vms.length);
+ assertNotNull(vms[0]);
+ logger.info("Leased vm '" + vms[0].getID() + '\'');
+
+ assertTrue(rm.exists(vms[0].getID(), Manager.INSTANCE));
+
+ Thread.sleep(4000L);
+ rm.trash(vms[0].getID(), Manager.INSTANCE, caller);
+
+ Thread.sleep(1000L);
+
+ final VM[] allvms = rm.getGlobalAll();
+ assertEquals(0, allvms.length);
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.