Search in sources :

Example 16 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class InstanceAdminClientTest method deleteInstanceExceptionTest.

@Test
public void deleteInstanceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockInstanceAdmin.addException(exception);
    try {
        InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
        client.deleteInstance(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InstanceName(com.google.spanner.admin.instance.v1.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 17 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class InstanceAdminClientTest method deleteInstanceTest.

@Test
public void deleteInstanceTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockInstanceAdmin.addResponse(expectedResponse);
    InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
    client.deleteInstance(name);
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteInstanceRequest actualRequest = ((DeleteInstanceRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.instance.v1.InstanceName) Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DeleteInstanceRequest(com.google.spanner.admin.instance.v1.DeleteInstanceRequest) Test(org.junit.Test)

Example 18 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class GapicSpannerRpc method deleteInstance.

@Override
public void deleteInstance(String instanceName) throws SpannerException {
    DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(instanceName).build();
    GrpcCallContext context = newCallContext(null, instanceName, request, InstanceAdminGrpc.getDeleteInstanceMethod());
    get(instanceAdminStub.deleteInstanceCallable().futureCall(request, context));
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) DeleteInstanceRequest(com.google.spanner.admin.instance.v1.DeleteInstanceRequest)

Example 19 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class GapicSpannerRpc method getInstance.

@Override
public Instance getInstance(String instanceName) throws SpannerException {
    GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(instanceName).build();
    GrpcCallContext context = newCallContext(null, instanceName, request, InstanceAdminGrpc.getGetInstanceMethod());
    return get(instanceAdminStub.getInstanceCallable().futureCall(request, context));
}
Also used : GetInstanceRequest(com.google.spanner.admin.instance.v1.GetInstanceRequest) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext)

Example 20 with InstanceName

use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.

the class InstanceAdminClient method deleteInstance.

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
 * Deletes an instance.
 *
 * <p>Immediately upon completion of the request:
 *
 * <p>&#42; Billing ceases for all of the instance's reserved resources.
 *
 * <p>Soon afterward:
 *
 * <p>&#42; The instance and &#42;all of its databases&#42; immediately and irrevocably disappear
 * from the API. All data in the databases is permanently deleted.
 *
 * <p>Sample code:
 *
 * <pre>{@code
 * try (InstanceAdminClient instanceAdminClient = InstanceAdminClient.create()) {
 *   InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
 *   instanceAdminClient.deleteInstance(name);
 * }
 * }</pre>
 *
 * @param name Required. The name of the instance to be deleted. Values are of the form
 *     `projects/&lt;project&gt;/instances/&lt;instance&gt;`
 * @throws com.google.api.gax.rpc.ApiException if the remote call fails
 */
public final void deleteInstance(InstanceName name) {
    DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build();
    deleteInstance(request);
}
Also used : DeleteInstanceRequest(com.google.spanner.admin.instance.v1.DeleteInstanceRequest)

Aggregations

Test (org.junit.Test)44 AbstractMessage (com.google.protobuf.AbstractMessage)24 StatusRuntimeException (io.grpc.StatusRuntimeException)24 ByteString (com.google.protobuf.ByteString)21 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)20 InstanceName (com.google.bigtable.admin.v2.InstanceName)20 InstanceName (com.google.spanner.admin.database.v1.InstanceName)16 ExecutionException (java.util.concurrent.ExecutionException)11 Operation (com.google.longrunning.Operation)9 InstanceName (com.google.spanner.admin.instance.v1.InstanceName)9 ArrayList (java.util.ArrayList)7 Table (com.google.bigtable.admin.v2.Table)5 Database (com.google.spanner.admin.database.v1.Database)4 InstanceConfigName (com.google.spanner.admin.instance.v1.InstanceConfigName)4 IOException (java.io.IOException)4 ExpectedException (org.junit.rules.ExpectedException)4 AppProfile (com.google.bigtable.admin.v2.AppProfile)3 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)3 Backup (com.google.spanner.admin.database.v1.Backup)3 DeleteInstanceRequest (com.google.spanner.admin.instance.v1.DeleteInstanceRequest)3