Skip to content

docs: samples and tests for database Admin APIs. #2775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
edc5bbf
fix: prevent illegal negative timeout values into thread sleep() meth…
arpan14 Feb 6, 2023
49a85df
Merge pull request #1 from arpan14/retryerror
arpan14 Feb 8, 2023
4cd497b
Fixing lint issues.
arpan14 Feb 8, 2023
4a6aa8e
Merge branch 'googleapis:main' into main
arpan14 Mar 13, 2023
b2aa09d
Merge branch 'googleapis:main' into main
arpan14 Mar 15, 2023
8d6d71e
Merge branch 'googleapis:main' into main
arpan14 May 9, 2023
77e6e7d
Merge branch 'googleapis:main' into main
arpan14 Jul 17, 2023
e8b7fad
Merge branch 'googleapis:main' into main
arpan14 Jul 25, 2023
8aa84e1
Merge branch 'googleapis:main' into main
arpan14 Oct 10, 2023
57fd405
Merge branch 'googleapis:main' into main
arpan14 Oct 27, 2023
1253563
Merge branch 'googleapis:main' into main
arpan14 Nov 20, 2023
d4f6a60
Merge branch 'googleapis:main' into main
arpan14 Dec 15, 2023
3efaf7c
Merge branch 'googleapis:main' into main
arpan14 Dec 26, 2023
f41b39f
Merge branch 'googleapis:main' into main
arpan14 Jan 3, 2024
7e3287f
Merge branch 'googleapis:main' into main
arpan14 Jan 13, 2024
2862112
chore: adding a few samples with auto-gen clients.
arpan14 Nov 29, 2023
313b6ee
chore: adding integration tests for samples.
arpan14 Dec 18, 2023
e9d0556
chore: fixing the end-point for staging.
arpan14 Dec 21, 2023
2416cd6
chore: modified test for CreateDatabaseWithDefaultLeaderSample.
arpan14 Dec 21, 2023
87cbb89
chore: adding sample and integration test for CreateInstanceSample.
arpan14 Dec 21, 2023
9feb1ab
chore: adding license headers.
arpan14 Dec 21, 2023
596fb26
chore: fix lint errors.
arpan14 Dec 21, 2023
d9a5ae0
chore: rename file and add sample tags.
arpan14 Dec 23, 2023
56dcdb2
chore: address comments.
arpan14 Dec 23, 2023
c7f998b
Update samples/snippets/src/main/java/com/example/spanner/v2/CreateDa…
arpan14 Dec 23, 2023
cd70008
chore: rename file path.
arpan14 Dec 26, 2023
b8f2000
chore: remove admin settings.
arpan14 Dec 26, 2023
3f7309e
chore: address comments.
arpan14 Dec 26, 2023
f3d4f66
chore: copy relevant apis.
arpan14 Dec 30, 2023
57aef57
chore: updating integration tests.
arpan14 Dec 30, 2023
ee79d74
chore: rewrite database admin APIs and tests.
arpan14 Jan 9, 2024
fe5b0a8
chore: fix broken integration tests.
arpan14 Jan 9, 2024
bad0fc0
chore: fix CreateDatabaseWithVersionRetentionPeriodSampleIT.
arpan14 Jan 10, 2024
259bb39
chore: fix lint errors.
arpan14 Jan 10, 2024
deb7bb6
chore: rebase fixes.
arpan14 Jan 13, 2024
3d24ef7
chore: fix broken intergration test for AddAndDropDatabaseRole.
arpan14 Feb 9, 2024
e27f2cc
chore: fix lint error.
arpan14 Feb 9, 2024
cbc6875
chore: add comment around jsonb
arpan14 Feb 15, 2024
24321b9
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Feb 15, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: modified test for CreateDatabaseWithDefaultLeaderSample.
  • Loading branch information
arpan14 committed Jan 13, 2024
commit 2416cd64484f2f34ff7e61ecbf8092b0c906a7b4
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//[START spanner_create_database_with_default_leader]

