Search in sources :

Example 41 with Instance

use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientIT method instanceAndClusterCreationDeletionTest.

/**
 * To optimize test run time, instance & cluster creation is tested at the same time
 */
@Test
public void instanceAndClusterCreationDeletionTest() {
    String newInstanceId = prefixGenerator.newPrefix();
    String newClusterId = newInstanceId;
    client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 3, StorageType.SSD).setDisplayName("Fresh-Instance-Name").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
    try {
        assertThat(client.exists(newInstanceId)).isTrue();
        client.updateInstance(UpdateInstanceRequest.of(newInstanceId).setDisplayName("Test-Instance-Name"));
        Instance instance = client.getInstance(newInstanceId);
        assertThat(instance.getDisplayName()).isEqualTo("Test-Instance-Name");
        assertThat(client.listInstances()).contains(instance);
        clusterCreationDeletionTestHelper(newInstanceId);
        basicClusterOperationTestHelper(newInstanceId, newClusterId);
        client.deleteInstance(newInstanceId);
        assertThat(client.exists(newInstanceId)).isFalse();
    } finally {
        if (client.exists(newInstanceId)) {
            client.deleteInstance(newInstanceId);
        }
    }
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Test(org.junit.Test)

Example 42 with Instance

use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientIT method createClusterWithManualScalingTest.

@Test
public void createClusterWithManualScalingTest() {
    String newInstanceId = prefixGenerator.newPrefix();
    String newClusterId = newInstanceId + "-c1";
    try {
        client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD).setDisplayName("Multi-Cluster-Instance-Test").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
        String clusterId = prefixGenerator.newPrefix();
        CreateClusterRequest createClusterRequest = CreateClusterRequest.of(newInstanceId, clusterId).setZone(testEnvRule.env().getSecondaryZone()).setScalingMode(StaticClusterSize.of(5));
        Cluster cluster = client.createCluster(createClusterRequest);
        assertThat(cluster.getId()).contains(clusterId);
        assertThat(cluster.getServeNodes()).isEqualTo(5);
        assertThat(cluster.getAutoscalingMaxServeNodes()).isEqualTo(0);
        assertThat(cluster.getAutoscalingMinServeNodes()).isEqualTo(0);
        assertThat(cluster.getAutoscalingCpuPercentageTarget()).isEqualTo(0);
    } catch (Exception e) {
        Assert.fail("error in the test: " + e.getMessage());
    } finally {
        client.deleteInstance(newInstanceId);
    }
}
Also used : CreateClusterRequest(com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) Test(org.junit.Test)

Example 43 with Instance

use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientIT method appProfileTestMultiClusterWithIds.

