NoteDbOnlyIT: Add test for ChangeNotes.Factory#create(Checked)

Despite the different names, these are both supposed to throw
NoSuchChangeException when a change doesn't exist in NoteDb. To be
honest, upon reading this code again I don't see why we have two
different codepaths, but in a stable branch I'm more interested in
documenting the existing behavior than understanding and untangling it.

Change-Id: I9bffe1c005ab8bcc85f47e648ace2672145c30af
This commit is contained in:
Dave Borowitz 2017-12-22 08:50:25 -05:00
parent 09a9cd607e
commit 05c99c5d83

View File

@ -29,6 +29,7 @@ import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdateListener;
import com.google.gerrit.server.update.BatchUpdateOp;
@ -41,6 +42,7 @@ import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
import org.eclipse.jgit.lib.CommitBuilder;
@ -193,6 +195,22 @@ public class NoteDbOnlyIT extends AbstractDaemonTest {
}
}
@Test
public void missingChange() throws Exception {
Change.Id changeId = new Change.Id(1234567);
assertNoSuchChangeException(() -> notesFactory.create(db, project, changeId));
assertNoSuchChangeException(() -> notesFactory.createChecked(db, project, changeId));
}
private void assertNoSuchChangeException(Callable<?> callable) throws Exception {
try {
callable.call();
assert_().fail("expected NoSuchChangeException");
} catch (NoSuchChangeException e) {
// Expected.
}
}
private class ConcurrentWritingListener implements BatchUpdateListener {
static final String MSG_PREFIX = "Other writer ";