use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class WorkspaceRuntimesTest method shouldInjectRuntime.
@Test
public void shouldInjectRuntime() throws Exception {
// given
WorkspaceImpl workspace = new WorkspaceImpl();
workspace.setId("ws123");
when(statuses.get("ws123")).thenReturn(WorkspaceStatus.RUNNING);
ImmutableMap<String, Machine> machines = ImmutableMap.of("machine", new MachineImpl(emptyMap(), emptyMap(), MachineStatus.STARTING));
RuntimeIdentity identity = new RuntimeIdentityImpl("ws123", "my-env", "myId", "infraNamespace");
RuntimeContext context = mockContext(identity);
ConcurrentHashMap<String, InternalRuntime<?>> runtimesStorage = new ConcurrentHashMap<>();
TestInternalRuntime testRuntime = new TestInternalRuntime(context, machines, WorkspaceStatus.STARTING);
runtimesStorage.put("ws123", testRuntime);
WorkspaceRuntimes localRuntimes = new WorkspaceRuntimes(runtimesStorage, eventService, ImmutableMap.of(TEST_ENVIRONMENT_TYPE, testEnvFactory), infrastructure, sharedPool, workspaceDao, dbInitializer, probeScheduler, statuses, lockService, devfileConverter, false);
// when
localRuntimes.injectRuntime(workspace);
// then
assertEquals(workspace.getStatus(), WorkspaceStatus.RUNNING);
assertEquals(workspace.getRuntime(), asRuntime(testRuntime));
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class WorkspaceRuntimesTest method runtimeIsNotRecoveredIfNoWorkspaceFound.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Workspace configuration is missing for the runtime 'workspace123:my-env'. Runtime won't be recovered")
public void runtimeIsNotRecoveredIfNoWorkspaceFound() throws Exception {
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace");
when(workspaceDao.get(identity.getWorkspaceId())).thenThrow(new NotFoundException("no!"));
// try recover
runtimes.recoverOne(infrastructure, identity);
assertFalse(runtimes.hasRuntime(identity.getWorkspaceId()));
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class WorkspaceRuntimesTest method runtimeIsNotRecoveredIfInfraPreparationFailed.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Couldn't recover runtime 'workspace123:my-env'. Error: oops!")
public void runtimeIsNotRecoveredIfInfraPreparationFailed() throws Exception {
RuntimeIdentity identity = new RuntimeIdentityImpl("workspace123", "my-env", "myId", "infraNamespace");
mockWorkspaceWithConfig(identity);
InternalEnvironment internalEnvironment = mock(InternalEnvironment.class);
doReturn(internalEnvironment).when(testEnvFactory).create(any(Environment.class));
doThrow(new InfrastructureException("oops!")).when(infrastructure).prepare(eq(identity), any(InternalEnvironment.class));
// try recover
runtimes.recoverOne(infrastructure, identity);
assertFalse(runtimes.hasRuntime(identity.getWorkspaceId()));
}
Aggregations