Search in sources :

Example 1 with WorkspaceRuntimeImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.

the class WorkspaceRuntimesTest method interruptsStartAfterEnvironmentIsStartedButRuntimeStatusIsNotRunning.

@Test
public void interruptsStartAfterEnvironmentIsStartedButRuntimeStatusIsNotRunning() 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", () -> setRuntime("workspace", WorkspaceStatus.STOPPING));
    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.STOPPED, null));
    verify(envEngine).stop(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 2 with WorkspaceRuntimeImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.

the class WorkspaceRuntimesTest method interruptsStartAfterEnvironmentIsStartedButThreadIsInterrupted.

@Test
public void interruptsStartAfterEnvironmentIsStartedButThreadIsInterrupted() throws Exception {
    WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
    // the status is successfully updated from STARTING -> RUNNING but after
    // that thread is interrupted so #stop is waiting for starting thread to stop the environment
    allowEnvironmentStart(workspace, "env-name", () -> Thread.currentThread().interrupt());
    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.STOPPED, null));
    verify(envEngine).stop(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 3 with WorkspaceRuntimeImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.

the class WorkspaceRuntimesTest method injectsRuntime.

@Test
public void injectsRuntime() throws Exception {
    setRuntime("workspace", WorkspaceStatus.RUNNING, "env-name");
    List<Instance> machines = prepareMachines("workspace", "env-name");
    WorkspaceImpl workspace = WorkspaceImpl.builder().setId("workspace").build();
    runtimes.injectRuntime(workspace);
    assertEquals(workspace.getStatus(), WorkspaceStatus.RUNNING);
    assertEquals(workspace.getRuntime(), new WorkspaceRuntimeImpl("env-name", machines));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) NoOpMachineInstance(org.eclipse.che.api.environment.server.NoOpMachineInstance) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Example 4 with WorkspaceRuntimeImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.

the class WorkspaceRuntimesTest method startsWorkspace.

@Test
public void startsWorkspace() throws Exception {
    WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
    List<Instance> machines = allowEnvironmentStart(workspace, "env-name");
    prepareMachines(workspace.getId(), machines);
    CompletableFuture<WorkspaceRuntimeImpl> cmpFuture = runtimes.startAsync(workspace, "env-name", false);
    captureAsyncTaskAndExecuteSynchronously();
    WorkspaceRuntimeImpl runtime = cmpFuture.get();
    assertEquals(runtimes.getStatus(workspace.getId()), WorkspaceStatus.RUNNING);
    assertEquals(runtime.getActiveEnv(), "env-name");
    assertEquals(runtime.getMachines().size(), machines.size());
    verifyEventsSequence(event("workspace", WorkspaceStatus.STOPPED, WorkspaceStatus.STARTING, EventType.STARTING, null), event("workspace", WorkspaceStatus.STARTING, WorkspaceStatus.RUNNING, EventType.RUNNING, null));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) NoOpMachineInstance(org.eclipse.che.api.environment.server.NoOpMachineInstance) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Example 5 with WorkspaceRuntimeImpl

use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl in project che by eclipse.

the class WorkspaceRuntimesTest method getsRuntime.

@Test
public void getsRuntime() throws Exception {
    setRuntime("workspace", WorkspaceStatus.RUNNING, "env-name");
    List<Instance> machines = prepareMachines("workspace", "env-name");
    assertEquals(runtimes.getRuntime("workspace"), new WorkspaceRuntimeImpl("env-name", machines));
    verify(envEngine).getMachines("workspace");
}
Also used : Instance(org.eclipse.che.api.machine.server.spi.Instance) NoOpMachineInstance(org.eclipse.che.api.environment.server.NoOpMachineInstance) 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