use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class WorkspaceRuntimesTest method removesOldSnapshotsWhenNewSnapshotsMetadataSuccessfullySaved.
@Test
public void removesOldSnapshotsWhenNewSnapshotsMetadataSuccessfullySaved() throws Exception {
WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
setRuntime(workspace.getId(), WorkspaceStatus.RUNNING);
SnapshotImpl oldSnapshot = mock(SnapshotImpl.class);
doReturn((singletonList(oldSnapshot))).when(snapshotDao).replaceSnapshots(any(), any(), any());
runtimes.snapshot(workspace.getId());
verify(envEngine).removeSnapshot(oldSnapshot);
verifyEventsSequence(event(workspace.getId(), WorkspaceStatus.RUNNING, WorkspaceStatus.SNAPSHOTTING, EventType.SNAPSHOT_CREATING, null), event(workspace.getId(), WorkspaceStatus.SNAPSHOTTING, WorkspaceStatus.RUNNING, EventType.SNAPSHOT_CREATED, null));
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class WorkspaceRuntimesTest method removesNewlyCreatedSnapshotsWhenFailedToSaveTheirsMetadata.
@Test
public void removesNewlyCreatedSnapshotsWhenFailedToSaveTheirsMetadata() throws Exception {
WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
setRuntime(workspace.getId(), WorkspaceStatus.RUNNING, "env-name");
doThrow(new SnapshotException("test")).when(snapshotDao).replaceSnapshots(any(), any(), any());
SnapshotImpl snapshot = mock(SnapshotImpl.class);
when(envEngine.saveSnapshot(any(), any())).thenReturn(snapshot);
try {
runtimes.snapshot(workspace.getId());
} catch (ServerException x) {
assertEquals(x.getMessage(), "test");
}
verify(snapshotDao).replaceSnapshots(any(), any(), snapshotsCaptor.capture());
verify(envEngine, times(snapshotsCaptor.getValue().size())).removeSnapshot(snapshot);
verifyEventsSequence(event(workspace.getId(), WorkspaceStatus.RUNNING, WorkspaceStatus.SNAPSHOTTING, EventType.SNAPSHOT_CREATING, null), event(workspace.getId(), WorkspaceStatus.SNAPSHOTTING, WorkspaceStatus.RUNNING, EventType.SNAPSHOT_CREATION_ERROR, "test"));
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldNotCreateSnapshotIfWorkspaceIsTemporaryAndAutoCreateSnapshotDisactivated.
@Test
public void shouldNotCreateSnapshotIfWorkspaceIsTemporaryAndAutoCreateSnapshotDisactivated() throws Exception {
final WorkspaceImpl workspace = createAndMockWorkspace();
workspace.getAttributes().put(Constants.AUTO_CREATE_SNAPSHOT, "false");
mockRuntime(workspace, RUNNING);
SnapshotImpl oldSnapshot = mock(SnapshotImpl.class);
when(snapshotDao.getSnapshot(eq(workspace.getId()), eq(workspace.getConfig().getDefaultEnv()), anyString())).thenReturn(oldSnapshot);
workspace.setTemporary(true);
workspaceManager.stopWorkspace(workspace.getId());
captureRunAsyncCallsAndRunSynchronously();
verify(runtimes, never()).snapshot(workspace.getId());
verify(runtimes).stop(workspace.getId());
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldRecoverWorkspaceWhenRecoverParameterIsTrueAndSnapshotExists.
@Test
public void shouldRecoverWorkspaceWhenRecoverParameterIsTrueAndSnapshotExists() throws Exception {
final WorkspaceImpl workspace = createAndMockWorkspace();
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(), true);
verify(runtimes).startAsync(workspace, workspace.getConfig().getDefaultEnv(), true);
assertNotNull(workspace.getAttributes().get(UPDATED_ATTRIBUTE_NAME));
}
use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldRemoveMachinesSnapshotsEvenSomeRemovalFails.
@Test
public void shouldRemoveMachinesSnapshotsEvenSomeRemovalFails() throws Exception {
// given
String testWsId = "testWsId";
String testNamespace = "testNamespace";
WorkspaceImpl workspaceMock = mock(WorkspaceImpl.class);
when(workspaceDao.get(testWsId)).thenReturn(workspaceMock);
when(workspaceMock.getNamespace()).thenReturn(testNamespace);
SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().generateId().setEnvName("env").setDev(true).setMachineName("machine1").setWorkspaceId(testWsId).setType("docker").setMachineSource(new MachineSourceImpl("image"));
SnapshotImpl snapshot1 = snapshotBuilder.build();
SnapshotImpl snapshot2 = snapshotBuilder.generateId().setDev(false).setMachineName("machine2").build();
when(snapshotDao.findSnapshots(testWsId)).thenReturn(asList(snapshot1, snapshot2));
doThrow(new SnapshotException("test")).when(snapshotDao).removeSnapshot(snapshot1.getId());
// when
workspaceManager.removeSnapshots(testWsId);
// then
captureExecuteCallsAndRunSynchronously();
verify(runtimes).removeBinaries(singletonList(snapshot2));
verify(snapshotDao).removeSnapshot(snapshot1.getId());
verify(snapshotDao).removeSnapshot(snapshot2.getId());
}
Aggregations