Search in sources :

Example 1 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl 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 2 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldBeAbleToStartMachine.

@Test
public void shouldBeAbleToStartMachine() throws Exception {
    // given
    List<Instance> instances = startEnv();
    verify(machineProvider, times(2)).startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class));
    String workspaceId = instances.get(0).getWorkspaceId();
    when(engine.generateMachineId()).thenReturn("newMachineId");
    Instance newMachine = mock(Instance.class);
    when(newMachine.getId()).thenReturn("newMachineId");
    when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
    when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
    MachineConfigImpl config = createConfig(false);
    // when
    Instance actualInstance = engine.startMachine(workspaceId, config, emptyList());
    // then
    assertEquals(actualInstance, newMachine);
    verify(instanceProvider, never()).createInstance(any(Machine.class), any(LineConsumer.class));
    verify(machineProvider, times(3)).startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class));
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) Matchers.anyString(org.mockito.Matchers.anyString) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Machine(org.eclipse.che.api.core.model.machine.Machine) Test(org.testng.annotations.Test)

Example 3 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldUseConfiguredInMachineRamInsteadOfSetDefaultOnMachineStart.

@Test
public void shouldUseConfiguredInMachineRamInsteadOfSetDefaultOnMachineStart() throws Exception {
    // given
    List<Instance> instances = startEnv();
    String workspaceId = instances.get(0).getWorkspaceId();
    when(engine.generateMachineId()).thenReturn("newMachineId");
    Instance newMachine = mock(Instance.class);
    when(newMachine.getId()).thenReturn("newMachineId");
    when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
    when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
    MachineConfigImpl config = createConfig(false);
    String machineName = "extraMachine";
    config.setName(machineName);
    config.setLimits(new MachineLimitsImpl(4096));
    // when
    engine.startMachine(workspaceId, config, emptyList());
    // then
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertEquals((long) actualService.getMemLimit(), 4096L * 1024L * 1024L);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) MachineLimitsImpl(org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 4 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldThrowExceptionOnMachineStartIfEnvironmentIsNotRunning.

@Test(expectedExceptions = EnvironmentNotRunningException.class, expectedExceptionsMessageRegExp = "Environment '.*' is not running")
public void shouldThrowExceptionOnMachineStartIfEnvironmentIsNotRunning() throws Exception {
    MachineConfigImpl config = createConfig(false);
    // when
    engine.startMachine("wsIdOfNotRunningEnv", config, emptyList());
}
Also used : MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Test(org.testng.annotations.Test)

Example 5 with MachineConfigImpl

use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnMachineStart.

@Test
public void shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnMachineStart() throws Exception {
    // given
    List<Instance> instances = startEnv();
    String workspaceId = instances.get(0).getWorkspaceId();
    when(engine.generateMachineId()).thenReturn("newMachineId");
    Instance newMachine = mock(Instance.class);
    when(newMachine.getId()).thenReturn("newMachineId");
    when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
    when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
    MachineConfigImpl config = createConfig(false);
    String machineName = "extraMachine";
    config.setName(machineName);
    config.setSource(new MachineSourceImpl("docker").setLocation(API_ENDPOINT + "/recipe/12345"));
    String dockerfileContent = "this is dockerfile content";
    when(recipeDownloader.getRecipe(anyString())).thenReturn("this is dockerfile content");
    // when
    engine.startMachine(workspaceId, config, emptyList());
    // then
    ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
    verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
    CheServiceImpl actualService = captor.getValue();
    assertNull(actualService.getBuild().getContext());
    assertNull(actualService.getBuild().getDockerfilePath());
    assertEquals(actualService.getBuild().getDockerfileContent(), dockerfileContent);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Aggregations

MachineConfigImpl (org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl)16 Test (org.testng.annotations.Test)14 Instance (org.eclipse.che.api.machine.server.spi.Instance)12 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)8 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)8 Matchers.anyString (org.mockito.Matchers.anyString)8 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 Machine (org.eclipse.che.api.core.model.machine.Machine)3 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)3 MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)3 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)3 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)3 ConflictException (org.eclipse.che.api.core.ConflictException)2 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)2 MachineLimitsImpl (org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl)2 WorkspaceRuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl)2 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)2 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)2 Response (com.jayway.restassured.response.Response)1 HashSet (java.util.HashSet)1