Support empty ChangeUpdates

To create a change in the notedb and ensure the meta ref exists, we
need a root commit, but thus far we don't have anything else to put in
the root commit, so it is effectively empty. Ensure this code path
works.

Change-Id: I3e5496c7019f083401ef24e430e2b9f89c9936b4
This commit is contained in:
Dave Borowitz
2014-07-25 11:37:35 -07:00
parent 5236477f04
commit 8925f3e287
2 changed files with 20 additions and 3 deletions

View File

@@ -473,12 +473,13 @@ public class ChangeUpdate extends AbstractChangeUpdate {
private boolean isEmpty() { private boolean isEmpty() {
return approvals.isEmpty() return approvals.isEmpty()
&& reviewers.isEmpty() && changeMessage == null
&& commentsForBase.isEmpty() && commentsForBase.isEmpty()
&& commentsForPs.isEmpty() && commentsForPs.isEmpty()
&& reviewers.isEmpty()
&& status == null && status == null
&& submitRecords == null && subject == null
&& changeMessage == null; && submitRecords == null;
} }
private static StringBuilder addFooter(StringBuilder sb, FooterKey footer) { private static StringBuilder addFooter(StringBuilder sb, FooterKey footer) {

View File

@@ -22,6 +22,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@@ -618,6 +620,20 @@ public class ChangeNotesTest {
Iterables.getOnlyElement(notes.getSubmitRecords())); Iterables.getOnlyElement(notes.getSubmitRecords()));
} }
@Test
public void emptyChangeUpdate() throws Exception {
ChangeUpdate update = newUpdate(newChange(), changeOwner);
update.commit();
assertNull(update.getRevision());
}
public void emptyExceptSubject() throws Exception {
ChangeUpdate update = newUpdate(newChange(), changeOwner);
update.setSubject("Create change");
update.commit();
assertNotNull(update.getRevision());
}
@Test @Test
public void multipleUpdatesInBatch() throws Exception { public void multipleUpdatesInBatch() throws Exception {
Change c = newChange(); Change c = newChange();