use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentEngineTest method startEnv.
private List<Instance> startEnv() throws Exception {
EnvironmentImpl env = createEnv();
CheServicesEnvironmentImpl cheServicesEnv = createCheServicesEnv();
return startEnv(env, cheServicesEnv);
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToStartEnvironmentWhenRecoverFailed.
@Test
public void shouldBeAbleToStartEnvironmentWhenRecoverFailed() throws Exception {
// given
String machineImage = "che/ubuntu_jdk";
when(snapshotDao.getSnapshot(anyString(), anyString(), anyString())).thenThrow(new NotFoundException("Snapshot not found"));
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;
});
CheServicesEnvironmentImpl servicesEnvironment = createCheServicesEnv();
for (CheServiceImpl service : servicesEnvironment.getServices().values()) {
service.setImage(machineImage);
}
when(environmentParser.parse(env)).thenReturn(servicesEnvironment);
// 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(), machineImage);
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentEngineTest method stopsTheEnvironmentWhileStartOfMachineIsInterrupted.
@Test
public void stopsTheEnvironmentWhileStartOfMachineIsInterrupted() throws Exception {
// given
EnvironmentImpl env = createEnv();
String envName = "env-1";
String workspaceId = "wsId";
int[] counter = new int[] { env.getMachines().size() };
ArrayList<Instance> created = new ArrayList<>();
when(machineProvider.startService(anyString(), eq(workspaceId), eq(envName), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenAnswer(invocationOnMock -> {
if (--counter[0] == 0) {
Thread.currentThread().interrupt();
throw new ServerException("interrupted!");
}
Object[] arguments = invocationOnMock.getArguments();
NoOpMachineInstance instance = spy(new NoOpMachineInstance(createMachine(workspaceId, envName, (CheServiceImpl) arguments[6], (String) arguments[3], (boolean) arguments[4])));
created.add(instance);
return instance;
});
when(environmentParser.parse(env)).thenReturn(createCheServicesEnv());
// when, then
try {
engine.start(workspaceId, envName, env, false, messageConsumer, startedHandler);
fail("environment must not be running");
} catch (EnvironmentStartInterruptedException x) {
assertEquals(x.getMessage(), format("Start of environment '%s' in workspace '%s' is interrupted", envName, workspaceId));
}
// environment must not be running
try {
engine.getMachines(workspaceId);
fail("environment must not be running");
} catch (EnvironmentNotRunningException x) {
assertEquals(x.getMessage(), format("Environment with ID '%s' is not found", workspaceId));
}
// all the machines expect of the last one must be destroyed
for (Instance instance : created) {
verify(instance).destroy();
}
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldApplyAgentsOnEnvironmentStart.
@Test
public void shouldApplyAgentsOnEnvironmentStart() throws Exception {
EnvironmentImpl env = createEnv();
String machineName = "extraMachine";
//prepare CheServicesEnvironmentImpl which should return compose parser
CheServicesEnvironmentImpl cheServicesEnvironment = createCheServicesEnvByName(machineName);
cheServicesEnvironment.getServices().get(machineName).withImage("codenvy/ubuntu_jdk8");
// when
startEnv(env, cheServicesEnvironment);
// then
verify(machineProvider).startService(anyString(), anyString(), anyString(), eq(machineName), eq(false), anyString(), any(CheServiceImpl.class), any(LineConsumer.class));
verify(infrastructureProvisioner).provision(eq(env), any(CheServicesEnvironmentImpl.class));
verifyNoMoreInteractions(infrastructureProvisioner);
}
use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.
the class EnvironmentParserTest method getEntryForDockerimageEnv.
private static List<Object> getEntryForDockerimageEnv(Map<String, ServerConf2Impl> servers, List<String> expectedExpose, Map<String, String> expectedLabels) {
EnvironmentImpl environmentConfig = createDockerimageEnvConfig();
ExtendedMachineImpl extendedMachine = getMachine(environmentConfig);
extendedMachine.setServers(servers);
CheServicesEnvironmentImpl parsedCheEnv = new CheServicesEnvironmentImpl();
parsedCheEnv.getServices().put(DEFAULT_MACHINE_NAME, new CheServiceImpl().withImage(DEFAULT_DOCKER_IMAGE));
return asList(environmentConfig, createExpectedEnvFromImage(expectedExpose, expectedLabels), parsedCheEnv);
}
Aggregations