Search in sources :

Example 1 with TestSubmitInput

use of com.google.gerrit.server.change.TestSubmitInput in project gerrit by GerritCodeReview.

the class OnStoreSubmitRequirementResultModifierIT method overrideToUnsatisfied_doesNotBlockSubmissionWithRetries.

@Test
public void overrideToUnsatisfied_doesNotBlockSubmissionWithRetries() throws Exception {
    TEST_ON_STORE_SUBMIT_REQUIREMENT_RESULT_MODIFIER.setModificationStrategy(ModificationStrategy.FAIL);
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    approve(changeId);
    ChangeInfo change = gApi.changes().id(changeId).get();
    assertThat(change.submitRequirements).hasSize(1);
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
    false);
    TestSubmitInput input = new TestSubmitInput();
    input.generateLockFailures = new ArrayDeque<>(ImmutableList.of(true));
    gApi.changes().id(changeId).current().submit(input);
    change = gApi.changes().id(changeId).get();
    assertThat(change.submitRequirements).hasSize(2);
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
    true);
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
    false);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) TestSubmitInput(com.google.gerrit.server.change.TestSubmitInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with TestSubmitInput

use of com.google.gerrit.server.change.TestSubmitInput in project gerrit by GerritCodeReview.

the class AbstractSubmit method retrySubmitAfterTornTopicOnLockFailure.

@Test
public void retrySubmitAfterTornTopicOnLockFailure() throws Throwable {
    assume().that(isSubmitWholeTopicEnabled()).isTrue();
    String topic = "test-topic";
    Project.NameKey keyA = createProjectForPush(getSubmitType());
    Project.NameKey keyB = createProjectForPush(getSubmitType());
    TestRepository<?> repoA = cloneProject(keyA);
    TestRepository<?> repoB = cloneProject(keyB);
    PushOneCommit.Result change1 = createChange(repoA, "master", "Change 1", "a.txt", "content", topic);
    PushOneCommit.Result change2 = createChange(repoB, "master", "Change 2", "b.txt", "content", topic);
    approve(change1.getChangeId());
    approve(change2.getChangeId());
    TestSubmitInput input = new TestSubmitInput();
    input.generateLockFailures = new ArrayDeque<>(ImmutableList.of(// Change 1, attempt 1: success
    false, // Change 2, attempt 1: lock failure
    true, // Change 1, attempt 2: success
    false, // Change 2, attempt 2: success
    false, // Leftover value to check total number of calls.
    false));
    submit(change2.getChangeId(), input);
    String expectedTopic = name(topic);
    change1.assertChange(Change.Status.MERGED, expectedTopic, admin);
    change2.assertChange(Change.Status.MERGED, expectedTopic, admin);
    repoA.git().fetch().call();
    RevWalk rwA = repoA.getRevWalk();
    RevCommit masterA = rwA.parseCommit(projectOperations.project(keyA).getHead("master"));
    RevCommit change1Ps = parseCurrentRevision(rwA, change1.getChangeId());
    assertThat(rwA.isMergedInto(change1Ps, masterA)).isTrue();
    repoB.git().fetch().call();
    RevWalk rwB = repoB.getRevWalk();
    RevCommit masterB = rwB.parseCommit(projectOperations.project(keyB).getHead("master"));
    RevCommit change2Ps = parseCurrentRevision(rwB, change2.getChangeId());
    assertThat(rwB.isMergedInto(change2Ps, masterB)).isTrue();
    assertThat(input.generateLockFailures).containsExactly(false);
}
Also used : Project(com.google.gerrit.entities.Project) TestSubmitInput(com.google.gerrit.server.change.TestSubmitInput) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with TestSubmitInput

use of com.google.gerrit.server.change.TestSubmitInput in project gerrit by GerritCodeReview.

the class AbstractSubmit method retrySubmitSingleChangeOnLockFailure.

@Test
public void retrySubmitSingleChangeOnLockFailure() throws Throwable {
    PushOneCommit.Result change = createChange();
    String id = change.getChangeId();
    approve(id);
    TestSubmitInput input = new TestSubmitInput();
    input.generateLockFailures = new ArrayDeque<>(ImmutableList.of(// Attempt 1: lock failure
    true, // Attempt 2: success
    false, // Leftover value to check total number of calls.
    false));
    submit(id, input);
    assertMerged(id);
    testRepo.git().fetch().call();
    RevWalk rw = testRepo.getRevWalk();
    RevCommit master = rw.parseCommit(projectOperations.project(project).getHead("master"));
    RevCommit patchSet = parseCurrentRevision(rw, change.getChangeId());
    assertThat(rw.isMergedInto(patchSet, master)).isTrue();
    assertThat(input.generateLockFailures).containsExactly(false);
}
Also used : TestSubmitInput(com.google.gerrit.server.change.TestSubmitInput) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with TestSubmitInput

use of com.google.gerrit.server.change.TestSubmitInput in project gerrit by GerritCodeReview.

the class SubmoduleSubscriptionsWholeTopicMergeIT method retrySubmitAfterTornTopicOnLockFailure.

@Test
public void retrySubmitAfterTornTopicOnLockFailure() throws Exception {
    Project.NameKey subKey1 = createProjectForPush(getSubmitType());
    TestRepository<?> sub1 = cloneProject(subKey1);
    Project.NameKey subKey2 = createProjectForPush(getSubmitType());
    TestRepository<?> sub2 = cloneProject(subKey2);
    allowMatchingSubmoduleSubscription(subKey1, "refs/heads/master", superKey, "refs/heads/master");
    allowMatchingSubmoduleSubscription(subKey2, "refs/heads/master", superKey, "refs/heads/master");
    Config config = new Config();
    prepareSubmoduleConfigEntry(config, subKey1, "master");
    prepareSubmoduleConfigEntry(config, subKey2, "master");
    pushSubmoduleConfig(superRepo, "master", config);
    ObjectId superPreviousId = pushChangeTo(superRepo, "master");
    String topic = "same-topic";
    ObjectId sub1Id = pushChangeTo(sub1, "refs/for/master", "some message", topic);
    ObjectId sub2Id = pushChangeTo(sub2, "refs/for/master", "some message", topic);
    String changeId1 = getChangeId(sub1, sub1Id).get();
    String changeId2 = getChangeId(sub2, sub2Id).get();
    approve(changeId1);
    approve(changeId2);
    TestSubmitInput input = new TestSubmitInput();
    input.generateLockFailures = new ArrayDeque<>(ImmutableList.of(// Change 1, attempt 1: success
    false, // Change 2, attempt 1: lock failure
    true, // Change 1, attempt 2: success
    false, // Change 2, attempt 2: success
    false, // Leftover value to check total number of calls.
    false));
    gApi.changes().id(changeId1).current().submit(input);
    assertThat(info(changeId1).status).isEqualTo(ChangeStatus.MERGED);
    assertThat(info(changeId2).status).isEqualTo(ChangeStatus.MERGED);
    sub1.git().fetch().call();
    RevWalk rw1 = sub1.getRevWalk();
    RevCommit master1 = rw1.parseCommit(projectOperations.project(subKey1).getHead("master"));
    RevCommit change1Ps = parseCurrentRevision(rw1, changeId1);
    assertThat(rw1.isMergedInto(change1Ps, master1)).isTrue();
    sub2.git().fetch().call();
    RevWalk rw2 = sub2.getRevWalk();
    RevCommit master2 = rw2.parseCommit(projectOperations.project(subKey2).getHead("master"));
    RevCommit change2Ps = parseCurrentRevision(rw2, changeId2);
    assertThat(rw2.isMergedInto(change2Ps, master2)).isTrue();
    assertThat(input.generateLockFailures).containsExactly(false);
    expectToHaveSubmoduleState(superRepo, "master", subKey1, sub1, "master");
    expectToHaveSubmoduleState(superRepo, "master", subKey2, sub2, "master");
    assertWithMessage("submodule subscription update should have made one commit").that(superRepo.getRepository().resolve("origin/master^")).isEqualTo(superPreviousId);
}
Also used : Project(com.google.gerrit.entities.Project) ObjectId(org.eclipse.jgit.lib.ObjectId) Config(org.eclipse.jgit.lib.Config) TestSubmitInput(com.google.gerrit.server.change.TestSubmitInput) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

TestSubmitInput (com.google.gerrit.server.change.TestSubmitInput)4 Test (org.junit.Test)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 Project (com.google.gerrit.entities.Project)2 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 Config (org.eclipse.jgit.lib.Config)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1