use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.
the class WorkspaceRuntimesTest method throwsStartInterruptedExceptionWhenStartIsInterruptedAndEnvironmentStopIsFailed.
@Test
public void throwsStartInterruptedExceptionWhenStartIsInterruptedAndEnvironmentStopIsFailed() throws Exception {
WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
// let's say status is changed to STOPPING by stop method,
// but starting thread hasn't been interrupted yet
allowEnvironmentStart(workspace, "env-name", () -> Thread.currentThread().interrupt());
rejectEnvironmentStop(workspace, new ServerException("no!"));
CompletableFuture<WorkspaceRuntimeImpl> cmpFuture = runtimes.startAsync(workspace, "env-name", false);
captureAndVerifyRuntimeStateAfterInterruption(workspace, cmpFuture);
verifyEventsSequence(event("workspace", WorkspaceStatus.STOPPED, WorkspaceStatus.STARTING, EventType.STARTING, null), event("workspace", WorkspaceStatus.STARTING, WorkspaceStatus.STOPPING, EventType.STOPPING, null), event("workspace", WorkspaceStatus.STOPPING, WorkspaceStatus.STOPPED, EventType.ERROR, "no!"));
verify(envEngine).stop(workspace.getId());
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.
the class WorkspaceRuntimesTest method startedRuntimeAndReturnedFromGetMethodAreTheSame.
@Test
public void startedRuntimeAndReturnedFromGetMethodAreTheSame() throws Exception {
WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
allowEnvironmentStart(workspace, "env-name");
prepareMachines(workspace.getId(), "env-name");
CompletableFuture<WorkspaceRuntimeImpl> cmpFuture = runtimes.startAsync(workspace, "env-name", false);
captureAsyncTaskAndExecuteSynchronously();
assertEquals(cmpFuture.get(), runtimes.getRuntime(workspace.getId()));
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.
the class WorkspaceRuntimesTest method cancellationOfPendingStartTask.
@Test
public void cancellationOfPendingStartTask() throws Throwable {
WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
when(sharedPool.submit(any())).thenReturn(Futures.immediateFuture(null));
CompletableFuture<WorkspaceRuntimeImpl> cmpFuture = runtimes.startAsync(workspace, "env-name", false);
// the real start is not being executed, fake sharedPool suppressed it
// so the situation is the same to the one if the task is cancelled before
// executor service started executing it
runtimes.stop(workspace.getId());
// start awaiting clients MUST receive interruption
try {
cmpFuture.get();
} catch (ExecutionException x) {
verifyCompletionException(cmpFuture, EnvironmentStartInterruptedException.class, "Start of environment 'env-name' in workspace 'workspace' is interrupted");
}
// completed clients receive interrupted exception and cancellation doesn't bother them
try {
captureAsyncTaskAndExecuteSynchronously();
} catch (CancellationException cancelled) {
assertEquals(cancelled.getMessage(), "Start of the workspace 'workspace' was cancelled");
}
verifyEventsSequence(event("workspace", WorkspaceStatus.STOPPED, WorkspaceStatus.STARTING, EventType.STARTING, null), event("workspace", WorkspaceStatus.STARTING, WorkspaceStatus.STOPPING, EventType.STOPPING, null), event("workspace", WorkspaceStatus.STOPPING, WorkspaceStatus.STOPPED, EventType.STOPPED, null));
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldBeAbleToStartMachineInRunningWs.
@Test
public void shouldBeAbleToStartMachineInRunningWs() throws Exception {
// given
WorkspaceImpl workspace = createAndMockWorkspace();
WorkspaceRuntimeImpl runtime = mockRuntime(workspace, RUNNING);
MachineConfigImpl machineConfig = createMachine(workspace.getId(), runtime.getActiveEnv(), false).getConfig();
// when
workspaceManager.startMachine(machineConfig, workspace.getId());
// then
captureExecuteCallsAndRunSynchronously();
verify(runtimes).startMachine(workspace.getId(), machineConfig);
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldBeAbleToGetMachineInstanceIfWorkspaceIsRunning.
@Test
public void shouldBeAbleToGetMachineInstanceIfWorkspaceIsRunning() throws Exception {
// given
final WorkspaceImpl workspace = createAndMockWorkspace();
WorkspaceRuntimeImpl runtime = mockRuntime(workspace, RUNNING);
MachineImpl machine = runtime.getMachines().get(0);
// when
workspaceManager.getMachineInstance(workspace.getId(), machine.getId());
// then
verify(runtimes).getMachine(workspace.getId(), machine.getId());
}
Aggregations