Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void test01_Backups() throws InterruptedException, ExecutionException, Ti
backup));

// Test pagination.
testPagination();
testPagination(database);
logger.info("Finished listBackup tests");

// Execute other tests as part of this integration test to reduce total execution time.
Expand Down Expand Up @@ -705,20 +705,21 @@ private void testUpdateBackup(Backup backup) {
assertEquals(tomorrow, backup.getExpireTime());
}

private void testPagination() {
private void testPagination(Database database) {
logger.info("Listing backups using pagination");
Options.ListOption filter =
Options.filter(String.format("database:%s", database.getId().getName()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The DatabaseId class does not have a getName() method. Calling database.getId().getName() will result in a compilation error. It should be replaced with database.getId().getDatabase() to correctly retrieve the database name.

Suggested change
Options.filter(String.format("database:%s", database.getId().getName()));
Options.filter(String.format("database:%s", database.getId().getDatabase()));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double-checked this, and DatabaseId actually does have a getName() method. It retrieves the fully-qualified Spanner resource name (projects/%s/instances/%s/databases/%s), whereas getDatabase() only returns the short string ID.

Since the Options.filter("database:" + ...) API natively accepts the fully-qualified resource name, database.getId().getName() works perfectly here


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

int numBackups = 0;
logger.info("Fetching first page");
Page<Backup> page = dbAdminClient.listBackups(instanceId, Options.pageSize(1));
Page<Backup> page = dbAdminClient.listBackups(instanceId, filter, Options.pageSize(1));
assertEquals(1, Iterables.size(page.getValues()));
numBackups++;
assertFalse(page.hasNextPage());
Set<String> seenPageTokens = new HashSet<>();
seenPageTokens.add("");
while (page.hasNextPage()) {
Expand All @@ -745,11 +746,11 @@ private void testPagination() {
seenPageTokens.add(page.getNextPageToken());
page =
dbAdminClient.listBackups(
instanceId, Options.pageToken(page.getNextPageToken()), Options.pageSize(1));
instanceId, filter, Options.pageToken(page.getNextPageToken()), Options.pageSize(1));
assertEquals(1, Iterables.size(page.getValues()));
numBackups++;
}
assertTrue(numBackups >= 1);
assertEquals(initialBackups.size(), numBackups);
}

private void testRestore(Backup backup, Timestamp versionTime, String expectedKey)
Expand Down
Loading