use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceRuntimesTest method failsToCreateSnapshotWhenDevMachineSnapshottingFailed.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "can't save")
public void failsToCreateSnapshotWhenDevMachineSnapshottingFailed() throws Exception {
WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
setRuntime(workspace.getId(), WorkspaceStatus.RUNNING);
prepareMachines(workspace.getId(), "env-name");
when(envEngine.saveSnapshot(any(), any())).thenThrow(new ServerException("can't save"));
try {
runtimes.snapshot(workspace.getId());
} catch (Exception x) {
verifyEventsSequence(event(workspace.getId(), WorkspaceStatus.RUNNING, WorkspaceStatus.SNAPSHOTTING, EventType.SNAPSHOT_CREATING, null), event(workspace.getId(), WorkspaceStatus.SNAPSHOTTING, WorkspaceStatus.RUNNING, EventType.SNAPSHOT_CREATION_ERROR, "can't save"));
throw x;
}
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceRuntimesTest method injectsStoppedStatusWhenWorkspaceDoesNotHaveRuntime.
@Test
public void injectsStoppedStatusWhenWorkspaceDoesNotHaveRuntime() throws Exception {
WorkspaceImpl workspace = WorkspaceImpl.builder().setId("workspace").build();
runtimes.injectRuntime(workspace);
assertEquals(workspace.getStatus(), WorkspaceStatus.STOPPED);
assertNull(workspace.getRuntime());
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl 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.workspace.server.model.impl.WorkspaceImpl 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.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceRuntimesTest method injectsStatusAndEmptyMachinesWhenCanNotGetEnvironmentMachines.
@Test
public void injectsStatusAndEmptyMachinesWhenCanNotGetEnvironmentMachines() throws Exception {
setRuntime("workspace", WorkspaceStatus.RUNNING, "env-name");
setNoMachinesForWorkspace("workspace");
WorkspaceImpl workspace = WorkspaceImpl.builder().setId("workspace").build();
runtimes.injectRuntime(workspace);
assertEquals(workspace.getStatus(), WorkspaceStatus.RUNNING);
assertEquals(workspace.getRuntime().getActiveEnv(), "env-name");
assertTrue(workspace.getRuntime().getMachines().isEmpty());
}
Aggregations