Search in sources :

Example 71 with Instance

use of com.google.spanner.admin.instance.v1.Instance 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()) {
 *   String name = InstanceName.of("[PROJECT]", "[INSTANCE]").toString();
 *   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(String name) {
    DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name).build();
    deleteInstance(request);
}
Also used : DeleteInstanceRequest(com.google.spanner.admin.instance.v1.DeleteInstanceRequest)

Example 72 with Instance

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

the class DatabaseAdminGaxTest method listDatabasesTest.

@Test
public void listDatabasesTest() {
    Exception exception = setupException();
    String nextPageToken = "token%d";
    List<com.google.spanner.admin.database.v1.Database> databases = new ArrayList<>(2);
    for (int i = 0; i < 2; i++) {
        databases.add(com.google.spanner.admin.database.v1.Database.newBuilder().setName(String.format("projects/%s/instances/%s/databases/test%d", PROJECT, INSTANCE, i)).build());
    }
    if (exceptionAtCall == 0) {
        mockDatabaseAdmin.addException(exception);
    }
    for (int i = 0; i < 2; i++) {
        ListDatabasesResponse.Builder builder = ListDatabasesResponse.newBuilder().addAllDatabases(Collections.singletonList(databases.get(i)));
        if (i < (databases.size() - 1)) {
            builder.setNextPageToken(String.format(nextPageToken, i));
        }
        if (exceptionAtCall == (i + 1)) {
            mockDatabaseAdmin.addException(exception);
        }
        mockDatabaseAdmin.addResponse(builder.build());
    }
    InstanceName parent = InstanceName.of(PROJECT, INSTANCE);
    Page<Database> pagedListResponse = client.listDatabases(INSTANCE);
    List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(2, resources.size());
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(2, actualRequests.size());
    ListDatabasesRequest actualRequest = (ListDatabasesRequest) actualRequests.get(0);
    Assert.assertEquals(parent, InstanceName.parse(actualRequest.getParent()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceName(com.google.spanner.admin.instance.v1.InstanceName) ListDatabasesResponse(com.google.spanner.admin.database.v1.ListDatabasesResponse) ListDatabasesRequest(com.google.spanner.admin.database.v1.ListDatabasesRequest) Test(org.junit.Test)

Example 73 with Instance

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

the class InstanceAdminGaxTest method getInstanceTest.

@Test
public void getInstanceTest() {
    Exception exception = setupException();
    InstanceName name2 = InstanceName.of(PROJECT, "INSTANCE");
    String displayName = "displayName1615086568";
    InstanceConfigName config = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
    com.google.spanner.admin.instance.v1.Instance expectedResponse = com.google.spanner.admin.instance.v1.Instance.newBuilder().setName(name2.toString()).setConfig(config.toString()).setDisplayName(displayName).setNodeCount(3).build();
    if (exceptionAtCall == 0) {
        mockInstanceAdmin.addException(exception);
    }
    mockInstanceAdmin.addResponse(expectedResponse);
    if (exceptionAtCall == 1) {
        mockInstanceAdmin.addException(exception);
    }
    mockInstanceAdmin.addResponse(expectedResponse);
    InstanceName name = InstanceName.of(PROJECT, "INSTANCE");
    for (int i = 0; i < 2; i++) {
        Instance actualResponse = client.getInstance(name.toString());
        Assert.assertEquals(displayName, actualResponse.getDisplayName());
    }
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    Assert.assertEquals(2, actualRequests.size());
}
Also used : InstanceName(com.google.spanner.admin.instance.v1.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName) Test(org.junit.Test)

Example 74 with Instance

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

the class InstanceAdminGaxTest method updateInstanceTest.

@Test
public void updateInstanceTest() throws Exception {
    boolean methodIsIdempotent = !spanner.getOptions().getInstanceAdminStubSettings().updateInstanceOperationSettings().getInitialCallSettings().getRetryableCodes().isEmpty();
    if (!methodIsIdempotent && exceptionType == ExceptionType.DELAYED) {
        // Skip this test as the method is non-idempotent and won't retry anyways.
        return;
    }
    Exception exception = setupException();
    InstanceName name = InstanceName.of(PROJECT, "INSTANCE");
    InstanceConfigName config = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
    String displayName = "displayName1615086568";
    int nodeCount = 1539922066;
    com.google.spanner.admin.instance.v1.Instance expectedResponse = com.google.spanner.admin.instance.v1.Instance.newBuilder().setName(name.toString()).setConfig(config.toString()).setDisplayName(displayName).setNodeCount(nodeCount).build();
    com.google.longrunning.Operation resultOperation = com.google.longrunning.Operation.newBuilder().setName("updateInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    if (exceptionAtCall == 0) {
        mockInstanceAdmin.addException(exception);
    }
    mockInstanceAdmin.addResponse(resultOperation);
    if (exceptionAtCall == 1) {
        mockInstanceAdmin.addException(exception);
    }
    mockInstanceAdmin.addResponse(resultOperation);
    for (int i = 0; i < 2; i++) {
        OperationFuture<Instance, UpdateInstanceMetadata> actualResponse = client.updateInstance(InstanceInfo.newBuilder(InstanceId.of(PROJECT, "INSTANCE")).setDisplayName(displayName).setNodeCount(nodeCount).build());
        try {
            Instance returnedInstance = actualResponse.get();
            if (!methodIsIdempotent && i == exceptionAtCall) {
                fail("missing expected exception");
            }
            Assert.assertEquals(displayName, returnedInstance.getDisplayName());
        } catch (ExecutionException e) {
            if (!exceptionType.isRetryable() || methodIsIdempotent || i != exceptionAtCall) {
                Throwables.throwIfUnchecked(e.getCause());
                throw e;
            }
        }
    }
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    if (methodIsIdempotent) {
        Assert.assertEquals(2, actualRequests.size());
    } else {
        Assert.assertEquals(1, actualRequests.size());
    }
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName) InstanceName(com.google.spanner.admin.instance.v1.InstanceName) UpdateInstanceMetadata(com.google.spanner.admin.instance.v1.UpdateInstanceMetadata) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 75 with Instance

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

the class InstanceAdminGaxTest method createInstanceTest.

@Test
public void createInstanceTest() throws Exception {
    boolean methodIsIdempotent = !spanner.getOptions().getInstanceAdminStubSettings().createInstanceOperationSettings().getInitialCallSettings().getRetryableCodes().isEmpty();
    if (!methodIsIdempotent && exceptionType == ExceptionType.DELAYED) {
        // Skip this test as the method is non-idempotent and won't retry anyways.
        return;
    }
    Exception exception = setupException();
    InstanceName name = InstanceName.of(PROJECT, "INSTANCE");
    InstanceConfigName config = InstanceConfigName.of(PROJECT, "INSTANCE_CONFIG");
    String displayName = "displayName1615086568";
    int nodeCount = 1539922066;
    com.google.spanner.admin.instance.v1.Instance expectedResponse = com.google.spanner.admin.instance.v1.Instance.newBuilder().setName(name.toString()).setConfig(config.toString()).setDisplayName(displayName).setNodeCount(nodeCount).build();
    com.google.longrunning.Operation resultOperation = com.google.longrunning.Operation.newBuilder().setName("createInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    if (exceptionAtCall == 0) {
        mockInstanceAdmin.addException(exception);
    }
    mockInstanceAdmin.addResponse(resultOperation);
    if (exceptionAtCall == 1) {
        mockInstanceAdmin.addException(exception);
    }
    mockInstanceAdmin.addResponse(resultOperation);
    for (int i = 0; i < 2; i++) {
        OperationFuture<Instance, CreateInstanceMetadata> actualResponse = client.createInstance(InstanceInfo.newBuilder(InstanceId.of(PROJECT, "INSTANCE")).setDisplayName(displayName).setNodeCount(nodeCount).build());
        try {
            Instance returnedInstance = actualResponse.get();
            if (!methodIsIdempotent && i == exceptionAtCall) {
                fail("missing expected exception");
            }
            Assert.assertEquals(displayName, returnedInstance.getDisplayName());
        } catch (ExecutionException e) {
            if (!exceptionType.isRetryable() || methodIsIdempotent || i != exceptionAtCall) {
                Throwables.throwIfUnchecked(e.getCause());
                throw e;
            }
        }
    }
    List<AbstractMessage> actualRequests = mockInstanceAdmin.getRequests();
    if (methodIsIdempotent) {
        Assert.assertEquals(2, actualRequests.size());
    } else {
        Assert.assertEquals(1, actualRequests.size());
    }
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) CreateInstanceMetadata(com.google.spanner.admin.instance.v1.CreateInstanceMetadata) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName) InstanceName(com.google.spanner.admin.instance.v1.InstanceName) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)50 AbstractMessage (com.google.protobuf.AbstractMessage)19 ByteString (com.google.protobuf.ByteString)17 ExecutionException (java.util.concurrent.ExecutionException)16 Instance (com.google.cloud.spanner.Instance)15 StatusRuntimeException (io.grpc.StatusRuntimeException)14 Instance (com.google.cloud.compute.v1.Instance)11 InstancesClient (com.google.cloud.compute.v1.InstancesClient)11 CreateInstanceMetadata (com.google.spanner.admin.instance.v1.CreateInstanceMetadata)11 Instance (com.google.spanner.admin.instance.v1.Instance)11 Instance (com.google.bigtable.admin.v2.Instance)10 InstanceAdminClient (com.google.cloud.spanner.InstanceAdminClient)10 InstanceInfo (com.google.cloud.spanner.InstanceInfo)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)9 Instance (com.google.cloud.notebooks.v1beta1.Instance)9 Spanner (com.google.cloud.spanner.Spanner)8 ArrayList (java.util.ArrayList)8 Operation (com.google.cloud.compute.v1.Operation)7 FieldMask (com.google.protobuf.FieldMask)7 InstanceName (com.google.spanner.admin.instance.v1.InstanceName)7