Search in sources :

Example 61 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class GroupsIT method reindexGroupsInSlaveMode.

@Test
@Sandboxed
@GerritConfig(name = "index.scheduledIndexer.enabled", value = "false")
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
@IgnoreGroupInconsistencies
public void reindexGroupsInSlaveMode() throws Exception {
    List<AccountGroup.UUID> expectedGroups = groups.getAllGroupReferences().map(GroupReference::getUUID).collect(toList());
    assertThat(expectedGroups.size()).isAtLeast(2);
    // Restart the server as slave, on startup of the slave all groups are indexed.
    restartAsSlave();
    GroupIndexedCounter groupIndexedCounter = new GroupIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(groupIndexedCounter)) {
        // Running the reindexer right after startup should not need to reindex any group since
        // reindexing was already done on startup.
        slaveGroupIndexer.run();
        groupIndexedCounter.assertNoReindex();
        // Create a group without updating the cache or index,
        // then run the reindexer -> only the new group is reindexed.
        String groupName = "foo";
        AccountGroup.UUID groupUuid = AccountGroup.uuid(groupName + "-UUID");
        groupsUpdate.createGroupInNoteDb(InternalGroupCreation.builder().setGroupUUID(groupUuid).setNameKey(AccountGroup.nameKey(groupName)).setId(AccountGroup.id(seq.nextGroupId())).build(), GroupDelta.builder().build());
        slaveGroupIndexer.run();
        groupIndexedCounter.assertReindexOf(groupUuid);
        // Update a group without updating the cache or index,
        // then run the reindexer -> only the updated group is reindexed.
        groupsUpdate.updateGroupInNoteDb(groupUuid, GroupDelta.builder().setDescription("bar").build());
        slaveGroupIndexer.run();
        groupIndexedCounter.assertReindexOf(groupUuid);
        // then run the reindexer -> only the deleted group is reindexed.
        try (Repository repo = repoManager.openRepository(allUsers)) {
            RefUpdate u = repo.updateRef(RefNames.refsGroups(groupUuid));
            u.setForceUpdate(true);
            assertThat(u.delete()).isEqualTo(RefUpdate.Result.FORCED);
        }
        slaveGroupIndexer.run();
        groupIndexedCounter.assertReindexOf(groupUuid);
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) AccountGroup(com.google.gerrit.entities.AccountGroup) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RefUpdate(org.eclipse.jgit.lib.RefUpdate) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

Example 62 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class SubmitRequirementIT method submitRequirements_eliminatesDuplicatesForLegacyNonMatchingSRs.

@Test
public void submitRequirements_eliminatesDuplicatesForLegacyNonMatchingSRs() throws Exception {
    // If a custom/prolog submit rule emits the same label name multiple times, we merge these into
    // a single submit requirement result: in this test, we have two different submit rules that
    // return the same label name, one as "OK" and the other as "NEED". The submit requirements
    // API favours the blocking entry and returns one SR result with status=UNSATISFIED.
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    SubmitRule r1 = createSubmitRule("r1", SubmitRecord.Status.OK, "CR", SubmitRecord.Label.Status.OK);
    SubmitRule r2 = createSubmitRule("r2", SubmitRecord.Status.NOT_READY, "CR", SubmitRecord.Label.Status.NEED);
    try (Registration registration = extensionRegistry.newRegistration().add(r1).add(r2)) {
        ChangeInfo change = gApi.changes().id(changeId).get();
        Collection<SubmitRequirementResultInfo> submitRequirements = change.submitRequirements;
        assertThat(submitRequirements).hasSize(2);
        assertSubmitRequirementStatus(submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
        true);
        assertSubmitRequirementStatus(submitRequirements, "CR", Status.UNSATISFIED, /* isLegacy= */
        true);
    }
}
Also used : SubmitRule(com.google.gerrit.server.rules.SubmitRule) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 63 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class SubmitRequirementIT method projectSubmitRequirementDuplicatesGlobal_overrideNotAllowed_globalEvaluated.

