Skip to content

Commit 1a263f2

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 1a263f2

1 file changed

Lines changed: 8 additions & 7 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: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public void test01_Backups() throws InterruptedException, ExecutionException, Ti
358358
backup));
359359

360360
// Test pagination.
361-
testPagination();
361+
testPagination(database);
362362
logger.info("Finished listBackup tests");
363363

364364
// Execute other tests as part of this integration test to reduce total execution time.
@@ -705,20 +705,21 @@ 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");
710+
Options.ListOption filter =
711+
Options.filter(String.format("database:%s", database.getId().getName()));
710712

711713
// First get all current backups without using pagination so we can compare that list with
712714
// the same list when pagination fails.
713715
List<Backup> initialBackups =
714-
Lists.newArrayList(dbAdminClient.listBackups(instanceId).iterateAll());
716+
Lists.newArrayList(dbAdminClient.listBackups(instanceId, filter).iterateAll());
715717

716718
int numBackups = 0;
717719
logger.info("Fetching first page");
718-
Page<Backup> page = dbAdminClient.listBackups(instanceId, Options.pageSize(1));
720+
Page<Backup> page = dbAdminClient.listBackups(instanceId, filter, Options.pageSize(1));
719721
assertEquals(1, Iterables.size(page.getValues()));
720722
numBackups++;
721-
assertFalse(page.hasNextPage());
722723
Set<String> seenPageTokens = new HashSet<>();
723724
seenPageTokens.add("");
724725
while (page.hasNextPage()) {
@@ -745,11 +746,11 @@ private void testPagination() {
745746
seenPageTokens.add(page.getNextPageToken());
746747
page =
747748
dbAdminClient.listBackups(
748-
instanceId, Options.pageToken(page.getNextPageToken()), Options.pageSize(1));
749+
instanceId, filter, Options.pageToken(page.getNextPageToken()), Options.pageSize(1));
749750
assertEquals(1, Iterables.size(page.getValues()));
750751
numBackups++;
751752
}
752-
assertTrue(numBackups >= 1);
753+
assertEquals(initialBackups.size(), numBackups);
753754
}
754755

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

0 commit comments

Comments
 (0)