use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class DockerfileEnvironmentParserTest method shouldBeAbleToParseDockerfileEnvironmentFromContent.
@Test
public void shouldBeAbleToParseDockerfileEnvironmentFromContent() throws ServerException {
Environment environment = createDockerfileEnvConfig(DEFAULT_DOCKERFILE, null, DEFAULT_MACHINE_NAME);
CheServicesEnvironmentImpl expected = new CheServicesEnvironmentImpl();
expected.getServices().put(DEFAULT_MACHINE_NAME, new CheServiceImpl().withBuild(new CheServiceBuildContextImpl().withDockerfileContent(DEFAULT_DOCKERFILE)));
// when
CheServicesEnvironmentImpl cheServicesEnvironment = parser.parse(environment);
// then
assertEquals(cheServicesEnvironment, expected);
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class MachineProviderImplTest method shouldNotRemoveImageWhenCreatingInstanceFromLocalImage.
@Test
public void shouldNotRemoveImageWhenCreatingInstanceFromLocalImage() throws Exception {
String repo = "repo1";
String tag = "latest";
MachineProviderImpl provider = spy(new MachineProviderBuilder().setSnapshotUseRegistry(false).build());
CheServiceImpl machine = createService();
machine.setBuild(null);
machine.setImage(repo + ":" + tag + "@digest");
provider.startService(USER_NAME, WORKSPACE_ID, ENV_NAME, MACHINE_NAME, false, NETWORK_NAME, machine, LineConsumer.DEV_NULL);
verify(dockerConnector, never()).removeImage(any(RemoveImageParams.class));
}
use of org.eclipse.che.api.environment.server.model.CheServiceImpl in project che by eclipse.
the class WorkspaceRuntimeIntegrationTest method environmentEngineShouldDestroyAllMachinesBeforeRemovalOfEnvironmentRecord.
// Check for https://github.com/codenvy/codenvy/issues/593
@Test(expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = "Workspace with id '" + WORKSPACE_ID + "' is not running")
public void environmentEngineShouldDestroyAllMachinesBeforeRemovalOfEnvironmentRecord() throws Exception {
// given
EnvironmentDto environment = newDto(EnvironmentDto.class);
environment.withMachines(singletonMap("service1", newDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent"))));
WorkspaceConfigDto config = newDto(WorkspaceConfigDto.class).withDefaultEnv(ENV_NAME).withName("ws1").withEnvironments(singletonMap(ENV_NAME, environment));
WorkspaceDto workspace = newDto(WorkspaceDto.class).withId(WORKSPACE_ID).withNamespace("namespace").withConfig(config);
Instance instance = mock(Instance.class);
MachineConfigImpl machineConfig = new MachineConfigImpl();
machineConfig.setDev(true);
machineConfig.setName("service1");
when(instance.getWorkspaceId()).thenReturn(WORKSPACE_ID);
when(instance.getId()).thenReturn("machineId");
when(instance.getConfig()).thenReturn(machineConfig);
CheServicesEnvironmentImpl internalEnv = new CheServicesEnvironmentImpl();
internalEnv.getServices().put("service1", new CheServiceImpl().withId("machineId"));
when(environmentParser.parse(any(Environment.class))).thenReturn(internalEnv);
when(instanceProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(instance);
runtimes.startAsync(workspace, ENV_NAME, false);
verify(sharedPool).submit(taskCaptor.capture());
taskCaptor.getValue().call();
WaitingAnswer<Void> waitingAnswer = new WaitingAnswer<>();
doAnswer(waitingAnswer).when(instance).destroy();
// when
executor.execute(() -> {
try {
runtimes.stop(WORKSPACE_ID);
} catch (Exception e) {
LOG.error(e.getLocalizedMessage(), e);
}
});
waitingAnswer.waitAnswerCall(1, TimeUnit.SECONDS);
// then
// no exception - environment and workspace are still running
runtimes.getRuntime(WORKSPACE_ID);
// let instance removal proceed
waitingAnswer.completeAnswer();
// verify destroying was called
verify(instance, timeout(1000)).destroy();
verify(instanceProvider, timeout(1000)).destroyNetwork(anyString());
// wait to ensure that removal of runtime is finished
Thread.sleep(500);
// runtime is removed - now getting of it should throw an exception
runtimes.getRuntime(WORKSPACE_ID);
}
Aggregations