@Test
public void projectSubmitRequirementDuplicatesGlobal_overrideNotAllowed_globalEvaluated() throws Exception {
    SubmitRequirement globalSubmitRequirement = SubmitRequirement.builder().setName("CoDe-reView").setSubmittabilityExpression(SubmitRequirementExpression.create("topic:test")).setAllowOverrideInChildProjects(false).build();
    try (Registration registration = extensionRegistry.newRegistration().add(globalSubmitRequirement)) {
        configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
        PushOneCommit.Result r = createChange();
        String changeId = r.getChangeId();
        // Vote does not satisfy submit requirement, because the global definition is evaluated.
        voteLabel(changeId, "CoDe-reView", 2);
        ChangeInfo change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(2);
        assertSubmitRequirementStatus(change.submitRequirements, "CoDe-reView", Status.UNSATISFIED, /* isLegacy= */
        false);
        // In addition, the legacy submit requirement is emitted, since the status mismatch
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        true);
        // Setting the topic satisfies the global definition.
        gApi.changes().id(changeId).topic("test");
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "CoDe-reView", Status.SATISFIED, /* isLegacy= */
        false);
    }
}
Also used : LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 64 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method sticky_copiedToLatestPatchSetFromSubmitRecords.

@Test
public void sticky_copiedToLatestPatchSetFromSubmitRecords() throws Exception {
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().updateLabelType(LabelId.VERIFIED, b -> b.setFunction(LabelFunction.NO_BLOCK));
        u.save();
    }
    // mentioned in the Submitted-With footer) is returned from the API.
    try (Registration registration = extensionRegistry.newRegistration().add(new TestSubmitRule(user.id()))) {
        // We want to add a vote on PS1, then not copy it to PS2, but include it in submit records
        PushOneCommit.Result r = createChange();
        String changeId = r.getChangeId();
        // Vote on patch-set 1
        vote(admin, changeId, 2, 1);
        vote(user, changeId, 1, -1);
        // Upload patch-set 2. Change user's "Verified" vote on PS2.
        changeOperations.change(Change.id(r.getChange().getId().get())).newPatchset().file("new_file").content("content").commitMessage("Upload PS2").create();
        vote(admin, changeId, 2, 1);
        vote(user, changeId, 1, 1);
        // Upload patch-set 3
        changeOperations.change(Change.id(r.getChange().getId().get())).newPatchset().file("another_file").content("content").commitMessage("Upload PS3").create();
        vote(admin, changeId, 2, 1);
        List<PatchSetApproval> patchSetApprovals = notesFactory.create(project, r.getChange().getId()).getApprovalsWithCopied().values().stream().sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList());
        // There's no verified approval on PS#3.
        assertThat(patchSetApprovals.stream().filter(a -> a.accountId().equals(user.id()) && a.label().equals(TestLabels.verified().getName()) && a.patchSetId().get() == 3).collect(Collectors.toList())).isEmpty();
        // Submit the change. The TestSubmitRule will store a "submit record" containing a label
        // voted by user, but the latest patch-set does not have an approval for this user, hence
        // it will be copied if we request approvals after the change is merged.
        requestScopeOperations.setApiUser(admin.id());
        gApi.changes().id(changeId).current().submit();
        patchSetApprovals = notesFactory.create(project, r.getChange().getId()).getApprovalsWithCopied().values().stream().sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList());
        // Get the copied approval for user on PS3 for the "Verified" label.
        PatchSetApproval verifiedApproval = patchSetApprovals.stream().filter(a -> a.accountId().equals(user.id()) && a.label().equals(TestLabels.verified().getName()) && a.patchSetId().get() == 3).collect(MoreCollectors.onlyElement());
        assertCopied(verifiedApproval, /* psId= */
        3, TestLabels.verified().getName(), (short) 1, /* copied= */
        true);
    }
}
Also used : NO_CHANGE(com.google.gerrit.extensions.client.ChangeKind.NO_CHANGE) Arrays(java.util.Arrays) TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) REWORK(com.google.gerrit.extensions.client.ChangeKind.REWORK) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeKindCreator(com.google.gerrit.acceptance.testsuite.change.ChangeKindCreator) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) LabelType(com.google.gerrit.entities.LabelType) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) EnumSet(java.util.EnumSet) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeOperations(com.google.gerrit.acceptance.testsuite.change.ChangeOperations) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MoreCollectors(com.google.common.collect.MoreCollectors) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) Account(com.google.gerrit.entities.Account) Set(java.util.Set) TestLabels.value(com.google.gerrit.server.project.testing.TestLabels.value) SubmitRecord(com.google.gerrit.entities.SubmitRecord) Collectors(java.util.stream.Collectors) NoHttpd(com.google.gerrit.acceptance.NoHttpd) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) TestProjectUpdate.allowLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RawInputUtil(com.google.gerrit.common.RawInputUtil) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) TestLabels(com.google.gerrit.server.project.testing.TestLabels) CURRENT_COMMIT(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT) ImmutableList(com.google.common.collect.ImmutableList) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) LabelFunction(com.google.gerrit.entities.LabelFunction) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Comparator.comparing(java.util.Comparator.comparing) FileInfo(com.google.gerrit.extensions.common.FileInfo) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) SubmitRule(com.google.gerrit.server.rules.SubmitRule) TestLabels.labelBuilder(com.google.gerrit.server.project.testing.TestLabels.labelBuilder) ChangeKindCacheImpl(com.google.gerrit.server.change.ChangeKindCacheImpl) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) NO_CODE_CHANGE(com.google.gerrit.extensions.client.ChangeKind.NO_CODE_CHANGE) MERGE_FIRST_PARENT_UPDATE(com.google.gerrit.extensions.client.ChangeKind.MERGE_FIRST_PARENT_UPDATE) ObjectId(org.eclipse.jgit.lib.ObjectId) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) TRIVIAL_REBASE(com.google.gerrit.extensions.client.ChangeKind.TRIVIAL_REBASE) ChangeKind(com.google.gerrit.extensions.client.ChangeKind) Named(com.google.inject.name.Named) Cache(com.google.common.cache.Cache) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 65 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class SubmitRequirementIT method submitRecords.

