Search in sources :

Example 51 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnEnvironmentStart.

@Test
public void shouldSetDockerfileContentInsteadOfUrlIfUrlPointsToCheApiOnEnvironmentStart() throws Exception {
    // given
    EnvironmentImpl env = createEnv();
    String machineName = "machineWithDockerfileFromApi";
    String dockerfileContent = "this is dockerfile content";
    when(recipeDownloader.getRecipe(anyString())).thenReturn(dockerfileContent);
    //prepare CheServicesEnvironmentImpl which should return compose parser
    CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
    cheServicesEnvironment.getServices().get(machineName).withBuild(new CheServiceBuildContextImpl().withContext(API_ENDPOINT + "/recipe/12345"));
    // when
    startEnv(env, cheServicesEnvironment);
    // 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) CheServiceBuildContextImpl(org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 52 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldUseConfiguredInServiceRamInsteadOfSetDefaultOnEnvironmentStart.

@Test
public void shouldUseConfiguredInServiceRamInsteadOfSetDefaultOnEnvironmentStart() throws Exception {
    // given
    EnvironmentImpl env = createEnv();
    String machineName = "machineWithoutRam";
    //prepare CheServicesEnvironmentImpl which should return compose parser
    CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
    cheServicesEnvironment.getServices().get(machineName).withMemLimit(42943433L);
    // when
    startEnv(env, cheServicesEnvironment);
    // 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(), 42943433L);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 53 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldReplaceServiceNameWithContainerNameInLinks.

@Test
public void shouldReplaceServiceNameWithContainerNameInLinks() {
    //given
    final String serviceNameToLink = "service";
    final String containerNameToLink = "container";
    List<String> links = new ArrayList<>();
    links.add(serviceNameToLink);
    CheServiceImpl serviceToNormalizeLinks = new CheServiceImpl().withLinks(links);
    CheServiceImpl service1 = mock(CheServiceImpl.class);
    CheServiceImpl service2 = mock(CheServiceImpl.class);
    Map<String, CheServiceImpl> allServices = new HashMap<>();
    allServices.put("this", serviceToNormalizeLinks);
    allServices.put(serviceNameToLink, service1);
    allServices.put("anotherService", service2);
    when(service1.getContainerName()).thenReturn(containerNameToLink);
    // when
    engine.normalizeLinks(serviceToNormalizeLinks, allServices);
    // then
    assertEquals(serviceToNormalizeLinks.getLinks().size(), 1);
    assertEquals(serviceToNormalizeLinks.getLinks().get(0), containerNameToLink);
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 54 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class AgentConfigApplierTest method shouldAddExposedPorts.

@Test
public void shouldAddExposedPorts() throws Exception {
    final ServerConf2 serverConf1 = mock(ServerConf2.class);
    final ServerConf2 serverConf2 = mock(ServerConf2.class);
    when(serverConf1.getPort()).thenReturn("1111/udp");
    when(serverConf2.getPort()).thenReturn("2222/tcp");
    when(sorter.sort(any())).thenReturn(asList(AgentKeyImpl.parse("agent1"), AgentKeyImpl.parse("agent2"), AgentKeyImpl.parse("agent3")));
    when(agent1.getServers()).thenAnswer(invocation -> singletonMap("a", serverConf1));
    when(agent2.getServers()).thenAnswer(invocation -> singletonMap("b", serverConf2));
    when(agent3.getServers()).thenReturn(emptyMap());
    CheServiceImpl service = new CheServiceImpl();
    agentConfigApplier.apply(new ExtendedMachineImpl(asList("agent1", "agent2", "agent3"), emptyMap(), emptyMap()), service);
    List<String> exposedPorts = service.getExpose();
    assertTrue(exposedPorts.contains("1111/udp"));
    assertTrue(exposedPorts.contains("2222/tcp"));
}
Also used : CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) ServerConf2(org.eclipse.che.api.core.model.workspace.ServerConf2) Test(org.testng.annotations.Test)

Example 55 with CheServiceImpl

use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.

the class CheEnvironmentEngineTest method shouldSetDefaultRamToMachinesWithoutRamOnEnvironmentStart.

@Test
public void shouldSetDefaultRamToMachinesWithoutRamOnEnvironmentStart() throws Exception {
    // given
    EnvironmentImpl env = createEnv();
    String machineName = "machineWithoutRam";
    //prepare CheServicesEnvironmentImpl which should return compose parser
    CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
    // when
    startEnv(env, cheServicesEnvironment);
    // 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(), DEFAULT_MACHINE_MEM_LIMIT_MB * 1024L * 1024L);
}
Also used : LineConsumer(org.eclipse.che.api.core.util.LineConsumer) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Aggregations

CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)93 Test (org.testng.annotations.Test)63 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)46 Matchers.anyString (org.mockito.Matchers.anyString)32 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)28 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)24 Map (java.util.Map)18 Machine (org.eclipse.che.api.core.model.machine.Machine)17 CreateContainerParams (org.eclipse.che.plugin.docker.client.params.CreateContainerParams)17 ServerException (org.eclipse.che.api.core.ServerException)16 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)16 IOException (java.io.IOException)14 List (java.util.List)14 ServerConf (org.eclipse.che.api.core.model.machine.ServerConf)14 Collections.singletonMap (java.util.Collections.singletonMap)13 Set (java.util.Set)13 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)13 Instance (org.eclipse.che.api.machine.server.spi.Instance)13 EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)13