import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.spanner.SpannerException;
import com.google.cloud.spanner.SpannerExceptionFactory;
import com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient;
import com.google.common.collect.ImmutableList;
Expand All @@ -17,23 +16,22 @@ public class CreateDatabaseWithDefaultLeaderSample {

static void createDatabaseWithDefaultLeader() throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "my-project";
final String instanceId = "my-instance";
final String databaseId = "my-database";
final String instanceName = "my-instance-name";
final String databaseId = "my-database-name";
final String defaultLeader = "my-default-leader";
createDatabaseWithDefaultLeader(projectId, instanceId, databaseId, defaultLeader);
createDatabaseWithDefaultLeader(instanceName, databaseId, defaultLeader);
}

static void createDatabaseWithDefaultLeader(
String projectId, String instanceId, String databaseId, String defaultLeader) throws IOException {
static void createDatabaseWithDefaultLeader(String instanceName, String databaseId,
String defaultLeader) throws IOException {
DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create();

try {
OperationFuture<Database, CreateDatabaseMetadata> op2 =
OperationFuture<Database, CreateDatabaseMetadata> op1 =
databaseAdminClient.createDatabaseAsync(
CreateDatabaseRequest.newBuilder()
.setParent(instanceId)
.setCreateStatement("CREATE DATABASE " + databaseId)
.setParent(instanceName)
.setCreateStatement("CREATE DATABASE " + "`" + databaseId + "`")
.addAllExtraStatements(
ImmutableList.of("CREATE TABLE Singers ("
+ " SingerId INT64 NOT NULL,"
Expand All @@ -50,12 +48,12 @@ static void createDatabaseWithDefaultLeader(
"ALTER DATABASE " + "`" + databaseId + "`"
+ " SET OPTIONS ( default_leader = '" + defaultLeader + "' )"))
.build());
Database createdDatabase = op2.get();
Database createdDatabase = op1.get();
System.out.println("Created database [" + createdDatabase.getName() + "]");
System.out.println("\tDefault leader: " + createdDatabase.getDefaultLeader());
} catch (ExecutionException e) {
// If the operation failed during execution, expose the cause.
throw (SpannerException) e.getCause();
throw SpannerExceptionFactory.asSpannerException(e);
} catch (InterruptedException e) {
// Throw when a thread is waiting, sleeping, or otherwise occupied,
// and the thread is interrupted, either before or during the activity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public void testCreateDatabaseWithDefaultLeader() throws Exception {
// Runs sample
final String out = SampleRunner.runSample(() ->
CreateDatabaseWithDefaultLeaderSample.createDatabaseWithDefaultLeader(
projectId,
multiRegionalInstanceId,
getInstanceName(projectId, multiRegionalInstanceId),
databaseId,
defaultLeader
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ public class SampleTestBaseV2 {

@BeforeClass
public static void beforeClass() throws IOException {
final String serverUrl = "staging-wrenchworks.sandbox.googleapis.com:443";
final SpannerOptions.Builder optionsBuilder = SpannerOptions
.newBuilder()
.setAutoThrottleAdministrativeRequests();
final String serverUrl = "";
final SpannerOptions.Builder optionsBuilder =
SpannerOptions.newBuilder().setAutoThrottleAdministrativeRequests();
final SpannerOptions options = optionsBuilder.build();
final DatabaseAdminSettings.Builder databaseAdminSettingsBuilder = DatabaseAdminSettings.newBuilder();
final InstanceAdminSettings.Builder instanceAdminSettingBuilder = InstanceAdminSettings.newBuilder();
Expand Down Expand Up @@ -99,15 +98,19 @@ public static void afterClass() {
}
}

private static String getDatabaseName(final String projectId,
static String getDatabaseName(final String projectId,
final String instanceId, final String databaseId) {
return String.format(
"projects/%s/instances/%s/databases/%s", projectId, instanceId, databaseId);
}

private static String getBackupName(final String projectId,
static String getBackupName(final String projectId,
final String instanceId, final String backupId) {
return String.format(
"projects/%s/instances/%s/backups/%s", projectId, instanceId, backupId);
}

public String getInstanceName(final String projectId, final String instanceId) {
return String.format("projects/%s/instances/%s", projectId, instanceId);
}
}