@Test
public void submitRecords() throws Exception {
    PushOneCommit.Result r = createChange();
    TestSubmitRule testSubmitRule = new TestSubmitRule();
    try (Registration registration = extensionRegistry.newRegistration().add(testSubmitRule)) {
        String changeId = r.getChangeId();
        ChangeInfo change = gApi.changes().id(changeId).get();
        assertThat(change.submitRecords).hasSize(2);
        // Check the default submit record for the code-review label
        SubmitRecordInfo codeReviewRecord = Iterables.get(change.submitRecords, 0);
        assertThat(codeReviewRecord.ruleName).isEqualTo("gerrit~DefaultSubmitRule");
        assertThat(codeReviewRecord.status).isEqualTo(SubmitRecordInfo.Status.NOT_READY);
        assertThat(codeReviewRecord.labels).hasSize(1);
        SubmitRecordInfo.Label label = Iterables.getOnlyElement(codeReviewRecord.labels);
        assertThat(label.label).isEqualTo("Code-Review");
        assertThat(label.status).isEqualTo(SubmitRecordInfo.Label.Status.NEED);
        assertThat(label.appliedBy).isNull();
        // Check the custom test record created by the TestSubmitRule
        SubmitRecordInfo testRecord = Iterables.get(change.submitRecords, 1);
        assertThat(testRecord.ruleName).isEqualTo("testSubmitRule");
        assertThat(testRecord.status).isEqualTo(SubmitRecordInfo.Status.OK);
        assertThat(testRecord.requirements).containsExactly(new LegacySubmitRequirementInfo("OK", "fallback text", "type"));
        assertThat(testRecord.labels).hasSize(1);
        SubmitRecordInfo.Label testLabel = Iterables.getOnlyElement(testRecord.labels);
        assertThat(testLabel.label).isEqualTo("label");
        assertThat(testLabel.status).isEqualTo(SubmitRecordInfo.Label.Status.OK);
        assertThat(testLabel.appliedBy).isNull();
        voteLabel(changeId, "Code-Review", 2);
        // Code review record is satisfied after voting +2
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRecords).hasSize(2);
        codeReviewRecord = Iterables.get(change.submitRecords, 0);
        assertThat(codeReviewRecord.ruleName).isEqualTo("gerrit~DefaultSubmitRule");
        assertThat(codeReviewRecord.status).isEqualTo(SubmitRecordInfo.Status.OK);
        assertThat(codeReviewRecord.labels).hasSize(1);
        label = Iterables.getOnlyElement(codeReviewRecord.labels);
        assertThat(label.label).isEqualTo("Code-Review");
        assertThat(label.status).isEqualTo(SubmitRecordInfo.Label.Status.OK);
        assertThat(label.appliedBy._accountId).isEqualTo(admin.id().get());
    }
}
Also used : LegacySubmitRequirementInfo(com.google.gerrit.extensions.common.LegacySubmitRequirementInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) SubmitRecordInfo(com.google.gerrit.extensions.common.SubmitRecordInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)205 Test (org.junit.Test)200 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)194 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)90 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)47 RestResponse (com.google.gerrit.acceptance.RestResponse)39 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)38 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)31 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)23 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)22 TestAccount (com.google.gerrit.acceptance.TestAccount)19 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)19 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)16 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)15 Config (org.eclipse.jgit.lib.Config)14 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)12 CreateProjectArgs (com.google.gerrit.server.project.CreateProjectArgs)11 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 ImmutableList (com.google.common.collect.ImmutableList)10