Search in sources :

Example 1 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class ChangeIT method createNewPatchSetOnInvisibleDraftPatchSet.

@Test
public void createNewPatchSetOnInvisibleDraftPatchSet() throws Exception {
    // Clone separate repositories of the same project as admin and as user
    TestRepository<InMemoryRepository> adminTestRepo = cloneProject(project, admin);
    TestRepository<InMemoryRepository> userTestRepo = cloneProject(project, user);
    // Create change as admin
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), adminTestRepo);
    PushOneCommit.Result r1 = push.to("refs/for/master");
    r1.assertOkStatus();
    // Amend draft as admin
    PushOneCommit.Result r2 = amendChange(r1.getChangeId(), "refs/drafts/master", admin, adminTestRepo);
    r2.assertOkStatus();
    // Fetch change
    GitUtil.fetch(userTestRepo, r1.getPatchSet().getRefName() + ":ps");
    userTestRepo.reset("ps");
    // Amend change as user
    PushOneCommit.Result r3 = amendChange(r1.getChangeId(), "refs/for/master", user, userTestRepo);
    r3.assertErrorStatus("cannot add patch set to " + r3.getChange().change().getChangeId() + ".");
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class ConfigChangeIT method rejectDoubleInheritance.

@Test
public void rejectDoubleInheritance() throws Exception {
    setApiUser(admin);
    // Create separate projects to test the config
    Project.NameKey parent = createProject("projectToInheritFrom");
    Project.NameKey child = createProject("projectWithMalformedConfig");
    String config = gApi.projects().name(child.get()).branch(RefNames.REFS_CONFIG).file("project.config").asString();
    // Append and push malformed project config
    String pattern = "[access]\n\tinheritFrom = " + allProjects.get() + "\n";
    String doubleInherit = pattern + "\tinheritFrom = " + parent.get() + "\n";
    config = config.replace(pattern, doubleInherit);
    TestRepository<InMemoryRepository> childRepo = cloneProject(child, admin);
    // Fetch meta ref
    GitUtil.fetch(childRepo, RefNames.REFS_CONFIG + ":cfg");
    childRepo.reset("cfg");
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), childRepo, "Subject", "project.config", config);
    PushOneCommit.Result res = push.to(RefNames.REFS_CONFIG);
    res.assertErrorStatus();
    res.assertMessage("cannot inherit from multiple projects");
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class RefControlTest method add.

private InMemoryRepository add(ProjectConfig pc) {
    PrologEnvironment.Factory envFactory = null;
    ProjectControl.AssistedFactory projectControlFactory = null;
    RulesCache rulesCache = null;
    SitePaths sitePaths = null;
    List<CommentLinkInfo> commentLinks = null;
    InMemoryRepository repo;
    try {
        repo = repoManager.createRepository(pc.getName());
        if (pc.getProject() == null) {
            pc.load(repo);
        }
    } catch (IOException | ConfigInvalidException e) {
        throw new RuntimeException(e);
    }
    all.put(pc.getName(), new ProjectState(sitePaths, projectCache, allProjectsName, allUsersName, projectControlFactory, envFactory, repoManager, rulesCache, commentLinks, capabilityCollectionFactory, pc));
    return repo;
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) SitePaths(com.google.gerrit.server.config.SitePaths) IOException(java.io.IOException) PrologEnvironment(com.google.gerrit.rules.PrologEnvironment) CommentLinkInfo(com.google.gerrit.extensions.api.projects.CommentLinkInfo) RulesCache(com.google.gerrit.rules.RulesCache)

Example 4 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class AbandonIT method batchAbandonChangeProject.

