diff options
author | Diego Zambelli Sessona <diego.sessona@gmail.com> | 2024-03-21 19:23:05 +0100 |
---|---|---|
committer | Diego Zambelli Sessona <diego.sessona@gmail.com> | 2024-03-29 09:07:06 +0000 |
commit | 1d7803586a74ab9688b32d64f9df15527fafbfde (patch) | |
tree | 1240db1ed5eb723cc02d515c29f6d4ad3e69f6f5 | |
parent | 6595c543d1ff49e84b6125413e6c95130b85d589 (diff) |
Add test paginationType NONE to query only if there are more results
If the first query to the index did not fill the full limit the caller
wants, we paginate to obtain more results. However, subsequent queries
are not needed if there are no more results from the previous query.
This add a test for the change 413358 [1], that has reintroduced the
issue fixed in change 344695.
[1]: https://gerrit-review.googlesource.com/c/gerrit/+/413358/comment/85bca522_2b3552b2/
Bug: Issue 330195358
Release-Notes: skip
Change-Id: If578ee877587488fdf3715331bd8d23e9d86f750
-rw-r--r-- | javatests/com/google/gerrit/server/query/change/FakeQueryChangesTest.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/javatests/com/google/gerrit/server/query/change/FakeQueryChangesTest.java b/javatests/com/google/gerrit/server/query/change/FakeQueryChangesTest.java index af14683e8b..2f5ae17e31 100644 --- a/javatests/com/google/gerrit/server/query/change/FakeQueryChangesTest.java +++ b/javatests/com/google/gerrit/server/query/change/FakeQueryChangesTest.java @@ -22,8 +22,11 @@ import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS import static org.junit.Assume.assumeFalse; import com.google.gerrit.acceptance.UseClockStep; +import com.google.gerrit.entities.Account; +import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Permission; import com.google.gerrit.entities.Project; +import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.index.PaginationType; import com.google.gerrit.index.testing.AbstractFakeIndex; import com.google.gerrit.server.config.AllProjectsName; @@ -34,6 +37,7 @@ import com.google.gerrit.testing.InMemoryRepositoryManager.Repo; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; +import java.util.List; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.Config; import org.junit.Test; @@ -84,6 +88,41 @@ public abstract class FakeQueryChangesTest extends AbstractQueryChangesTest { @Test @UseClockStep @SuppressWarnings("unchecked") + public void queryRightNumberOfTimes() throws Exception { + TestRepository<Repo> repo = createProject("repo"); + Account.Id user2 = + accountManager.authenticate(authRequestFactory.createForUser("anotheruser")).getAccountId(); + + // create 1 visible change + Change visibleChange1 = insert(repo, newChangeWithStatus(repo, Change.Status.NEW)); + + // create 4 private changes + Change invisibleChange2 = insert(repo, newChangeWithStatus(repo, Change.Status.NEW), user2); + Change invisibleChange3 = insert(repo, newChangeWithStatus(repo, Change.Status.NEW), user2); + Change invisibleChange4 = insert(repo, newChangeWithStatus(repo, Change.Status.NEW), user2); + Change invisibleChange5 = insert(repo, newChangeWithStatus(repo, Change.Status.NEW), user2); + gApi.changes().id(invisibleChange2.getChangeId()).setPrivate(true, null); + gApi.changes().id(invisibleChange3.getChangeId()).setPrivate(true, null); + gApi.changes().id(invisibleChange4.getChangeId()).setPrivate(true, null); + gApi.changes().id(invisibleChange5.getChangeId()).setPrivate(true, null); + + AbstractFakeIndex idx = (AbstractFakeIndex) changeIndexCollection.getSearchIndex(); + int queriesBeforeExecution = idx.getQueryCount(); + List<ChangeInfo> queryResult = newQuery("status:new").withLimit(2).get(); + assertThat(queryResult).hasSize(1); + assertThat(queryResult.get(0).changeId).isEqualTo(visibleChange1.getKey().get()); + + // Since the limit of the query (i.e. 2), 2 index searches are expected in fact: + // 1: The first query will return invisibleChange5, invisibleChange4 and invisibleChange3, + // 2: Another query is needed to back-fill the limit requested by the user. + // even if one result in the second query is skipped because it is not visible, + // there are no more results to query. + assertThat(idx.getQueryCount() - queriesBeforeExecution).isEqualTo(2); + } + + @Test + @UseClockStep + @SuppressWarnings("unchecked") public void noLimitQueryPaginates() throws Exception { assumeFalse(PaginationType.NONE == getCurrentPaginationType()); TestRepository<InMemoryRepositoryManager.Repo> testRepo = createProject("repo"); |