use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class SnapshotDaoTest method shouldSaveSnapshot.
@Test(dependsOnMethods = "shouldGetSnapshotById")
public void shouldSaveSnapshot() throws Exception {
final SnapshotImpl newSnapshot = createSnapshot("new-snapshot", workspaces[0].getId(), "env-name", "machine-name");
snapshotDao.saveSnapshot(newSnapshot);
assertEquals(snapshotDao.getSnapshot(newSnapshot.getId()), new SnapshotImpl(newSnapshot));
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class SnapshotDaoTest method shouldGetSnapshotById.
@Test
public void shouldGetSnapshotById() throws Exception {
final SnapshotImpl snapshot = snapshots[0];
assertEquals(snapshotDao.getSnapshot(snapshot.getId()), snapshot);
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl 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.model.impl.SnapshotImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldBeAbleToCreateSnapshot.
@Test
public void shouldBeAbleToCreateSnapshot() throws Exception {
// then
WorkspaceImpl workspace = createAndMockWorkspace();
mockRuntime(workspace, RUNNING);
SnapshotImpl oldSnapshot = mock(SnapshotImpl.class);
when(snapshotDao.getSnapshot(eq(workspace.getId()), eq(workspace.getConfig().getDefaultEnv()), anyString())).thenReturn(oldSnapshot);
// when
workspaceManager.createSnapshot(workspace.getId());
// then
verify(runtimes).snapshotAsync(workspace.getId());
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldRecoverWorkspaceWhenRecoverParameterIsNullAndAutoRestoreAttributeIsSetAndSnapshotExists.
@Test
public void shouldRecoverWorkspaceWhenRecoverParameterIsNullAndAutoRestoreAttributeIsSetAndSnapshotExists() throws Exception {
final WorkspaceImpl workspace = createAndMockWorkspace();
workspace.getAttributes().put(AUTO_RESTORE_FROM_SNAPSHOT, "true");
mockStart(workspace);
SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().generateId().setEnvName("env").setDev(true).setMachineName("machine1").setWorkspaceId(workspace.getId()).setType("docker").setMachineSource(new MachineSourceImpl("image"));
SnapshotImpl snapshot1 = snapshotBuilder.build();
SnapshotImpl snapshot2 = snapshotBuilder.generateId().setDev(false).setMachineName("machine2").build();
when(snapshotDao.findSnapshots(workspace.getId())).thenReturn(asList(snapshot1, snapshot2));
workspaceManager.startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), null);
verify(runtimes).startAsync(workspace, workspace.getConfig().getDefaultEnv(), true);
assertNotNull(workspace.getAttributes().get(UPDATED_ATTRIBUTE_NAME));
}
Aggregations