@Test
public void batchAbandonChangeProject() throws Exception {
    String project1Name = name("Project1");
    String project2Name = name("Project2");
    gApi.projects().create(project1Name);
    gApi.projects().create(project2Name);
    TestRepository<InMemoryRepository> project1 = cloneProject(new Project.NameKey(project1Name));
    TestRepository<InMemoryRepository> project2 = cloneProject(new Project.NameKey(project2Name));
    CurrentUser user = atrScope.get().getUser();
    PushOneCommit.Result a = createChange(project1, "master", "x", "x", "x", "");
    List<ChangeControl> controlA = changeFinder.find(a.getChangeId(), user);
    assertThat(controlA).hasSize(1);
    PushOneCommit.Result b = createChange(project2, "master", "x", "x", "x", "");
    List<ChangeControl> controlB = changeFinder.find(b.getChangeId(), user);
    assertThat(controlB).hasSize(1);
    List<ChangeControl> list = ImmutableList.of(controlA.get(0), controlB.get(0));
    exception.expect(ResourceConflictException.class);
    exception.expectMessage(String.format("Project name \"%s\" doesn't match \"%s\"", project2Name, project1Name));
    changeAbandoner.batchAbandon(batchUpdateFactory, new Project.NameKey(project1Name), user, list);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) CurrentUser(com.google.gerrit.server.CurrentUser) ChangeControl(com.google.gerrit.server.project.ChangeControl) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class NoteDbOnlyIT method retryOnLockFailureWithAtomicUpdates.

@Test
public void retryOnLockFailureWithAtomicUpdates() throws Exception {
    assume().that(notesMigration.fuseUpdates()).isTrue();
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getChange().getId();
    String master = "refs/heads/master";
    ObjectId initial;
    try (Repository repo = repoManager.openRepository(project)) {
        ((InMemoryRepository) repo).setPerformsAtomicTransactions(true);
        initial = repo.exactRef(master).getObjectId();
    }
    AtomicInteger updateRepoCalledCount = new AtomicInteger();
    AtomicInteger updateChangeCalledCount = new AtomicInteger();
    AtomicInteger afterUpdateReposCalledCount = new AtomicInteger();
    String result = retryHelper.execute(batchUpdateFactory -> {
        try (BatchUpdate bu = newBatchUpdate(batchUpdateFactory)) {
            bu.addOp(id, new UpdateRefAndAddMessageOp(updateRepoCalledCount, updateChangeCalledCount));
            bu.execute(new ConcurrentWritingListener(afterUpdateReposCalledCount));
        }
        return "Done";
    });
    assertThat(result).isEqualTo("Done");
    assertThat(updateRepoCalledCount.get()).isEqualTo(2);
    assertThat(afterUpdateReposCalledCount.get()).isEqualTo(2);
    assertThat(updateChangeCalledCount.get()).isEqualTo(2);
    List<String> messages = getMessages(id);
    assertThat(Iterables.getLast(messages)).isEqualTo(UpdateRefAndAddMessageOp.CHANGE_MESSAGE);
    assertThat(Collections.frequency(messages, UpdateRefAndAddMessageOp.CHANGE_MESSAGE)).isEqualTo(1);
    try (Repository repo = repoManager.openRepository(project)) {
        // Op lost the race, so the other writer's commit happened first. Then op retried and wrote
        // its commit with the other writer's commit as parent.
        assertThat(commitMessages(repo, initial, repo.exactRef(master).getObjectId())).containsExactly(ConcurrentWritingListener.MSG_PREFIX + "1", UpdateRefAndAddMessageOp.COMMIT_MESSAGE).inOrder();
    }
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ObjectId(org.eclipse.jgit.lib.ObjectId) Change(com.google.gerrit.reviewdb.client.Change) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Repository(org.eclipse.jgit.lib.Repository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)54 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)37 Test (org.junit.Test)37 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)30 Project (com.google.gerrit.reviewdb.client.Project)21 DfsRepositoryDescription (org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription)12 Before (org.junit.Before)12 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)8 Message (com.google.gerrit.testutil.FakeEmailSender.Message)8 PushResult (org.eclipse.jgit.transport.PushResult)8 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)6 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)5 TestAccount (com.google.gerrit.acceptance.TestAccount)4 CurrentUser (com.google.gerrit.server.CurrentUser)4 Config (org.eclipse.jgit.lib.Config)4 Sandboxed (com.google.gerrit.acceptance.Sandboxed)3 SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 LifecycleManager (com.google.gerrit.lifecycle.LifecycleManager)3