Search in sources :

Example 1 with GetDatabaseRequest

use of com.google.spanner.admin.database.v1.GetDatabaseRequest in project java-spanner by googleapis.

the class GapicSpannerRpc method getDatabase.

@Override
public Database getDatabase(String databaseName) throws SpannerException {
    acquireAdministrativeRequestsRateLimiter();
    final GetDatabaseRequest request = GetDatabaseRequest.newBuilder().setName(databaseName).build();
    final GrpcCallContext context = newCallContext(null, databaseName, request, DatabaseAdminGrpc.getGetDatabaseMethod());
    return runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.getDatabaseCallable().futureCall(request, context)));
}
Also used : GetDatabaseRequest(com.google.spanner.admin.database.v1.GetDatabaseRequest) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext)

Example 2 with GetDatabaseRequest

use of com.google.spanner.admin.database.v1.GetDatabaseRequest in project java-spanner by googleapis.

the class DatabaseAdminClientTest method getDatabaseTest.

@Test
public void getDatabaseTest() throws Exception {
    Database expectedResponse = Database.newBuilder().setName(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setCreateTime(Timestamp.newBuilder().build()).setRestoreInfo(RestoreInfo.newBuilder().build()).setEncryptionConfig(EncryptionConfig.newBuilder().build()).addAllEncryptionInfo(new ArrayList<EncryptionInfo>()).setVersionRetentionPeriod("versionRetentionPeriod-629783929").setEarliestVersionTime(Timestamp.newBuilder().build()).setDefaultLeader("defaultLeader759009962").setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    DatabaseName name = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
    Database actualResponse = client.getDatabase(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetDatabaseRequest actualRequest = ((GetDatabaseRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : GetDatabaseRequest(com.google.spanner.admin.database.v1.GetDatabaseRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Database(com.google.spanner.admin.database.v1.Database) ArrayList(java.util.ArrayList) DatabaseName(com.google.spanner.admin.database.v1.DatabaseName) Test(org.junit.Test)

Example 3 with GetDatabaseRequest

use of com.google.spanner.admin.database.v1.GetDatabaseRequest in project java-spanner by googleapis.

the class DatabaseAdminClientTest method getDatabaseTest2.

@Test
public void getDatabaseTest2() throws Exception {
    Database expectedResponse = Database.newBuilder().setName(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setCreateTime(Timestamp.newBuilder().build()).setRestoreInfo(RestoreInfo.newBuilder().build()).setEncryptionConfig(EncryptionConfig.newBuilder().build()).addAllEncryptionInfo(new ArrayList<EncryptionInfo>()).setVersionRetentionPeriod("versionRetentionPeriod-629783929").setEarliestVersionTime(Timestamp.newBuilder().build()).setDefaultLeader("defaultLeader759009962").setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    String name = "name3373707";
    Database actualResponse = client.getDatabase(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetDatabaseRequest actualRequest = ((GetDatabaseRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : GetDatabaseRequest(com.google.spanner.admin.database.v1.GetDatabaseRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Database(com.google.spanner.admin.database.v1.Database) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

GetDatabaseRequest (com.google.spanner.admin.database.v1.GetDatabaseRequest)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 Database (com.google.spanner.admin.database.v1.Database)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ByteString (com.google.protobuf.ByteString)1 DatabaseName (com.google.spanner.admin.database.v1.DatabaseName)1