Search in sources :

Example 71 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class WalkSorterTest method seriesOfChangesAtSameTimestamp.

@Test
public void seriesOfChangesAtSameTimestamp() throws Exception {
    TestRepository<Repo> p = newRepo("p");
    RevCommit c0 = p.commit().tick(0).create();
    RevCommit c1 = p.commit().tick(0).parent(c0).create();
    RevCommit c2 = p.commit().tick(0).parent(c1).create();
    RevCommit c3 = p.commit().tick(0).parent(c2).create();
    RevCommit c4 = p.commit().tick(0).parent(c3).create();
    RevWalk rw = p.getRevWalk();
    rw.parseCommit(c1);
    assertThat(rw.parseCommit(c2).getCommitTime()).isEqualTo(c1.getCommitTime());
    assertThat(rw.parseCommit(c3).getCommitTime()).isEqualTo(c1.getCommitTime());
    assertThat(rw.parseCommit(c4).getCommitTime()).isEqualTo(c1.getCommitTime());
    ChangeData cd1 = newChange(p, c1);
    ChangeData cd2 = newChange(p, c2);
    ChangeData cd3 = newChange(p, c3);
    ChangeData cd4 = newChange(p, c4);
    List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd3, cd4);
    WalkSorter sorter = new WalkSorter(repoManager);
    assertSorted(sorter, changes, ImmutableList.of(patchSetData(cd4, c4), patchSetData(cd3, c3), patchSetData(cd2, c2), patchSetData(cd1, c1)));
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 72 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class WalkSorterTest method projectsSortedByName.

@Test
public void projectsSortedByName() throws Exception {
    TestRepository<Repo> pa = newRepo("a");
    TestRepository<Repo> pb = newRepo("b");
    RevCommit c1 = pa.commit().create();
    RevCommit c2 = pb.commit().create();
    RevCommit c3 = pa.commit().parent(c1).create();
    RevCommit c4 = pb.commit().parent(c2).create();
    ChangeData cd1 = newChange(pa, c1);
    ChangeData cd2 = newChange(pb, c2);
    ChangeData cd3 = newChange(pa, c3);
    ChangeData cd4 = newChange(pb, c4);
    assertSorted(new WalkSorter(repoManager), ImmutableList.of(cd1, cd2, cd3, cd4), ImmutableList.of(patchSetData(cd3, c3), patchSetData(cd1, c1), patchSetData(cd4, c4), patchSetData(cd2, c2)));
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 73 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byStatusOpen.

@Test
public void byStatusOpen() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
    Change change1 = insert(repo, ins1);
    insert(repo, newChangeWithStatus(repo, Change.Status.MERGED));
    Change[] expected = new Change[] { change1 };
    assertQuery("status:open", expected);
    assertQuery("status:OPEN", expected);
    assertQuery("status:o", expected);
    assertQuery("status:op", expected);
    assertQuery("status:ope", expected);
    assertQuery("status:pending", expected);
    assertQuery("status:PENDING", expected);
    assertQuery("status:p", expected);
    assertQuery("status:pe", expected);
    assertQuery("status:pen", expected);
    assertQuery("is:open", expected);
    assertQuery("is:pending", expected);
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 74 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byAfterSince.

@Test
public void byAfterSince() throws Exception {
    long thirtyHoursInMs = MILLISECONDS.convert(30, HOURS);
    resetTimeWithClockStep(thirtyHoursInMs, MILLISECONDS);
    TestRepository<Repo> repo = createProject("repo");
    long startMs = TestTimeUtil.START.toEpochMilli();
    Change change1 = insert(repo, newChange(repo), null, Instant.ofEpochMilli(startMs));
    Change change2 = insert(repo, newChange(repo), null, Instant.ofEpochMilli(startMs + thirtyHoursInMs));
    TestTimeUtil.setClockStep(0, MILLISECONDS);
    // Change2 was last updated on 2009-10-02 03:00:00 -0000
    for (String predicate : Lists.newArrayList("after:", "since:")) {
        assertQuery(predicate + "2009-10-03");
        assertQuery(predicate + "\"2009-10-01 20:59:59 -0400\"", change2);
        assertQuery(predicate + "\"2009-10-01 20:59:59 -0000\"", change2);
        assertQuery(predicate + "2009-10-01", change2);
        assertQuery(predicate + "2009-09-30", change2, change1);
        assertQuery(predicate + "\"2009-09-30 21:00:00 -0000\"", change2, change1);
        assertQuery(predicate + "\"2009-10-02 03:00:00 -0000\"", change2);
    }
    // Same test as above, but using filter code path.
    for (String predicate : Lists.newArrayList("after:", "since:")) {
        assertQuery(makeIndexedPredicateFilterQuery(predicate + "2009-10-03"));
        assertQuery(makeIndexedPredicateFilterQuery(predicate + "\"2009-10-01 20:59:59 -0400\""), change2);
        assertQuery(makeIndexedPredicateFilterQuery(predicate + "\"2009-10-01 20:59:59 -0000\""), change2);
        assertQuery(makeIndexedPredicateFilterQuery(predicate + "2009-10-01"), change2);
        assertQuery(makeIndexedPredicateFilterQuery(predicate + "2009-09-30"), change2, change1);
        assertQuery(makeIndexedPredicateFilterQuery(predicate + "\"2009-09-30 21:00:00 -0000\""), change2, change1);
        assertQuery(makeIndexedPredicateFilterQuery(predicate + "\"2009-10-02 03:00:00 -0000\""), change2);
    }
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 75 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method reindexIfStale.

@Test
public void reindexIfStale() throws Exception {
    Account.Id user = createAccount("user");
    Project.NameKey project = Project.nameKey("repo");
    TestRepository<Repo> repo = createProject(project.get());
    Change change = insert(repo, newChange(repo));
    String changeId = change.getKey().get();
    ChangeNotes notes = notesFactory.create(change.getProject(), change.getId());
    PatchSet ps = psUtil.get(notes, change.currentPatchSetId());
    requestContext.setContext(newRequestContext(user));
    gApi.changes().id(changeId).edit().create();
    assertQuery("has:edit", change);
    assertThat(indexer.reindexIfStale(project, change.getId()).get()).isFalse();
    // Delete edit ref behind index's back.
    RefUpdate ru = repo.getRepository().updateRef(RefNames.refsEdit(user, change.getId(), ps.id()));
    ru.setForceUpdate(true);
    assertThat(ru.delete()).isEqualTo(RefUpdate.Result.FORCED);
    // Index is stale.
    assertQuery("has:edit", change);
    assertThat(indexer.reindexIfStale(project, change.getId()).get()).isTrue();
    assertQuery("has:edit");
}
Also used : Account(com.google.gerrit.entities.Account) Project(com.google.gerrit.entities.Project) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) RefUpdate(org.eclipse.jgit.lib.RefUpdate) Test(org.junit.Test)

Aggregations

Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)126 Test (org.junit.Test)117 Change (com.google.gerrit.entities.Change)112 Account (com.google.gerrit.entities.Account)30 RevCommit (org.eclipse.jgit.revwalk.RevCommit)30 ChangeInserter (com.google.gerrit.server.change.ChangeInserter)17 ChangeData (com.google.gerrit.server.query.change.ChangeData)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)8 Project (com.google.gerrit.entities.Project)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)5 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)4 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)4 AuthException (com.google.gerrit.extensions.restapi.AuthException)4 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)4 QueryParseException (com.google.gerrit.index.query.QueryParseException)4 IOException (java.io.IOException)4