use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffChangesIgnoresChangeTimestampIfAnyOtherEntitiesExist.
@Test
public void diffChangesIgnoresChangeTimestampIfAnyOtherEntitiesExist() {
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());
c1.setLastUpdatedOn(a.getGranted());
Change c2 = clone(c1);
c2.setLastUpdatedOn(TimeUtil.nowTs());
// ReviewDb has later lastUpdatedOn timestamp than NoteDb, allowed since
// NoteDb matches the latest timestamp of a non-Change entity.
ChangeBundle b1 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c1, messages(), patchSets(ps), approvals(a), comments(), reviewers(), NOTE_DB);
assertThat(b1.getChange().getLastUpdatedOn()).isGreaterThan(b2.getChange().getLastUpdatedOn());
assertNoDiffs(b1, b2);
// Timestamps must actually match if Change is the only entity.
b1 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
b2 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
assertDiffs(b1, b2, "effective last updated time differs for Change.Id " + c1.getId() + " in NoteDb vs. ReviewDb:" + " {2009-09-30 17:00:12.0} != {2009-09-30 17:00:18.0}");
}
use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffPatchSetsIgnoresCreatedOnWhenReviewDbIsNonMonotonic.
@Test
public void diffPatchSetsIgnoresCreatedOnWhenReviewDbIsNonMonotonic() throws Exception {
Change c = TestChanges.newChange(project, accountId);
Timestamp beforePs1 = TimeUtil.nowTs();
PatchSet goodPs1 = new PatchSet(new PatchSet.Id(c.getId(), 1));
goodPs1.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
goodPs1.setUploader(accountId);
goodPs1.setCreatedOn(TimeUtil.nowTs());
PatchSet goodPs2 = new PatchSet(new PatchSet.Id(c.getId(), 2));
goodPs2.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
goodPs2.setUploader(accountId);
goodPs2.setCreatedOn(TimeUtil.nowTs());
assertThat(goodPs2.getCreatedOn()).isGreaterThan(goodPs1.getCreatedOn());
PatchSet badPs2 = clone(goodPs2);
badPs2.setCreatedOn(beforePs1);
assertThat(badPs2.getCreatedOn()).isLessThan(goodPs1.getCreatedOn());
// Both ReviewDb, exact match required.
ChangeBundle b1 = new ChangeBundle(c, messages(), patchSets(goodPs1, goodPs2), approvals(), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c, messages(), patchSets(goodPs1, badPs2), approvals(), comments(), reviewers(), REVIEW_DB);
assertDiffs(b1, b2, "createdOn differs for PatchSet.Id " + badPs2.getId() + ":" + " {2009-09-30 17:00:18.0} != {2009-09-30 17:00:06.0}");
// Non-monotonic in ReviewDb but monotonic in NoteDb, timestamps are
// ignored, including for ps1.
PatchSet badPs1 = clone(goodPs1);
badPs1.setCreatedOn(TimeUtil.nowTs());
b1 = new ChangeBundle(c, messages(), patchSets(badPs1, badPs2), approvals(), comments(), reviewers(), REVIEW_DB);
b2 = new ChangeBundle(c, messages(), patchSets(goodPs1, goodPs2), approvals(), comments(), reviewers(), NOTE_DB);
assertNoDiffs(b1, b2);
assertNoDiffs(b2, b1);
// Non-monotonic in NoteDb but monotonic in ReviewDb, timestamps are not
// ignored.
b1 = new ChangeBundle(c, messages(), patchSets(goodPs1, goodPs2), approvals(), comments(), reviewers(), REVIEW_DB);
b2 = new ChangeBundle(c, messages(), patchSets(badPs1, badPs2), approvals(), comments(), reviewers(), NOTE_DB);
assertDiffs(b1, b2, "createdOn differs for PatchSet.Id " + badPs1.getId() + " in NoteDb vs. ReviewDb:" + " {2009-09-30 17:00:24.0} != {2009-09-30 17:00:12.0}", "createdOn differs for PatchSet.Id " + badPs2.getId() + " in NoteDb vs. ReviewDb:" + " {2009-09-30 17:00:06.0} != {2009-09-30 17:00:18.0}");
}
use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffPatchSetsIgnoresTrailingNewlinesInPushCertificate.
@Test
public void diffPatchSetsIgnoresTrailingNewlinesInPushCertificate() throws Exception {
subWindowResolution();
Change c = TestChanges.newChange(project, accountId);
PatchSet ps1 = new PatchSet(c.currentPatchSetId());
ps1.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
ps1.setUploader(accountId);
ps1.setCreatedOn(roundToSecond(TimeUtil.nowTs()));
ps1.setPushCertificate("some cert");
PatchSet ps2 = clone(ps1);
ps2.setPushCertificate(ps2.getPushCertificate() + "\n\n");
ChangeBundle b1 = new ChangeBundle(c, messages(), patchSets(ps1), approvals(), comments(), reviewers(), NOTE_DB);
ChangeBundle b2 = new ChangeBundle(c, messages(), patchSets(ps2), approvals(), comments(), reviewers(), REVIEW_DB);
assertNoDiffs(b1, b2);
assertNoDiffs(b2, b1);
b1 = new ChangeBundle(c, messages(), patchSets(ps1), approvals(), comments(), reviewers(), REVIEW_DB);
b2 = new ChangeBundle(c, messages(), patchSets(ps2), approvals(), comments(), reviewers(), NOTE_DB);
assertNoDiffs(b1, b2);
assertNoDiffs(b2, b1);
}
use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class PatchSetUtil method insert.
public PatchSet insert(ReviewDb db, RevWalk rw, ChangeUpdate update, PatchSet.Id psId, ObjectId commit, boolean draft, List<String> groups, String pushCertificate, String description) throws OrmException, IOException {
checkNotNull(groups, "groups may not be null");
ensurePatchSetMatches(psId, update);
PatchSet ps = new PatchSet(psId);
ps.setRevision(new RevId(commit.name()));
ps.setUploader(update.getAccountId());
ps.setCreatedOn(new Timestamp(update.getWhen().getTime()));
ps.setDraft(draft);
ps.setGroups(groups);
ps.setPushCertificate(pushCertificate);
ps.setDescription(description);
db.patchSets().insert(Collections.singleton(ps));
update.setCommit(rw, commit, pushCertificate);
update.setPsDescription(description);
update.setGroups(groups);
if (draft) {
update.setPatchSetState(DRAFT);
}
return ps;
}
use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class ChangeNotesTest method patchLineCommentNotesFormatMultiplePatchSetsSameRevId.
@Test
public void patchLineCommentNotesFormatMultiplePatchSetsSameRevId() throws Exception {
Change c = newChange();
PatchSet.Id psId1 = c.currentPatchSetId();
incrementPatchSet(c);
PatchSet.Id psId2 = c.currentPatchSetId();
String uuid1 = "uuid1";
String uuid2 = "uuid2";
String uuid3 = "uuid3";
String message1 = "comment 1";
String message2 = "comment 2";
String message3 = "comment 3";
CommentRange range1 = new CommentRange(1, 1, 2, 1);
CommentRange range2 = new CommentRange(2, 1, 3, 1);
Timestamp time = TimeUtil.nowTs();
RevId revId = new RevId("abcd1234abcd1234abcd1234abcd1234abcd1234");
Comment comment1 = newComment(psId1, "file1", uuid1, range1, range1.getEndLine(), otherUser, null, time, message1, (short) 0, revId.get(), false);
Comment comment2 = newComment(psId1, "file1", uuid2, range2, range2.getEndLine(), otherUser, null, time, message2, (short) 0, revId.get(), false);
Comment comment3 = newComment(psId2, "file1", uuid3, range1, range1.getEndLine(), otherUser, null, time, message3, (short) 0, revId.get(), false);
ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(psId2);
update.putComment(Status.PUBLISHED, comment3);
update.putComment(Status.PUBLISHED, comment2);
update.putComment(Status.PUBLISHED, comment1);
update.commit();
ChangeNotes notes = newNotes(c);
try (RevWalk walk = new RevWalk(repo)) {
ArrayList<Note> notesInTree = Lists.newArrayList(notes.revisionNoteMap.noteMap.iterator());
Note note = Iterables.getOnlyElement(notesInTree);
byte[] bytes = walk.getObjectReader().open(note.getData(), Constants.OBJ_BLOB).getBytes();
String noteString = new String(bytes, UTF_8);
String timeStr = ChangeNoteUtil.formatTime(serverIdent, time);
if (!testJson()) {
assertThat(noteString).isEqualTo("Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n" + "Base-for-patch-set: 1\n" + "File: file1\n" + "\n" + "1:1-2:1\n" + timeStr + "\n" + "Author: Other Account <2@gerrit>\n" + "Unresolved: false\n" + "UUID: uuid1\n" + "Bytes: 9\n" + "comment 1\n" + "\n" + "2:1-3:1\n" + timeStr + "\n" + "Author: Other Account <2@gerrit>\n" + "Unresolved: false\n" + "UUID: uuid2\n" + "Bytes: 9\n" + "comment 2\n" + "\n" + "Base-for-patch-set: 2\n" + "File: file1\n" + "\n" + "1:1-2:1\n" + timeStr + "\n" + "Author: Other Account <2@gerrit>\n" + "Unresolved: false\n" + "UUID: uuid3\n" + "Bytes: 9\n" + "comment 3\n" + "\n");
}
}
assertThat(notes.getComments()).isEqualTo(ImmutableListMultimap.of(revId, comment1, revId, comment2, revId, comment3));
}
Aggregations