use of org.eclipse.che.api.machine.server.spi.Instance 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.spi.Instance 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()));
}
use of org.eclipse.che.api.machine.server.spi.Instance in project che by eclipse.
the class CheEnvironmentEngineTest method envStartShouldFireEvents.
@Test
public void envStartShouldFireEvents() throws Exception {
// when
List<Instance> instances = startEnv();
assertTrue(instances.size() > 1, "This test requires at least 2 instances in environment");
// then
for (Instance instance : instances) {
verify(eventService).publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.CREATING).withDev(instance.getConfig().isDev()).withMachineName(instance.getConfig().getName()).withMachineId(instance.getId()).withWorkspaceId(instance.getWorkspaceId()));
verify(eventService).publish(newDto(MachineStatusEvent.class).withEventType(MachineStatusEvent.EventType.RUNNING).withDev(instance.getConfig().isDev()).withMachineName(instance.getConfig().getName()).withMachineId(instance.getId()).withWorkspaceId(instance.getWorkspaceId()));
}
}
use of org.eclipse.che.api.machine.server.spi.Instance 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.machine.server.spi.Instance in project che by eclipse.
the class CheEnvironmentEngineTest method machineStartShouldThrowExceptionIfMachineWithTheSameNameAlreadyExistsInEnvironment.
@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "Machine with name '.*' already exists in environment of workspace '.*'")
public void machineStartShouldThrowExceptionIfMachineWithTheSameNameAlreadyExistsInEnvironment() throws Exception {
// given
List<Instance> instances = startEnv();
Instance instance = instances.get(0);
MachineConfigImpl config = createConfig(false);
config.setName(instance.getConfig().getName());
// when
engine.startMachine(instance.getWorkspaceId(), config, emptyList());
}
Aggregations