Inserisci un errore dell'istanza

Inserisci un errore in un'istanza specifica per testare il modo in cui l'applicazione gestisce gli errori del database. È utile per verificare le procedure di failover e ripristino dell'applicazione.

Esempio di codice

C#

Per eseguire l'autenticazione in AlloyDB, configura le credenziali predefinite dell'applicazione. Per saperne di più, consulta Configura l'autenticazione per un ambiente di sviluppo locale.

using Google.Cloud.AlloyDb.V1;
using Google.LongRunning;

public sealed partial class GeneratedAlloyDBAdminClientSnippets
{
    /// <summary>Snippet for InjectFault</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void InjectFault()
    {
        // Create client
        AlloyDBAdminClient alloyDBAdminClient = AlloyDBAdminClient.Create();
        // Initialize request argument(s)
        InjectFaultRequest.Types.FaultType faultType = InjectFaultRequest.Types.FaultType.Unspecified;
        string name = "projects/[PROJECT]/locations/[LOCATION]/clusters/[CLUSTER]/instances/[INSTANCE]";
        // Make the request
        Operation<Instance, OperationMetadata> response = alloyDBAdminClient.InjectFault(faultType, name);

        // Poll until the returned long-running operation is complete
        Operation<Instance, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        Instance result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<Instance, OperationMetadata> retrievedResponse = alloyDBAdminClient.PollOnceInjectFault(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Instance retrievedResult = retrievedResponse.Result;
        }
    }
}

Passaggi successivi

Per cercare e filtrare gli esempi di codice per altri prodotti Google Cloud , consulta il browser degli esempi diGoogle Cloud .