Search in sources :

Example 26 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class WorkspaceRuntimesTest method stopsTheRunningWorkspaceAndRethrowsTheErrorDifferentFromServerException.

@Test
public void stopsTheRunningWorkspaceAndRethrowsTheErrorDifferentFromServerException() throws Exception {
    setRuntime("workspace", WorkspaceStatus.RUNNING);
    doThrow(new EnvironmentNotRunningException("no!")).when(envEngine).stop("workspace");
    try {
        runtimes.stop("workspace");
    } catch (ServerException x) {
        assertEquals(x.getMessage(), "no!");
        assertTrue(x.getCause() instanceof EnvironmentNotRunningException);
    }
    verify(envEngine).stop("workspace");
    assertFalse(runtimeStates.containsKey("workspace"));
    verifyEventsSequence(event("workspace", WorkspaceStatus.RUNNING, WorkspaceStatus.STOPPING, EventType.STOPPING, null), event("workspace", WorkspaceStatus.STOPPING, WorkspaceStatus.STOPPED, EventType.ERROR, "no!"));
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) Test(org.testng.annotations.Test)

Example 27 with ServerException

use of org.eclipse.che.api.core.ServerException 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;
    }
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) CancellationException(java.util.concurrent.CancellationException) EnvironmentException(org.eclipse.che.api.environment.server.exception.EnvironmentException) ConflictException(org.eclipse.che.api.core.ConflictException) NotFoundException(org.eclipse.che.api.core.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException) ServerException(org.eclipse.che.api.core.ServerException) Test(org.testng.annotations.Test)

Example 28 with ServerException

use of org.eclipse.che.api.core.ServerException 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"));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException) Test(org.testng.annotations.Test)

Example 29 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class WorkspaceRuntimesTest method stopsTheRunningWorkspaceWhileServerExceptionOccurs.

@Test
public void stopsTheRunningWorkspaceWhileServerExceptionOccurs() throws Exception {
    setRuntime("workspace", WorkspaceStatus.RUNNING);
    doThrow(new ServerException("no!")).when(envEngine).stop("workspace");
    try {
        runtimes.stop("workspace");
    } catch (ServerException x) {
        assertEquals(x.getMessage(), "no!");
    }
    verify(envEngine).stop("workspace");
    assertFalse(runtimeStates.containsKey("workspace"));
    verifyEventsSequence(event("workspace", WorkspaceStatus.RUNNING, WorkspaceStatus.STOPPING, EventType.STOPPING, null), event("workspace", WorkspaceStatus.STOPPING, WorkspaceStatus.STOPPED, EventType.ERROR, "no!"));
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) Test(org.testng.annotations.Test)

Example 30 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class WorkspaceManagerTest method shouldStopWorkspaceEventIfSnapshotCreationFailed.

@Test
public void shouldStopWorkspaceEventIfSnapshotCreationFailed() throws Exception {
    WorkspaceImpl workspace = createAndMockWorkspace();
    mockRuntime(workspace, RUNNING);
    doThrow(new ServerException("Test")).when(runtimes).snapshot(workspace.getId());
    workspaceManager.stopWorkspace(workspace.getId(), true);
    captureRunAsyncCallsAndRunSynchronously();
    verify(runtimes).stop(any());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) Test(org.testng.annotations.Test)

Aggregations

ServerException (org.eclipse.che.api.core.ServerException)143 IOException (java.io.IOException)51 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)37 ConflictException (org.eclipse.che.api.core.ConflictException)32 File (java.io.File)22 Test (org.testng.annotations.Test)20 ArrayList (java.util.ArrayList)19 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)19 List (java.util.List)15 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)15 Map (java.util.Map)13 Transactional (com.google.inject.persist.Transactional)12 BadRequestException (org.eclipse.che.api.core.BadRequestException)12 InputStream (java.io.InputStream)11 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)10 String.format (java.lang.String.format)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 HashMap (java.util.HashMap)8