use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceRuntimesTest method cancellationOfPendingStartTask.
@Test
public void cancellationOfPendingStartTask() throws Throwable {
WorkspaceImpl workspace = newWorkspace("workspace", "env-name");
when(sharedPool.submit(any())).thenReturn(Futures.immediateFuture(null));
CompletableFuture<WorkspaceRuntimeImpl> cmpFuture = runtimes.startAsync(workspace, "env-name", false);
// the real start is not being executed, fake sharedPool suppressed it
// so the situation is the same to the one if the task is cancelled before
// executor service started executing it
runtimes.stop(workspace.getId());
// start awaiting clients MUST receive interruption
try {
cmpFuture.get();
} catch (ExecutionException x) {
verifyCompletionException(cmpFuture, EnvironmentStartInterruptedException.class, "Start of environment 'env-name' in workspace 'workspace' is interrupted");
}
// completed clients receive interrupted exception and cancellation doesn't bother them
try {
captureAsyncTaskAndExecuteSynchronously();
} catch (CancellationException cancelled) {
assertEquals(cancelled.getMessage(), "Start of the workspace 'workspace' was cancelled");
}
verifyEventsSequence(event("workspace", WorkspaceStatus.STOPPED, WorkspaceStatus.STARTING, EventType.STARTING, null), event("workspace", WorkspaceStatus.STARTING, WorkspaceStatus.STOPPING, EventType.STOPPING, null), event("workspace", WorkspaceStatus.STOPPING, WorkspaceStatus.STOPPED, EventType.STOPPED, null));
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceServiceTest method shouldNotRestoreWorkspace.
@Test
public void shouldNotRestoreWorkspace() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
when(wsManager.startWorkspace(any(), any(), any())).thenReturn(workspace);
when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().post(SECURE_PATH + "/workspace/" + workspace.getId() + "/runtime" + "?environment=" + workspace.getConfig().getDefaultEnv() + "&restore=false");
assertEquals(response.getStatusCode(), 200);
assertEquals(new WorkspaceImpl(unwrapDto(response, WorkspaceDto.class), TEST_ACCOUNT), workspace);
verify(wsManager).startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), false);
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceServiceTest method shouldUpdateProject.
@Test
public void shouldUpdateProject() throws Exception {
final WorkspaceImpl workspace = createWorkspace(createConfigDto());
when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
final ProjectConfigDto projectDto = createProjectDto();
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(projectDto).when().put(SECURE_PATH + "/workspace/" + workspace.getId() + "/project" + projectDto.getPath());
assertEquals(response.getStatusCode(), 200);
verify(validator).validateConfig(workspace.getConfig());
verify(wsManager).updateWorkspace(any(), any());
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class JpaWorkspaceDaoTest method shouldSynchronizeWorkspaceNameWithConfigNameWhenConfigIsUpdated.
@Test(expectedExceptions = DuplicateKeyException.class)
public void shouldSynchronizeWorkspaceNameWithConfigNameWhenConfigIsUpdated() throws Exception {
final AccountImpl account = new AccountImpl("accountId", "namespace", "test");
final WorkspaceImpl workspace1 = createWorkspace("id", account, "name1");
final WorkspaceImpl workspace2 = createWorkspace("id2", account, "name2");
// persist prepared data
manager.getTransaction().begin();
manager.persist(account);
manager.persist(workspace1);
manager.persist(workspace2);
manager.getTransaction().commit();
// make conflict update
workspace2.getConfig().setName(workspace1.getConfig().getName());
manager.getTransaction().begin();
manager.merge(workspace2);
manager.getTransaction().commit();
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceTckModule method configure.
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(AccountImpl.class, WorkspaceImpl.class, WorkspaceConfigImpl.class, ProjectConfigImpl.class, EnvironmentImpl.class, EnvironmentRecipeImpl.class, ExtendedMachineImpl.class, SourceStorageImpl.class, ServerConf2Impl.class, StackImpl.class, CommandImpl.class, SnapshotImpl.class, RecipeImpl.class).addEntityClass("org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute").setExceptionHandler(H2ExceptionHandler.class).build());
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
bind(new TypeLiteral<TckRepository<AccountImpl>>() {
}).toInstance(new JpaTckRepository<>(AccountImpl.class));
bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {
}).toInstance(new WorkspaceRepository());
bind(new TypeLiteral<TckRepository<StackImpl>>() {
}).toInstance(new StackRepository());
bind(WorkspaceDao.class).to(JpaWorkspaceDao.class);
bind(StackDao.class).to(JpaStackDao.class);
}
Aggregations