Search in sources :

Example 6 with WorkspaceRuntimeImpl

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());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Example 7 with WorkspaceRuntimeImpl

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()));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Example 8 with WorkspaceRuntimeImpl

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));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) CancellationException(java.util.concurrent.CancellationException) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 9 with WorkspaceRuntimeImpl

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);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Example 10 with WorkspaceRuntimeImpl

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());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Aggregations

WorkspaceRuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl)21 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)16 Test (org.testng.annotations.Test)16 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)7 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)6 EnvironmentStartInterruptedException (org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException)4 CancellationException (java.util.concurrent.CancellationException)3 NoOpMachineInstance (org.eclipse.che.api.environment.server.NoOpMachineInstance)3 EnvironmentException (org.eclipse.che.api.environment.server.exception.EnvironmentException)3 MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)3 Instance (org.eclipse.che.api.machine.server.spi.Instance)3 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)3 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)3 Response (com.jayway.restassured.response.Response)2 HashSet (java.util.HashSet)2 AgentException (org.eclipse.che.api.agent.server.exception.AgentException)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 ServerException (org.eclipse.che.api.core.ServerException)2 Matchers.anyString (org.mockito.Matchers.anyString)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1