Skip to content

Commit 23e0d9e

Browse files
committed
changes as per comments
1 parent e6d042b commit 23e0d9e

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

samples/snippets/src/main/java/com/example/spanner/CopyBackupSample.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,6 @@
3434
import java.util.concurrent.TimeUnit;
3535

3636
public class CopyBackupSample {
37-
public static void main(String[] args) {
38-
if (args.length != 4) {
39-
throw new IllegalArgumentException(
40-
"Invalid number of arguments. "
41-
+ "Usage: CopyBackupSample "
42-
+ "<project-id> <instance-id> <source-backup-id> <destination-backup-id>");
43-
}
44-
String projectId = args[0];
45-
String instanceId = args[1];
46-
String sourceBackupId = args[2];
47-
String destinationBackupId = args[3];
48-
49-
try (Spanner spanner =
50-
SpannerOptions.newBuilder().setProjectId(projectId).build().getService()) {
51-
DatabaseAdminClient databaseAdminClient = spanner.getDatabaseAdminClient();
52-
copyBackup(databaseAdminClient, projectId, instanceId, sourceBackupId, destinationBackupId);
53-
}
54-
}
55-
5637
static void copyBackup() {
5738
// TODO(developer): Replace these variables before running the sample.
5839
String projectId = "my-project";
@@ -87,12 +68,12 @@ static void copyBackup(
8768

8869
// Initiate the request which returns an OperationFuture.
8970
System.out.println("Copying backup [" + destinationBackup.getId() + "]...");
90-
OperationFuture<Backup, CopyBackupMetadata> op =
71+
OperationFuture<Backup, CopyBackupMetadata> operation =
9172
databaseAdminClient.copyBackup(
9273
BackupId.of(projectId, instanceId, sourceBackupId), destinationBackup);
9374
try {
9475
// Wait for the backup operation to complete.
95-
destinationBackup = op.get();
76+
destinationBackup = operation.get();
9677
System.out.println("Copied backup [" + destinationBackup.getId() + "]");
9778
} catch (ExecutionException e) {
9879
throw (SpannerException) e.getCause();
@@ -114,7 +95,7 @@ static void copyBackup(
11495
destinationBackup.getProto().getVersionTime().getSeconds(),
11596
destinationBackup.getProto().getVersionTime().getNanos(),
11697
OffsetDateTime.now().getOffset())));
117-
return null;
98+
return;
11899
}
119100
}
120101
// [END spanner_copy_backup]

samples/snippets/src/main/java/com/example/spanner/SpannerSample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public class SpannerSample {
9595

9696
/** Class to contain singer sample data. */
9797
static class Singer {
98-
9998
final long singerId;
10099
final String firstName;
101100
final String lastName;

samples/snippets/src/test/java/com/example/spanner/SpannerSampleIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.example.spanner;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20+
import static org.junit.Assert.assertTrue;
2021

2122
import com.google.cloud.Timestamp;
2223
import com.google.cloud.spanner.Backup;
@@ -328,9 +329,8 @@ public void testSample() throws Exception {
328329
"Backup %s on database %s pending:",
329330
backupId.getName(),
330331
dbId.getName()));
331-
assertThat(out).contains(
332-
"Copy Backup Operations"
333-
);
332+
assertTrue("Out does not contain copy backup operations", out.contains(
333+
"Copy Backup Operations"));
334334
} catch (SpannerException e) {
335335
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.INVALID_ARGUMENT);
336336
assertThat(e.getMessage()).contains("Cannot evaluate filter expression");

0 commit comments

Comments
 (0)