Search in sources :

Example 1 with Instance

use of org.eclipse.che.api.machine.server.spi.Instance in project che by eclipse.

the class WorkspaceRuntimesTest method shouldBeAbleToStartMachine.

@Test
public void shouldBeAbleToStartMachine() throws Exception {
    // when
    setRuntime("workspace", WorkspaceStatus.RUNNING, "env-name");
    MachineConfig config = newMachine("workspace", "env-name", "new", false).getConfig();
    Instance instance = mock(Instance.class);
    when(envEngine.startMachine(anyString(), any(MachineConfig.class), any())).thenReturn(instance);
    when(instance.getConfig()).thenReturn(config);
    // when
    Instance actual = runtimes.startMachine("workspace", config);
    // then
    assertEquals(actual, instance);
    verify(envEngine).startMachine(eq("workspace"), eq(config), any());
}
Also used : MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) Instance(org.eclipse.che.api.machine.server.spi.Instance) NoOpMachineInstance(org.eclipse.che.api.environment.server.NoOpMachineInstance) Test(org.testng.annotations.Test)

Example 2 with Instance

use of org.eclipse.che.api.machine.server.spi.Instance in project che by eclipse.

the class WorkspaceRuntimesTest method shouldBeAbleToGetMachine.

@Test
public void shouldBeAbleToGetMachine() throws Exception {
    // given
    Instance expected = newMachine("workspace", "env-name", "existing", false);
    when(envEngine.getMachine("workspace", expected.getId())).thenReturn(expected);
    // when
    Instance actualMachine = runtimes.getMachine("workspace", expected.getId());
    // then
    assertEquals(actualMachine, expected);
    verify(envEngine).getMachine("workspace", expected.getId());
}
Also used : Instance(org.eclipse.che.api.machine.server.spi.Instance) NoOpMachineInstance(org.eclipse.che.api.environment.server.NoOpMachineInstance) Test(org.testng.annotations.Test)

Example 3 with Instance

use of org.eclipse.che.api.machine.server.spi.Instance 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 Instance

use of org.eclipse.che.api.machine.server.spi.Instance 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 Instance

use of org.eclipse.che.api.machine.server.spi.Instance 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

Instance (org.eclipse.che.api.machine.server.spi.Instance)47 Test (org.testng.annotations.Test)36 Matchers.anyString (org.mockito.Matchers.anyString)22 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)19 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)17 MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)17 NotFoundException (org.eclipse.che.api.core.NotFoundException)13 MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)11 ArrayList (java.util.ArrayList)10 ServerException (org.eclipse.che.api.core.ServerException)10 Machine (org.eclipse.che.api.core.model.machine.Machine)10 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)10 EnvironmentNotRunningException (org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException)10 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)10 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)9 ConflictException (org.eclipse.che.api.core.ConflictException)8 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)7 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)7 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)7 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)7