use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class GroupsIT method disabledReindexGroupsOnStartupSlaveMode.
@Test
@Sandboxed
@GerritConfig(name = "index.scheduledIndexer.runOnStartup", value = "false")
@GerritConfig(name = "index.scheduledIndexer.enabled", value = "false")
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
@IgnoreGroupInconsistencies
public void disabledReindexGroupsOnStartupSlaveMode() throws Exception {
List<AccountGroup.UUID> expectedGroups = groups.getAllGroupReferences().map(GroupReference::getUUID).collect(toList());
assertThat(expectedGroups.size()).isAtLeast(2);
restartAsSlave();
GroupIndexedCounter groupIndexedCounter = new GroupIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(groupIndexedCounter)) {
// No group indexing happened on startup. All groups should be reindexed now.
slaveGroupIndexer.run();
groupIndexedCounter.assertReindexOf(expectedGroups);
}
}
use of com.google.gerrit.acceptance.config.GerritConfig 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.config.GerritConfig in project gerrit by GerritCodeReview.
the class GroupsIT method createGroupWithDefaultNameOfSystemGroup_Conflict.
@Test
@GerritConfig(name = "groups.global:Anonymous-Users.name", value = "All Users")
public void createGroupWithDefaultNameOfSystemGroup_Conflict() throws Exception {
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.groups().create("anonymous users"));
assertThat(thrown).hasMessageThat().contains("group name 'Anonymous Users' is reserved");
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class SubmitWithStickyApprovalDiffIT method postSubmitDiffCannotBeTooBigWithLargeComments.
@Test
@GerritConfig(name = "change.cumulativeCommentSizeLimit", value = "10k")
public void postSubmitDiffCannotBeTooBigWithLargeComments() throws Exception {
Change.Id changeId = changeOperations.newChange().project(project).file("file").content("content").create();
gApi.changes().id(changeId.get()).current().review(ReviewInput.approve());
// unrelated comment taking up most of the space, making post submit diff shorter.
String message = new String(new char[9700]).replace("\0", "a");
ReviewInput reviewInput = new ReviewInput().message(message);
CommentInput commentInput = new CommentInput();
commentInput.line = 1;
commentInput.path = "file";
reviewInput.comments = ImmutableMap.of("file", ImmutableList.of(commentInput));
gApi.changes().id(changeId.get()).current().review(reviewInput);
String content = new String(new char[500]).replace("\0", "a");
changeOperations.change(changeId).newPatchset().file("file").content(content).create();
// Post submit diff is over the cumulativeCommentSizeLimit, since the comment took most of
// the space (even though the post submit diff is not limited).
gApi.changes().id(changeId.get()).current().submit();
assertThat(Iterables.getLast(gApi.changes().id(changeId.get()).messages()).message).isEqualTo("Change has been successfully merged\n\n1 is the latest approved patch-set.\nThe " + "change was submitted with unreviewed changes in the following " + "files:\n\n```\nThe name of the file: file\nInsertions: 1, Deletions: 1.\n\nThe" + " diff is too large to show. Please review the diff.\n```\n");
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class MailProcessorIT method limitNumberOfComments.
@Test
@GerritConfig(name = "change.maxComments", value = "9")
public void limitNumberOfComments() throws Exception {
// This change has 2 change messages and 2 comments.
String changeId = createChangeWithReview();
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
CommentInput commentInput = new CommentInput();
commentInput.line = 1;
commentInput.message = "foo";
commentInput.path = FILE_NAME;
RobotCommentInput robotCommentInput = TestCommentHelper.createRobotCommentInputWithMandatoryFields(FILE_NAME);
ReviewInput reviewInput = new ReviewInput();
reviewInput.comments = ImmutableMap.of(FILE_NAME, ImmutableList.of(commentInput));
reviewInput.robotComments = ImmutableMap.of(FILE_NAME, ImmutableList.of(robotCommentInput));
// Add 1 change message and another 2 comments. Total count is now 7, which is still OK.
gApi.changes().id(changeId).current().review(reviewInput);
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
MailMessage.Builder mailMessage = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", "1) change message", "2) reply to comment", "3) file comment");
mailMessage.textContent(txt + textFooterForChange(changeInfo._number, ts));
ImmutableSet<CommentInfo> commentsBefore = getCommentsAndRobotComments(changeId);
// Should have 4 comments (and 3 change messages).
assertThat(commentsBefore).hasSize(4);
// The email adds 3 new comments (of which 1 is the change message).
mailProcessor.process(mailMessage.build());
ImmutableSet<CommentInfo> commentsAfter = getCommentsAndRobotComments(changeId);
assertThat(commentsAfter).isEqualTo(commentsBefore);
assertNotifyTo(user);
Message message = sender.nextMessage();
assertThat(message.body()).contains("rejected one or more comments");
}
Aggregations