use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffPatchSetApprovalKeySets.
@Test
public void diffPatchSetApprovalKeySets() throws Exception {
Change c = TestChanges.newChange(project, accountId);
int id = c.getId().get();
PatchSetApproval a1 = new PatchSetApproval(new PatchSetApproval.Key(c.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
PatchSetApproval a2 = new PatchSetApproval(new PatchSetApproval.Key(c.currentPatchSetId(), accountId, new LabelId("Verified")), (short) 1, TimeUtil.nowTs());
ChangeBundle b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), REVIEW_DB);
assertDiffs(b1, b2, "PatchSetApproval.Key sets differ:" + " [" + id + "%2C1,100,Code-Review] only in A;" + " [" + id + "%2C1,100,Verified] only in B");
}
use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.
the class ChangeNotesParser method parseRemoveApproval.
private PatchSetApproval parseRemoveApproval(PatchSet.Id psId, Account.Id committerId, Account.Id realAccountId, Timestamp ts, String line) throws ConfigInvalidException {
// See comments in parseAddApproval about the various users involved.
Account.Id effectiveAccountId;
String label;
int s = line.indexOf(' ');
if (s > 0) {
label = line.substring(1, s);
PersonIdent ident = RawParseUtils.parsePersonIdent(line.substring(s + 1));
checkFooter(ident != null, FOOTER_LABEL, line);
effectiveAccountId = noteUtil.parseIdent(ident, id);
} else {
label = line.substring(1);
effectiveAccountId = committerId;
}
try {
LabelType.checkNameInternal(label);
} catch (IllegalArgumentException e) {
ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_LABEL, line);
pe.initCause(e);
throw pe;
}
// Store an actual 0-vote approval in the map for a removed approval, for
// several reasons:
// - This is closer to the ReviewDb representation, which leads to less
// confusion and special-casing of NoteDb.
// - More importantly, ApprovalCopier needs an actual approval in order to
// block copying an earlier approval over a later delete.
PatchSetApproval remove = new PatchSetApproval(new PatchSetApproval.Key(psId, effectiveAccountId, new LabelId(label)), (short) 0, ts);
if (!Objects.equals(realAccountId, committerId)) {
remove.setRealAccountId(realAccountId);
}
ApprovalKey k = ApprovalKey.create(psId, effectiveAccountId, label);
if (!approvals.containsKey(k)) {
approvals.put(k, remove);
}
return remove;
}
use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffPatchSetApprovalsMixedSourcesAllowsSlop.
@Test
public void diffPatchSetApprovalsMixedSourcesAllowsSlop() throws Exception {
Change c = TestChanges.newChange(project, accountId);
subWindowResolution();
PatchSetApproval a1 = new PatchSetApproval(new PatchSetApproval.Key(c.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, roundToSecond(TimeUtil.nowTs()));
PatchSetApproval a2 = clone(a1);
a2.setGranted(TimeUtil.nowTs());
// Both are ReviewDb, exact timestamp match is required.
ChangeBundle b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), REVIEW_DB);
assertDiffs(b1, b2, "granted differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review:" + " {2009-09-30 17:00:07.0} != {2009-09-30 17:00:08.0}");
// One NoteDb, slop is allowed.
b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), NOTE_DB);
b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), REVIEW_DB);
assertNoDiffs(b1, b2);
// But not too much slop.
superWindowResolution();
PatchSetApproval a3 = clone(a1);
a3.setGranted(TimeUtil.nowTs());
b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), NOTE_DB);
ChangeBundle b3 = new ChangeBundle(c, messages(), latest(c), approvals(a3), comments(), reviewers(), REVIEW_DB);
String msg = "granted differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review in NoteDb vs. ReviewDb:" + " {2009-09-30 17:00:07.0} != {2009-09-30 17:00:15.0}";
assertDiffs(b1, b3, msg);
assertDiffs(b3, b1, msg);
}
use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffChangesTakesMaxEntityTimestampFromReviewDb.
@Test
public void diffChangesTakesMaxEntityTimestampFromReviewDb() throws Exception {
Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
PatchSet ps = new PatchSet(c1.currentPatchSetId());
ps.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
ps.setUploader(accountId);
ps.setCreatedOn(TimeUtil.nowTs());
PatchSetApproval a = new PatchSetApproval(new PatchSetApproval.Key(c1.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
Change c2 = clone(c1);
c2.setLastUpdatedOn(a.getGranted());
// Both ReviewDb, exact match required.
ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
assertDiffs(b1, b2, "effective last updated time differs for Change.Id " + c1.getId() + ":" + " {2009-09-30 17:00:00.0} != {2009-09-30 17:00:12.0}");
// NoteDb allows latest timestamp from all entities in bundle.
b2 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), NOTE_DB);
assertNoDiffs(b1, b2);
}
use of com.google.gerrit.reviewdb.client.LabelId in project gerrit by GerritCodeReview.
the class ChangeIT method addReviewerWithNoteDbWhenDummyApprovalInReviewDbExists.
@Test
public void addReviewerWithNoteDbWhenDummyApprovalInReviewDbExists() throws Exception {
assume().that(notesMigration.enabled()).isTrue();
assume().that(notesMigration.changePrimaryStorage()).isEqualTo(PrimaryStorage.REVIEW_DB);
PushOneCommit.Result r = createChange();
// insert dummy approval in ReviewDb
PatchSetApproval psa = new PatchSetApproval(new PatchSetApproval.Key(r.getPatchSetId(), user.id, new LabelId("Code-Review")), (short) 0, TimeUtil.nowTs());
db.patchSetApprovals().insert(Collections.singleton(psa));
AddReviewerInput in = new AddReviewerInput();
in.reviewer = user.email;
gApi.changes().id(r.getChangeId()).addReviewer(in);
}
Aggregations