@Test
public void appProfileTestMultiClusterWithIds() {
    String newInstanceId = prefixGenerator.newPrefix();
    String newClusterId = newInstanceId + "-c1";
    String newClusterId2 = newInstanceId + "-c2";
    client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD).addCluster(newClusterId2, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD).setDisplayName("Multi-Cluster-Instance-Test").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
    try {
        assertThat(client.exists(newInstanceId)).isTrue();
        String testAppProfile = "test-app-profile";
        CreateAppProfileRequest request = CreateAppProfileRequest.of(newInstanceId, testAppProfile).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.of(newClusterId)).setDescription("This is to test app profile");
        AppProfile newlyCreatedAppProfile = client.createAppProfile(request);
        AppProfile updated = client.updateAppProfile(UpdateAppProfileRequest.of(newlyCreatedAppProfile).setDescription("new description"));
        AppProfile freshAppProfile = client.getAppProfile(newInstanceId, testAppProfile);
        assertThat(freshAppProfile.getDescription()).isEqualTo(updated.getDescription());
        AppProfile.MultiClusterRoutingPolicy freshAppProfilePolicy = (AppProfile.MultiClusterRoutingPolicy) freshAppProfile.getPolicy();
        AppProfile.MultiClusterRoutingPolicy updatedAppProfilePolicy = (AppProfile.MultiClusterRoutingPolicy) updated.getPolicy();
        assertThat(freshAppProfilePolicy.getClusterIds()).containsExactly(newClusterId);
        assertThat(freshAppProfilePolicy.getClusterIds()).isEqualTo(updatedAppProfilePolicy.getClusterIds());
        assertThat(freshAppProfilePolicy).isEqualTo(updatedAppProfilePolicy);
        assertThat(client.listAppProfiles(newInstanceId)).contains(freshAppProfile);
        // update again with routing policy
        AppProfile updated2 = client.updateAppProfile(UpdateAppProfileRequest.of(updated).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.of(newClusterId2)));
        AppProfile freshAppProfile2 = client.getAppProfile(newInstanceId, testAppProfile);
        assertThat(freshAppProfile2.getDescription()).isEqualTo(updated2.getDescription());
        AppProfile.MultiClusterRoutingPolicy freshAppProfilePolicy2 = (AppProfile.MultiClusterRoutingPolicy) freshAppProfile2.getPolicy();
        AppProfile.MultiClusterRoutingPolicy updatedAppProfilePolicy2 = (AppProfile.MultiClusterRoutingPolicy) updated2.getPolicy();
        assertThat(freshAppProfilePolicy2.getClusterIds()).containsExactly(newClusterId2);
        assertThat(freshAppProfilePolicy2.getClusterIds()).isEqualTo(updatedAppProfilePolicy2.getClusterIds());
        assertThat(freshAppProfilePolicy2).isEqualTo(updatedAppProfilePolicy2);
        assertThat(client.listAppProfiles(newInstanceId)).contains(freshAppProfile2);
        // update to single routing policy
        AppProfile updated3 = client.updateAppProfile(UpdateAppProfileRequest.of(updated).setRoutingPolicy(AppProfile.SingleClusterRoutingPolicy.of(newClusterId)));
        AppProfile freshAppProfile3 = client.getAppProfile(newInstanceId, testAppProfile);
        assertThat(freshAppProfile3.getDescription()).isEqualTo(updated3.getDescription());
        AppProfile.SingleClusterRoutingPolicy freshAppProfilePolicy3 = (AppProfile.SingleClusterRoutingPolicy) freshAppProfile3.getPolicy();
        AppProfile.SingleClusterRoutingPolicy updatedAppProfilePolicy3 = (AppProfile.SingleClusterRoutingPolicy) updated3.getPolicy();
        assertThat(freshAppProfilePolicy3.getClusterId()).isEqualTo(newClusterId);
        assertThat(freshAppProfilePolicy3.getClusterId()).isEqualTo(updatedAppProfilePolicy3.getClusterId());
        assertThat(freshAppProfilePolicy3).isEqualTo(updatedAppProfilePolicy3);
        assertThat(client.listAppProfiles(newInstanceId)).contains(freshAppProfile3);
    } finally {
        if (client.exists(newInstanceId)) {
            client.deleteInstance(newInstanceId);
        }
    }
}
Also used : AppProfile(com.google.cloud.bigtable.admin.v2.models.AppProfile) CreateAppProfileRequest(com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest) Test(org.junit.Test)

Example 44 with Instance

use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientIT method basicInstanceOperationTest.

/* As cluster creation is very expensive operation, so reusing existing clusters to verify rest
  of the operation.*/
@Test
public void basicInstanceOperationTest() {
    assertThat(client.exists(instanceId)).isTrue();
    client.updateInstance(UpdateInstanceRequest.of(instanceId).setDisplayName("Updated-Instance-Name"));
    Instance instance = client.getInstance(instanceId);
    assertThat(instance.getDisplayName()).isEqualTo("Updated-Instance-Name");
    assertThat(client.listInstances()).contains(instance);
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Test(org.junit.Test)

Example 45 with Instance

use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method testUpdateInstance.

@Test
public void testUpdateInstance() {
    // Setup
    Mockito.when(mockStub.partialUpdateInstanceOperationCallable()).thenReturn(mockUpdateInstanceCallable);
    com.google.bigtable.admin.v2.PartialUpdateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.PartialUpdateInstanceRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("display_name")).setInstance(com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).setDisplayName("new display name")).build();
    com.google.bigtable.admin.v2.Instance expectedResponse = com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).build();
    mockOperationResult(mockUpdateInstanceCallable, expectedRequest, expectedResponse);
    // Execute
    Instance actualResult = adminClient.updateInstance(UpdateInstanceRequest.of(INSTANCE_ID).setDisplayName("new display name"));
    // Verify
    assertThat(actualResult).isEqualTo(Instance.fromProto(expectedResponse));
}
Also used : Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)19 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)10 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)7 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)4 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 ClusterName (com.google.bigtable.admin.v2.ClusterName)3 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)3 AppProfile (com.google.cloud.bigtable.admin.v2.models.AppProfile)3 ClusterAutoscalingConfig (com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig)3 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)3 ApiFuture (com.google.api.core.ApiFuture)2 AutoscalingLimits (com.google.bigtable.admin.v2.AutoscalingLimits)2 AutoscalingTargets (com.google.bigtable.admin.v2.AutoscalingTargets)2 GetInstanceRequest (com.google.bigtable.admin.v2.GetInstanceRequest)2 InstanceName (com.google.bigtable.admin.v2.InstanceName)2