use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.
the class GapicSpannerRpc method createSession.
@Override
public Session createSession(String databaseName, @Nullable Map<String, String> labels, @Nullable Map<Option, ?> options) throws SpannerException {
CreateSessionRequest.Builder requestBuilder = CreateSessionRequest.newBuilder().setDatabase(databaseName);
if (labels != null && !labels.isEmpty()) {
Session.Builder session = Session.newBuilder().putAllLabels(labels);
requestBuilder.setSession(session);
}
CreateSessionRequest request = requestBuilder.build();
GrpcCallContext context = newCallContext(options, databaseName, request, SpannerGrpc.getCreateSessionMethod());
return get(spannerStub.createSessionCallable().futureCall(request, context));
}
use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.
the class DatabaseAdminGaxTest method getDatabaseTest.
@Test
public void getDatabaseTest() {
Exception exception = setupException();
DatabaseName name2 = DatabaseName.of(PROJECT, INSTANCE, "DATABASE");
com.google.spanner.admin.database.v1.Database expectedResponse = com.google.spanner.admin.database.v1.Database.newBuilder().setName(name2.toString()).build();
if (exceptionAtCall == 0) {
mockDatabaseAdmin.addException(exception);
}
mockDatabaseAdmin.addResponse(expectedResponse);
if (exceptionAtCall == 1) {
mockDatabaseAdmin.addException(exception);
}
mockDatabaseAdmin.addResponse(expectedResponse);
for (int i = 0; i < 2; i++) {
Database actualResponse = client.getDatabase(INSTANCE, "DATABASE");
Assert.assertEquals(name2.toString(), actualResponse.getId().getName());
}
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(2, actualRequests.size());
}
use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.
the class DatabaseAdminClientTest method getDatabaseExceptionTest.
@Test
public void getDatabaseExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockDatabaseAdmin.addException(exception);
try {
DatabaseName name = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
client.getDatabase(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.v1.DatabaseName 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()));
}
use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.
the class DatabaseAdminClientTest method dropDatabaseTest.
@Test
public void dropDatabaseTest() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockDatabaseAdmin.addResponse(expectedResponse);
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
client.dropDatabase(database);
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
DropDatabaseRequest actualRequest = ((DropDatabaseRequest) actualRequests.get(0));
Assert.assertEquals(database.toString(), actualRequest.getDatabase());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations