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);
}
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);
}
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);
}
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"));
}
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);
}
Aggregations