public void TestCreateBackup()
    {
        CreateBackupSample createBackupSample = new CreateBackupSample();
        // Backup already exists since it was created in the test setup so it should throw an exception.
        var exception = Assert.Throws <RpcException>(() => createBackupSample.CreateBackup(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.BackupDatabaseId, _spannerFixture.BackupId));

        Assert.Equal(StatusCode.AlreadyExists, exception.StatusCode);
    }
Esempio n. 2
0
    public void TestCreateBackup()
    {
        var databaseAdminClient = DatabaseAdminClient.Create();
        var database            = databaseAdminClient.GetDatabase(DatabaseName.FromProjectInstanceDatabase(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.BackupDatabaseId));
        var earliestVersionTime = database.EarliestVersionTime.ToDateTime();

        CreateBackupSample createBackupSample = new CreateBackupSample();
        // Backup already exists since it was created in the test setup so it should throw an exception.
        var exception = Assert.Throws <RpcException>(()
                                                     => createBackupSample.CreateBackup(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.BackupDatabaseId, _spannerFixture.BackupId, earliestVersionTime));

        Assert.Equal(StatusCode.AlreadyExists, exception.StatusCode);
    }
    public void TestCreateBackup()
    {
        string connectionString = $"Data Source=projects/{_spannerFixture.ProjectId}/instances/{_spannerFixture.InstanceId}/databases/{_spannerFixture.BackupDatabaseId}";

        using var connection = new SpannerConnection(connectionString);
        connection.Open();
        var versionTime = (DateTime)connection.CreateSelectCommand("SELECT CURRENT_TIMESTAMP").ExecuteScalar();

        CreateBackupSample createBackupSample = new CreateBackupSample();
        // Backup already exists since it was created in the test setup so it should throw an exception.
        var exception = Assert.Throws <RpcException>(()
                                                     => createBackupSample.CreateBackup(_spannerFixture.ProjectId, _spannerFixture.InstanceId, _spannerFixture.BackupDatabaseId, _spannerFixture.BackupId, versionTime));

        Assert.Equal(StatusCode.AlreadyExists, exception.StatusCode);
    }
Esempio n. 4
0
    private async Task InitializeBackupAsync()
    {
        // Sample database for backup and restore tests.
        try
        {
            CreateDatabaseAsyncSample createDatabaseAsyncSample = new CreateDatabaseAsyncSample();
            InsertDataAsyncSample     insertDataAsyncSample     = new InsertDataAsyncSample();
            await createDatabaseAsyncSample.CreateDatabaseAsync(ProjectId, InstanceId, BackupDatabaseId);

            await insertDataAsyncSample.InsertDataAsync(ProjectId, InstanceId, BackupDatabaseId);
        }
        catch (Exception e) when(e.ToString().Contains("Database already exists"))
        {
            // We intentionally keep an existing database around to reduce
            // the likelihood of test timeouts when creating a backup so
            // it's ok to get an AlreadyExists error.
            Console.WriteLine($"Database {BackupDatabaseId} already exists.");
        }

        using var connection = new SpannerConnection(ConnectionString);
        await connection.OpenAsync();

        var currentTimestamp = (DateTime)connection.CreateSelectCommand("SELECT CURRENT_TIMESTAMP").ExecuteScalar();

        try
        {
            CreateBackupSample createBackupSample = new CreateBackupSample();
            createBackupSample.CreateBackup(ProjectId, InstanceId, BackupDatabaseId, BackupId, currentTimestamp);
        }
        catch (RpcException e) when(e.StatusCode == StatusCode.AlreadyExists)
        {
            // We intentionally keep an existing backup around to reduce
            // the likelihood of test timeouts when creating a backup so
            // it's ok to get an AlreadyExists error.
            Console.WriteLine($"Backup {BackupId} already exists.");
        }
        catch (RpcException e) when(e.StatusCode == StatusCode.FailedPrecondition &&
                                    e.Message.Contains("maximum number of pending backups (1) for the database has been reached"))
        {
            // It's ok backup has been in progress in another test cycle.
            Console.WriteLine($"Backup {BackupId} already in progress.");
        }
    }