use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnMachineStart.
@Test
public void shouldNotSetDockerfileContentInsteadOfUrlIfUrlDoesNotPointToCheApiOnMachineStart() throws Exception {
// given
List<Instance> instances = startEnv();
String workspaceId = instances.get(0).getWorkspaceId();
when(engine.generateMachineId()).thenReturn("newMachineId");
Instance newMachine = mock(Instance.class);
when(newMachine.getId()).thenReturn("newMachineId");
when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
MachineConfigImpl config = createConfig(false);
String machineName = "extraMachine";
config.setName(machineName);
String contextUrl = "http://another-server.com/recipe/12345";
config.setSource(new MachineSourceImpl("docker").setLocation(contextUrl));
// when
engine.startMachine(workspaceId, config, emptyList());
// 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().getDockerfilePath());
assertNull(actualService.getBuild().getDockerfileContent());
assertEquals(actualService.getBuild().getContext(), contextUrl);
}
use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldSetDefaultRamToMachineWithoutRamOnMachineStart.
@Test
public void shouldSetDefaultRamToMachineWithoutRamOnMachineStart() throws Exception {
// given
List<Instance> instances = startEnv();
String workspaceId = instances.get(0).getWorkspaceId();
when(engine.generateMachineId()).thenReturn("newMachineId");
Instance newMachine = mock(Instance.class);
when(newMachine.getId()).thenReturn("newMachineId");
when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
MachineConfigImpl config = createConfig(false);
String machineName = "extraMachine";
config.setName(machineName);
config.setLimits(null);
// when
engine.startMachine(workspaceId, config, emptyList());
// 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.machine.server.model.impl.MachineConfigImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldApplyAgentsOnDockerMachineStart.
@Test
public void shouldApplyAgentsOnDockerMachineStart() throws Exception {
// given
List<Instance> instances = startEnv();
String workspaceId = instances.get(0).getWorkspaceId();
when(engine.generateMachineId()).thenReturn("newMachineId");
Instance newMachine = mock(Instance.class);
when(newMachine.getId()).thenReturn("newMachineId");
when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
when(machineProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(newMachine);
MachineConfigImpl config = createConfig(false);
List<String> agents = asList("agent1", "agent2");
// when
engine.startMachine(workspaceId, config, agents);
// then
verify(infrastructureProvisioner).provision(any(ExtendedMachineImpl.class), any(CheServiceImpl.class));
}
use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToStartNonDockerMachine.
@Test
public void shouldBeAbleToStartNonDockerMachine() throws Exception {
// given
ServerConf2 serverConf2 = mock(ServerConf2.class);
when(serverConf2.getPort()).thenReturn("1111/tcp");
when(serverConf2.getProtocol()).thenReturn("http");
when(serverConf2.getProperties()).thenReturn(singletonMap("path", "some path"));
when(agent.getServers()).thenAnswer(invocation -> singletonMap("ssh", serverConf2));
List<Instance> instances = startEnv();
String workspaceId = instances.get(0).getWorkspaceId();
when(engine.generateMachineId()).thenReturn("newMachineId");
Instance newMachine = mock(Instance.class);
when(newMachine.getId()).thenReturn("newMachineId");
when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
when(machineInstanceProviders.getProvider("anotherType")).thenReturn(instanceProvider);
doReturn(newMachine).when(instanceProvider).createInstance(any(Machine.class), any(LineConsumer.class));
MachineConfigImpl config = MachineConfigImpl.builder().fromConfig(createConfig(false)).setType("anotherType").build();
// when
Instance actualInstance = engine.startMachine(workspaceId, config, singletonList("agent"));
// then
assertEquals(actualInstance, newMachine);
ArgumentCaptor<Machine> argumentCaptor = ArgumentCaptor.forClass(Machine.class);
verify(instanceProvider).createInstance(argumentCaptor.capture(), any(LineConsumer.class));
MachineConfigImpl newConfig = new MachineConfigImpl(config);
newConfig.setServers(singletonList(new ServerConfImpl("ssh", "1111/tcp", "http", "some path")));
assertEquals(argumentCaptor.getValue().getConfig(), newConfig);
}
use of org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl in project che by eclipse.
the class CheEnvironmentEngineTest method machineStartShouldPublishEvents.
@Test
public void machineStartShouldPublishEvents() throws Exception {
// given
List<Instance> instances = startEnv();
Instance instance = instances.get(0);
MachineConfigImpl config = createConfig(false);
when(engine.generateMachineId()).thenReturn("newMachineId");
// when
engine.startMachine(instance.getWorkspaceId(), config, emptyList());
// then
verify(eventService).publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.CREATING).withDev(config.isDev()).withMachineName(config.getName()).withMachineId("newMachineId").withWorkspaceId(instance.getWorkspaceId()));
verify(eventService).publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.RUNNING).withDev(config.isDev()).withMachineName(config.getName()).withMachineId("newMachineId").withWorkspaceId(instance.getWorkspaceId()));
}
Aggregations