public async Task TestCreateDatabaseAsync() { var databaseId = $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; CreateDatabaseAsyncSample sample = new CreateDatabaseAsyncSample(); await sample.CreateDatabaseAsync(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId); var databases = _spannerFixture.GetDatabases(); Assert.Contains(databases, d => d.DatabaseName.DatabaseId == databaseId); }
public async Task TestCreateDatabaseWithRetentionPeriodAsync() { var databaseId = $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; var sample = new CreateDatabaseWithRetentionPeriodAsyncSample(); await sample.CreateDatabaseWithRetentionPeriodAsync(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId); var databases = _spannerFixture.GetDatabases(); Assert.Contains(databases, d => d.DatabaseName.DatabaseId == databaseId); var database = databases.Where(d => d.DatabaseName.DatabaseId == databaseId).FirstOrDefault(); Assert.Equal("7d", database.VersionRetentionPeriod); }
public void TestRestoreDatabase() { RestoreDatabaseSample restoreDatabaseSample = new RestoreDatabaseSample(); try { restoreDatabaseSample.RestoreDatabase(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.RestoredDatabaseId, _spannerFixture.BackupId); } catch (RpcException ex) when(ex.Status.StatusCode == StatusCode.FailedPrecondition) { // Handles maximum number of pending restores which is currently one for the instance. } finally { var backupDatabaseId = $"projects/{_spannerFixture.ProjectId}/instances/{_spannerFixture.InstanceId}/databases/{_spannerFixture.BackupDatabaseId}"; var databases = _spannerFixture.GetDatabases().Where(c => c.RestoreInfo != null).ToList(); Assert.Contains(databases, d => d.RestoreInfo.BackupInfo.SourceDatabase == backupDatabaseId); } }