mirror of https://github.com/apache/jclouds.git
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:
parent
8b3010b587
commit
3404850aba
|
@ -29,10 +29,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.*;
|
||||||
import org.virtualbox_4_1.IProgress;
|
|
||||||
import org.virtualbox_4_1.VBoxException;
|
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -48,9 +45,8 @@ import com.google.common.base.Function;
|
||||||
* found. VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened.
|
* found. VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened.
|
||||||
* VBOX_E_IPRT_ERROR: Launching process for machine failed. VBOX_E_VM_ERROR:
|
* VBOX_E_IPRT_ERROR: Launching process for machine failed. VBOX_E_VM_ERROR:
|
||||||
* Failed to assign machine to session.
|
* Failed to assign machine to session.
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*
|
|
||||||
* @see ErrorCode
|
* @see ErrorCode
|
||||||
*/
|
*/
|
||||||
public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void> {
|
public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void> {
|
||||||
|
@ -73,7 +69,7 @@ public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void
|
||||||
public Void apply(@Nullable IMachine machine) {
|
public Void apply(@Nullable IMachine machine) {
|
||||||
try {
|
try {
|
||||||
final IProgress progress = machine
|
final IProgress progress = machine
|
||||||
.launchVMProcess(manager.getSessionObject(), type.stringValue(), environment);
|
.launchVMProcess(manager.getSessionObject(), type.stringValue(), environment);
|
||||||
progress.waitForCompletion(-1);
|
progress.waitForCompletion(-1);
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -81,12 +77,17 @@ public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
ErrorCode errorCode = ErrorCode.valueOf(e);
|
ErrorCode errorCode = ErrorCode.valueOf(e);
|
||||||
switch (errorCode) {
|
switch (errorCode) {
|
||||||
case VBOX_E_INVALID_OBJECT_STATE:
|
case VBOX_E_INVALID_OBJECT_STATE:
|
||||||
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). "
|
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). "
|
||||||
+ "The machine might already be running.", errorCode);
|
+ "The machine might already be running.", errorCode);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
propagate(e);
|
propagate(e);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (manager.getSessionObject().getState() == SessionState.Locked) {
|
||||||
|
// Remove session lock taken by launchVmProcess()
|
||||||
|
manager.getSessionObject().unlockMachine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -26,10 +26,7 @@ import static org.easymock.classextension.EasyMock.verify;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.*;
|
||||||
import org.virtualbox_4_1.IProgress;
|
|
||||||
import org.virtualbox_4_1.ISession;
|
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest")
|
@Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest")
|
||||||
public class LaunchMachineIfNotAlreadyRunningTest {
|
public class LaunchMachineIfNotAlreadyRunningTest {
|
||||||
|
@ -54,9 +51,11 @@ public class LaunchMachineIfNotAlreadyRunningTest {
|
||||||
IMachine machine = createMock(IMachine.class);
|
IMachine machine = createMock(IMachine.class);
|
||||||
IProgress progress = createMock(IProgress.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);
|
expect(machine.launchVMProcess(session, type, environment)).andReturn(progress);
|
||||||
progress.waitForCompletion(-1);
|
progress.waitForCompletion(-1);
|
||||||
|
expect(session.getState()).andReturn(SessionState.Locked);
|
||||||
|
session.unlockMachine();
|
||||||
|
|
||||||
replay(manager, machine, session, progress);
|
replay(manager, machine, session, progress);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue