use of com.google.spanner.admin.database.v1.ListDatabasesRequest in project java-spanner by googleapis.
the class DatabaseAdminClientTest method listDatabasesTest2.
@Test
public void listDatabasesTest2() throws Exception {
Database responsesElement = Database.newBuilder().build();
ListDatabasesResponse expectedResponse = ListDatabasesResponse.newBuilder().setNextPageToken("").addAllDatabases(Arrays.asList(responsesElement)).build();
mockDatabaseAdmin.addResponse(expectedResponse);
String parent = "parent-995424086";
ListDatabasesPagedResponse pagedListResponse = client.listDatabases(parent);
List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDatabasesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDatabasesRequest actualRequest = ((ListDatabasesRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.database.v1.ListDatabasesRequest in project java-spanner by googleapis.
the class GapicSpannerRpc method listDatabases.
@Override
public Paginated<Database> listDatabases(String instanceName, int pageSize, @Nullable String pageToken) throws SpannerException {
acquireAdministrativeRequestsRateLimiter();
ListDatabasesRequest.Builder requestBuilder = ListDatabasesRequest.newBuilder().setParent(instanceName).setPageSize(pageSize);
if (pageToken != null) {
requestBuilder.setPageToken(pageToken);
}
final ListDatabasesRequest request = requestBuilder.build();
final GrpcCallContext context = newCallContext(null, instanceName, request, DatabaseAdminGrpc.getListDatabasesMethod());
ListDatabasesResponse response = runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.listDatabasesCallable().futureCall(request, context)));
return new Paginated<>(response.getDatabasesList(), response.getNextPageToken());
}
use of com.google.spanner.admin.database.v1.ListDatabasesRequest in project java-spanner by googleapis.
the class DatabaseAdminGaxTest method listDatabasesTest.
@Test
public void listDatabasesTest() {
Exception exception = setupException();
String nextPageToken = "token%d";
List<com.google.spanner.admin.database.v1.Database> databases = new ArrayList<>(2);
for (int i = 0; i < 2; i++) {
databases.add(com.google.spanner.admin.database.v1.Database.newBuilder().setName(String.format("projects/%s/instances/%s/databases/test%d", PROJECT, INSTANCE, i)).build());
}
if (exceptionAtCall == 0) {
mockDatabaseAdmin.addException(exception);
}
for (int i = 0; i < 2; i++) {
ListDatabasesResponse.Builder builder = ListDatabasesResponse.newBuilder().addAllDatabases(Collections.singletonList(databases.get(i)));
if (i < (databases.size() - 1)) {
builder.setNextPageToken(String.format(nextPageToken, i));
}
if (exceptionAtCall == (i + 1)) {
mockDatabaseAdmin.addException(exception);
}
mockDatabaseAdmin.addResponse(builder.build());
}
InstanceName parent = InstanceName.of(PROJECT, INSTANCE);
Page<Database> pagedListResponse = client.listDatabases(INSTANCE);
List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(2, resources.size());
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(2, actualRequests.size());
ListDatabasesRequest actualRequest = (ListDatabasesRequest) actualRequests.get(0);
Assert.assertEquals(parent, InstanceName.parse(actualRequest.getParent()));
}
use of com.google.spanner.admin.database.v1.ListDatabasesRequest in project java-spanner by googleapis.
the class DatabaseAdminClientTest method listDatabasesTest.
@Test
public void listDatabasesTest() throws Exception {
Database responsesElement = Database.newBuilder().build();
ListDatabasesResponse expectedResponse = ListDatabasesResponse.newBuilder().setNextPageToken("").addAllDatabases(Arrays.asList(responsesElement)).build();
mockDatabaseAdmin.addResponse(expectedResponse);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
ListDatabasesPagedResponse pagedListResponse = client.listDatabases(parent);
List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDatabasesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDatabasesRequest actualRequest = ((ListDatabasesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations