Small fix for running live tests from clean slate. Still stuff to do to get it running more than once...

This commit is contained in:
Mattias Holmqvist 2011-10-29 21:48:55 +02:00
parent 8b3010b587
commit 3404850aba
2 changed files with 18 additions and 18 deletions

View File

@ -29,10 +29,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.virtualbox.domain.ErrorCode;
import org.jclouds.virtualbox.domain.ExecutionType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
import org.virtualbox_4_1.*;
import com.google.common.base.Function;
@ -50,7 +47,6 @@ import com.google.common.base.Function;
* Failed to assign machine to session.
*
* @author Mattias Holmqvist
*
* @see ErrorCode
*/
public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void> {
@ -73,7 +69,7 @@ public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void
public Void apply(@Nullable IMachine machine) {
try {
final IProgress progress = machine
.launchVMProcess(manager.getSessionObject(), type.stringValue(), environment);
.launchVMProcess(manager.getSessionObject(), type.stringValue(), environment);
progress.waitForCompletion(-1);
Thread.sleep(5000);
} catch (InterruptedException e) {
@ -81,12 +77,17 @@ public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void
} catch (VBoxException e) {
ErrorCode errorCode = ErrorCode.valueOf(e);
switch (errorCode) {
case VBOX_E_INVALID_OBJECT_STATE:
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). "
+ "The machine might already be running.", errorCode);
break;
default:
propagate(e);
case VBOX_E_INVALID_OBJECT_STATE:
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). "
+ "The machine might already be running.", errorCode);
break;
default:
propagate(e);
}
} finally {
if (manager.getSessionObject().getState() == SessionState.Locked) {
// Remove session lock taken by launchVmProcess()
manager.getSessionObject().unlockMachine();
}
}
return null;

View File

@ -26,10 +26,7 @@ import static org.easymock.classextension.EasyMock.verify;
import org.jclouds.virtualbox.domain.ExecutionType;
import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.VirtualBoxManager;
import org.virtualbox_4_1.*;
@Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest")
public class LaunchMachineIfNotAlreadyRunningTest {
@ -54,9 +51,11 @@ public class LaunchMachineIfNotAlreadyRunningTest {
IMachine machine = createMock(IMachine.class);
IProgress progress = createMock(IProgress.class);
expect(manager.getSessionObject()).andReturn(session);
expect(manager.getSessionObject()).andReturn(session).anyTimes();
expect(machine.launchVMProcess(session, type, environment)).andReturn(progress);
progress.waitForCompletion(-1);
expect(session.getState()).andReturn(SessionState.Locked);
session.unlockMachine();
replay(manager, machine, session, progress);