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);
}
}
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);
}
}
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);
}
}
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);
}
}
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());
}
}
Aggregations