예제 #1
0
    private async Task InitializeDatabaseAsync()
    {
        // If the database has not been initialized, retry.
        CreateDatabaseAsyncSample  createDatabaseAsyncSample  = new CreateDatabaseAsyncSample();
        InsertDataAsyncSample      insertDataAsyncSample      = new InsertDataAsyncSample();
        AddColumnAsyncSample       addColumnAsyncSample       = new AddColumnAsyncSample();
        AddIndexAsyncSample        addIndexAsyncSample        = new AddIndexAsyncSample();
        AddStoringIndexAsyncSample addStoringIndexAsyncSample = new AddStoringIndexAsyncSample();
        await createDatabaseAsyncSample.CreateDatabaseAsync(ProjectId, InstanceId, DatabaseId);

        await insertDataAsyncSample.InsertDataAsync(ProjectId, InstanceId, DatabaseId);

        await InsertStructDataAsync();

        await addColumnAsyncSample.AddColumnAsync(ProjectId, InstanceId, DatabaseId);

        await AddCommitTimestampAsync();

        await addIndexAsyncSample.AddIndexAsync(ProjectId, InstanceId, DatabaseId);

        // Add storing Index on table.
        await addStoringIndexAsyncSample.AddStoringIndexAsync(ProjectId, InstanceId, DatabaseId);

        // Update the value of MarketingBudgets.
        await RefillMarketingBudgetsAsync(300000, 300000);
    }
예제 #2
0
    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 TestAddNumericColumnAsync()
    {
        var databaseId = $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
        CreateDatabaseAsyncSample sample = new CreateDatabaseAsyncSample();
        await sample.CreateDatabaseAsync(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId);

        await _spannerFixture.CreateVenuesTableAndInsertDataAsync(databaseId);

        AddNumericColumnAsyncSample addNumericColumnAsyncSample = new AddNumericColumnAsyncSample();
        await addNumericColumnAsyncSample.AddNumericColumnAsync(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId);
    }
예제 #4
0
    public async Task TestDeleteDataAsync()
    {
        var databaseId = $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
        CreateDatabaseAsyncSample createDatabaseAsyncSample = new CreateDatabaseAsyncSample();
        InsertDataAsyncSample     insertDataAsyncSample     = new InsertDataAsyncSample();
        await createDatabaseAsyncSample.CreateDatabaseAsync(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId);

        await insertDataAsyncSample.InsertDataAsync(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId);

        DeleteDataAsyncSample deleteDataAsyncSample = new DeleteDataAsyncSample();
        var rowCount = await deleteDataAsyncSample.DeleteDataAsync(_spannerFixture.ProjectId, _spannerFixture.InstanceId, databaseId);

        Assert.Equal(6, rowCount);
    }
예제 #5
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.");
        }
    }
예제 #6
0
    private async Task InitializeDatabaseAsync()
    {
        // If the database has not been initialized, retry.
        CreateDatabaseAsyncSample         createDatabaseAsyncSample                         = new CreateDatabaseAsyncSample();
        InsertDataAsyncSample             insertDataAsyncSample                             = new InsertDataAsyncSample();
        InsertStructSampleDataAsyncSample insertStructSampleDataAsyncSample                 = new InsertStructSampleDataAsyncSample();
        AddColumnAsyncSample                      addColumnAsyncSample                      = new AddColumnAsyncSample();
        AddCommitTimestampAsyncSample             addCommitTimestampAsyncSample             = new AddCommitTimestampAsyncSample();
        AddIndexAsyncSample                       addIndexAsyncSample                       = new AddIndexAsyncSample();
        AddStoringIndexAsyncSample                addStoringIndexAsyncSample                = new AddStoringIndexAsyncSample();
        CreateTableWithDataTypesAsyncSample       createTableWithDataTypesAsyncSample       = new CreateTableWithDataTypesAsyncSample();
        InsertDataTypesDataAsyncSample            insertDataTypesDataAsyncSample            = new InsertDataTypesDataAsyncSample();
        CreateTableWithTimestampColumnAsyncSample createTableWithTimestampColumnAsyncSample =
            new CreateTableWithTimestampColumnAsyncSample();
        await createDatabaseAsyncSample.CreateDatabaseAsync(ProjectId, InstanceId, DatabaseId);

        await insertDataAsyncSample.InsertDataAsync(ProjectId, InstanceId, DatabaseId);

        await insertStructSampleDataAsyncSample.InsertStructSampleDataAsync(ProjectId, InstanceId, DatabaseId);

        await addColumnAsyncSample.AddColumnAsync(ProjectId, InstanceId, DatabaseId);

        await addCommitTimestampAsyncSample.AddCommitTimestampAsync(ProjectId, InstanceId, DatabaseId);

        await addIndexAsyncSample.AddIndexAsync(ProjectId, InstanceId, DatabaseId);

        // Create a new table that includes supported datatypes.
        await createTableWithDataTypesAsyncSample.CreateTableWithDataTypesAsync(ProjectId, InstanceId, DatabaseId);

        // Write data to the new table.
        await insertDataTypesDataAsyncSample.InsertDataTypesDataAsync(ProjectId, InstanceId, DatabaseId);

        // Add storing Index on table.
        await addStoringIndexAsyncSample.AddStoringIndexAsync(ProjectId, InstanceId, DatabaseId);

        // Update the value of MarketingBudgets.
        await RefillMarketingBudgetsAsync(300000, 300000);

        // Create table with Timestamp column
        await createTableWithTimestampColumnAsyncSample.CreateTableWithTimestampColumnAsync(ProjectId, InstanceId, DatabaseId);
    }