use of com.google.spanner.admin.database.v1.Database in project jaxdb by jaxdb.
the class JSqlTest method loadEntitiesJaxSB.
@SuppressWarnings("unchecked")
static int loadEntitiesJaxSB(final Connection connection, final String name) throws ClassNotFoundException, IOException, SAXException, SQLException, TransformerException {
Database.threadLocal((Class<? extends Schema>) Class.forName(Entities.class.getPackage().getName() + "." + name)).connectPrepared(() -> connection);
final URL sqlx = ClassLoader.getSystemClassLoader().getResource("jaxdb/" + name + ".sqlx");
assertNotNull(sqlx);
final $Database database = ($Database) Bindings.parse(sqlx);
final DDLx ddlx = new DDLx(ClassLoader.getSystemClassLoader().getResource(name + ".ddlx"));
Schemas.truncate(connection, ddlx.getMergedSchema().getTable());
final Batch batch = new Batch();
final int expectedCount = DBVendor.valueOf(connection.getMetaData()) == DBVendor.ORACLE ? 0 : 1;
for (final data.Table<?> table : Entities.toEntities(database)) batch.addStatement(INSERT(table), (e, c) -> assertEquals(expectedCount, c));
return batch.execute();
}
use of com.google.spanner.admin.database.v1.Database 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)));
}
use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class DatabaseAdminClientTest method instanceListBackupOperationsWithProgress.
@Test
public void instanceListBackupOperationsWithProgress() throws InvalidProtocolBufferException {
Instance instance = spanner.getInstanceAdminClient().newInstanceBuilder(InstanceId.of(PROJECT_ID, INSTANCE_ID)).build();
String database = String.format("%s/databases/%s", TEST_PARENT, DB_ID);
String filter = String.format("(metadata.database:%s) AND " + "(metadata.@type:type.googleapis.com/" + "google.spanner.admin.database.v1.CreateBackupMetadata)", database);
Page<Operation> operations = instance.listBackupOperations(Options.filter(filter));
for (Operation op : operations.iterateAll()) {
CreateBackupMetadata metadata = op.getMetadata().unpack(CreateBackupMetadata.class);
String progress = String.format("Backup %s on database %s pending: %d%% complete", metadata.getName(), metadata.getDatabase(), metadata.getProgress().getProgressPercent());
assertThat(progress.contains("100%"));
}
}
use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class DatabaseAdminClientTest method testRetryOperationOnAdminMethodQuotaPerMinutePerProjectExceeded.
@Test
public void testRetryOperationOnAdminMethodQuotaPerMinutePerProjectExceeded() {
ErrorInfo info = ErrorInfo.newBuilder().putMetadata("quota_limit", "AdminMethodQuotaPerMinutePerProject").build();
Metadata.Key<ErrorInfo> key = Metadata.Key.of(info.getDescriptorForType().getFullName() + Metadata.BINARY_HEADER_SUFFIX, ProtoLiteUtils.metadataMarshaller(info));
Metadata trailers = new Metadata();
trailers.put(key, info);
mockDatabaseAdmin.addException(Status.RESOURCE_EXHAUSTED.withDescription("foo").asRuntimeException(trailers));
mockDatabaseAdmin.clearRequests();
Database database = client.getDatabase(INSTANCE_ID, DB_ID);
assertEquals(DB_ID, database.getId().getDatabase());
assertEquals(2, mockDatabaseAdmin.countRequestsOfType(GetDatabaseRequest.class));
}
use of com.google.spanner.admin.database.v1.Database 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()));
}
Aggregations