Skip to content

Commit 0194748

Browse files
test(spanner): restrict pagination test to explicitly created database
The `ITBackupTest.testPagination` method previously listed all backups on the instance and asserted that only a single page of results would be returned (`assertFalse(page.hasNextPage())`). When running on shared integration test instances (`spanner.testenv.instance`), this assertion would fail if backups from other test runs were present on the instance. This commit updates the pagination API calls to use `Options.filter("database:" + databaseId)`, ensuring that the test only paginates over the backups associated with the uniquely generated database for the active test run. This prevents the test from failing due to unrelated backups in the shared test environment.
1 parent 96a7e6f commit 0194748

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

  • java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/slow

java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/slow/ITBackupTest.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -705,17 +705,26 @@ private void testUpdateBackup(Backup backup) {
705705
assertEquals(tomorrow, backup.getExpireTime());
706706
}
707707

708-
private void testPagination() {
708+
private void testPagination(Database database) {
709709
logger.info("Listing backups using pagination");
710710

711711
// First get all current backups without using pagination so we can compare that list with
712712
// the same list when pagination fails.
713713
List<Backup> initialBackups =
714-
Lists.newArrayList(dbAdminClient.listBackups(instanceId).iterateAll());
714+
Lists.newArrayList(
715+
dbAdminClient
716+
.listBackups(
717+
instanceId,
718+
Options.filter(String.format("database:%s", database.getId().getName())))
719+
.iterateAll());
715720

716721
int numBackups = 0;
717722
logger.info("Fetching first page");
718-
Page<Backup> page = dbAdminClient.listBackups(instanceId, Options.pageSize(1));
723+
Page<Backup> page =
724+
dbAdminClient.listBackups(
725+
instanceId,
726+
Options.filter(String.format("database:%s", database.getId().getName())),
727+
Options.pageSize(1));
719728
assertEquals(1, Iterables.size(page.getValues()));
720729
numBackups++;
721730
assertFalse(page.hasNextPage());
@@ -745,11 +754,14 @@ private void testPagination() {
745754
seenPageTokens.add(page.getNextPageToken());
746755
page =
747756
dbAdminClient.listBackups(
748-
instanceId, Options.pageToken(page.getNextPageToken()), Options.pageSize(1));
757+
instanceId,
758+
Options.filter(String.format("database:%s", database.getId().getName())),
759+
Options.pageToken(page.getNextPageToken()),
760+
Options.pageSize(1));
749761
assertEquals(1, Iterables.size(page.getValues()));
750762
numBackups++;
751763
}
752-
assertTrue(numBackups >= 1);
764+
assertEquals(initialBackups.size(), numBackups);
753765
}
754766

755767
private void testRestore(Backup backup, Timestamp versionTime, String expectedKey)

0 commit comments

Comments
 (0)