ChangeBundle: Handle empty topic on the ReviewDb side

In the ReviewDb storage layer there is a distinction between a null
topic field and an empty value. However, for the purposes of the REST
API and index, these are the same. Because of this, in NoteDb we
decided to let "Topic: " indicate that the topic field should be
cleared, i.e. set to null, and there is no separate way to set to the
empty string.

Support this slight difference in ChangeBundle, allowing a null topic
on the NoteDb side if the ReviewDb side is empty.

Change-Id: I1b23cb8c3be030f9c2405bd03dadfc5dbea2a28c
This commit is contained in:
Dave Borowitz
2016-04-28 13:56:24 -04:00
parent 713d2b2c36
commit 1784a2e96d
3 changed files with 78 additions and 6 deletions

View File

@@ -226,6 +226,52 @@ public class ChangeBundleTest {
+ " {null} != {Original subject}");
}
@Test
public void diffChangesConsidersEmptyReviewDbTopicEquivalentToNullInNoteDb()
throws Exception {
Change c1 = TestChanges.newChange(
new Project.NameKey("project"), new Account.Id(100));
c1.setTopic("");
Change c2 = clone(c1);
c2.setTopic(null);
// Both ReviewDb, exact match required.
ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(),
comments(), REVIEW_DB);
ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(),
comments(), REVIEW_DB);
assertDiffs(b1, b2,
"topic differs for Change.Id " + c1.getId() + ":"
+ " {} != {null}");
// Topic ignored if ReviewDb is empty and NoteDb is null.
b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(),
REVIEW_DB);
b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(),
NOTE_DB);
assertNoDiffs(b1, b2);
// Exact match still required if NoteDb has empty value (not realistic).
b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(),
NOTE_DB);
b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(),
REVIEW_DB);
assertDiffs(b1, b2,
"topic differs for Change.Id " + c1.getId() + ":"
+ " {} != {null}");
// Null is not equal to a non-empty string.
Change c3 = clone(c1);
c3.setTopic("topic");
b1 = new ChangeBundle(c3, messages(), patchSets(), approvals(), comments(),
REVIEW_DB);
b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(),
NOTE_DB);
assertDiffs(b1, b2,
"topic differs for Change.Id " + c1.getId() + ":"
+ " {topic} != {null}");
}
@Test
public void diffChangeMessageKeySets() throws Exception {
Change c = TestChanges.newChange(project, accountId);