use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl 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.workspace.server.model.impl.EnvironmentImpl 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);
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToStartEnvironmentWithRecover.
@Test
public void shouldBeAbleToStartEnvironmentWithRecover() throws Exception {
// given
SnapshotImpl snapshot = mock(SnapshotImpl.class);
MachineSourceImpl machineSource = new MachineSourceImpl("image", "registry.com/snapshot123:latest@sha256:abc1234567890", null);
when(snapshotDao.getSnapshot(anyString(), anyString(), anyString())).thenReturn(snapshot);
when(snapshot.getMachineSource()).thenReturn(machineSource);
// given
EnvironmentImpl env = createEnv();
String envName = "env-1";
String workspaceId = "wsId";
List<Instance> expectedMachines = new ArrayList<>();
when(machineProvider.startService(anyString(), eq(workspaceId), eq(envName), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenAnswer(invocationOnMock -> {
Object[] arguments = invocationOnMock.getArguments();
String machineName = (String) arguments[3];
boolean isDev = (boolean) arguments[4];
CheServiceImpl service = (CheServiceImpl) arguments[6];
Machine machine = createMachine(workspaceId, envName, service, machineName, isDev);
NoOpMachineInstance instance = spy(new NoOpMachineInstance(machine));
expectedMachines.add(instance);
return instance;
});
when(environmentParser.parse(env)).thenReturn(createCheServicesEnv());
// when
List<Instance> machines = engine.start(workspaceId, envName, env, true, messageConsumer);
// then
assertEquals(machines, expectedMachines);
ArgumentCaptor<CheServiceImpl> captor = ArgumentCaptor.forClass(CheServiceImpl.class);
verify(machineProvider).startService(anyString(), anyString(), anyString(), anyString(), eq(false), anyString(), captor.capture(), any(LineConsumer.class));
CheServiceImpl actualService = captor.getValue();
assertEquals(actualService.getImage(), "registry.com/snapshot123:latest");
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentValidatorTest method createEnv.
private static EnvironmentDto createEnv() {
// singletonMap, asList are wrapped into modifiable collections to ease env modifying by tests
EnvironmentImpl env = new EnvironmentImpl();
Map<String, ExtendedMachineImpl> machines = new HashMap<>();
Map<String, ServerConf2Impl> servers = new HashMap<>();
servers.put("ref1", new ServerConf2Impl("8080/tcp", "proto1", singletonMap("prop1", "propValue")));
servers.put("ref2", new ServerConf2Impl("8080/udp", "proto1", null));
servers.put("ref3", new ServerConf2Impl("9090", "proto1", null));
machines.put("dev-machine", new ExtendedMachineImpl(asList("org.eclipse.che.ws-agent", "someAgent"), servers, singletonMap("memoryLimitBytes", "10000")));
machines.put("machine2", new ExtendedMachineImpl(asList("someAgent2", "someAgent3"), null, singletonMap("memoryLimitBytes", "10000")));
env.setRecipe(new EnvironmentRecipeImpl("compose", "application/x-yaml", "content", null));
env.setMachines(machines);
return DtoConverter.asDto(env);
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class EnvironmentParserTest method shouldOverrideMemoryLimitFromExtendedMachineInComposeEnv.
@Test
public void shouldOverrideMemoryLimitFromExtendedMachineInComposeEnv() throws Exception {
// given
HashMap<String, ExtendedMachineImpl> machines = new HashMap<>();
machines.put("machine1", new ExtendedMachineImpl(emptyList(), emptyMap(), singletonMap("memoryLimitBytes", "101010")));
machines.put("machine2", new ExtendedMachineImpl(emptyList(), emptyMap(), emptyMap()));
EnvironmentImpl environment = new EnvironmentImpl(new EnvironmentRecipeImpl("compose", "application/x-yaml", "content", null), machines);
CheServicesEnvironmentImpl cheEnv = new CheServicesEnvironmentImpl();
cheEnv.getServices().put("machine1", new CheServiceImpl());
cheEnv.getServices().put("machine2", new CheServiceImpl());
when(envParser.parse(environment)).thenReturn(cheEnv);
// when
CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
// then
assertEquals(cheServicesEnvironment, cheEnv);
assertEquals(cheServicesEnvironment.getServices().get("machine1").getMemLimit().longValue(), 101010L);
assertEquals(cheServicesEnvironment.getServices().get("machine2").getMemLimit(), null);
}
Aggregations