Search in sources :

Example 36 with InstanceName

use of com.google.bigtable.admin.v2.InstanceName 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)

Example 37 with InstanceName

use of com.google.bigtable.admin.v2.InstanceName in project java-spanner by googleapis.

the class SpannerThreadsTest method mockGetInstanceResponse.

private void mockGetInstanceResponse() {
    InstanceName name2 = InstanceName.of("[PROJECT]", "[INSTANCE]");
    InstanceConfigName config = InstanceConfigName.of("[PROJECT]", "[INSTANCE_CONFIG]");
    String displayName = "displayName1615086568";
    int nodeCount = 1539922066;
    Instance expectedResponse = Instance.newBuilder().setName(name2.toString()).setConfig(config.toString()).setDisplayName(displayName).setNodeCount(nodeCount).build();
    mockInstanceAdmin.addResponse(expectedResponse);
}
Also used : InstanceName(com.google.spanner.admin.instance.v1.InstanceName) Instance(com.google.spanner.admin.instance.v1.Instance) InstanceConfigName(com.google.spanner.admin.instance.v1.InstanceConfigName)

Example 38 with InstanceName

use of com.google.bigtable.admin.v2.InstanceName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method listBackupOperationsExceptionTest.

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

Example 39 with InstanceName

use of com.google.bigtable.admin.v2.InstanceName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method createBackupExceptionTest.

@Test
public void createBackupExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
        Backup backup = Backup.newBuilder().build();
        String backupId = "backupId2121930365";
        client.createBackupAsync(parent, backup, backupId).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Backup(com.google.spanner.admin.database.v1.Backup) StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 40 with InstanceName

use of com.google.bigtable.admin.v2.InstanceName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method restoreDatabaseTest.

@Test
public void restoreDatabaseTest() throws Exception {
    Database expectedResponse = Database.newBuilder().setName(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setCreateTime(Timestamp.newBuilder().build()).setRestoreInfo(RestoreInfo.newBuilder().build()).setEncryptionConfig(EncryptionConfig.newBuilder().build()).addAllEncryptionInfo(new ArrayList<EncryptionInfo>()).setVersionRetentionPeriod("versionRetentionPeriod-629783929").setEarliestVersionTime(Timestamp.newBuilder().build()).setDefaultLeader("defaultLeader759009962").setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
    Operation resultOperation = Operation.newBuilder().setName("restoreDatabaseTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockDatabaseAdmin.addResponse(resultOperation);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    String databaseId = "databaseId1688905718";
    BackupName backup = BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]");
    Database actualResponse = client.restoreDatabaseAsync(parent, databaseId, backup).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    RestoreDatabaseRequest actualRequest = ((RestoreDatabaseRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(databaseId, actualRequest.getDatabaseId());
    Assert.assertEquals(backup.toString(), actualRequest.getBackup());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) RestoreDatabaseRequest(com.google.spanner.admin.database.v1.RestoreDatabaseRequest) Database(com.google.spanner.admin.database.v1.Database) ArrayList(java.util.ArrayList) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) BackupName(com.google.spanner.admin.database.v1.BackupName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)45 AbstractMessage (com.google.protobuf.AbstractMessage)24 StatusRuntimeException (io.grpc.StatusRuntimeException)24 ByteString (com.google.protobuf.ByteString)22 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 Table (com.google.bigtable.admin.v2.Table)7 ArrayList (java.util.ArrayList)7 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 HashMap (java.util.HashMap)3