Search in sources :

Example 1 with CreateInstanceRequest

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

the class BaseBigtableInstanceAdminClientTest method createInstanceTest2.

@Test
public void createInstanceTest2() throws Exception {
    Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("createInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableInstanceAdmin.addResponse(resultOperation);
    String parent = "parent-995424086";
    String instanceId = "instanceId902024336";
    Instance instance = Instance.newBuilder().build();
    Map<String, Cluster> clusters = new HashMap<>();
    Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance, clusters).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateInstanceRequest actualRequest = ((CreateInstanceRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(instanceId, actualRequest.getInstanceId());
    Assert.assertEquals(instance, actualRequest.getInstance());
    Assert.assertEquals(clusters, actualRequest.getClustersMap());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Instance(com.google.bigtable.admin.v2.Instance) HashMap(java.util.HashMap) Cluster(com.google.bigtable.admin.v2.Cluster) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) CreateInstanceRequest(com.google.bigtable.admin.v2.CreateInstanceRequest) Test(org.junit.Test)

Example 2 with CreateInstanceRequest

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

the class BaseBigtableInstanceAdminClientTest method createInstanceTest.

@Test
public void createInstanceTest() throws Exception {
    Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
    Operation resultOperation = Operation.newBuilder().setName("createInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockBigtableInstanceAdmin.addResponse(resultOperation);
    ProjectName parent = ProjectName.of("[PROJECT]");
    String instanceId = "instanceId902024336";
    Instance instance = Instance.newBuilder().build();
    Map<String, Cluster> clusters = new HashMap<>();
    Instance actualResponse = client.createInstanceAsync(parent, instanceId, instance, clusters).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateInstanceRequest actualRequest = ((CreateInstanceRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(instanceId, actualRequest.getInstanceId());
    Assert.assertEquals(instance, actualRequest.getInstance());
    Assert.assertEquals(clusters, actualRequest.getClustersMap());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Instance(com.google.bigtable.admin.v2.Instance) ProjectName(com.google.bigtable.admin.v2.ProjectName) HashMap(java.util.HashMap) Cluster(com.google.bigtable.admin.v2.Cluster) ByteString(com.google.protobuf.ByteString) Operation(com.google.longrunning.Operation) CreateInstanceRequest(com.google.bigtable.admin.v2.CreateInstanceRequest) Test(org.junit.Test)

Example 3 with CreateInstanceRequest

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

the class BigtableInstanceAdminClientTest method testCreateInstanceAutoscaling.

@Test
public void testCreateInstanceAutoscaling() {
    Mockito.when(mockStub.createInstanceOperationCallable()).thenReturn(mockCreateInstanceCallable);
    // Setup
    AutoscalingLimits autoscalingLimits = AutoscalingLimits.newBuilder().setMaxServeNodes(5).setMinServeNodes(1).build();
    AutoscalingTargets autoscalingTargets = AutoscalingTargets.newBuilder().setCpuUtilizationPercent(49).build();
    com.google.bigtable.admin.v2.Cluster.ClusterAutoscalingConfig clusterAutoscalingConfig = com.google.bigtable.admin.v2.Cluster.ClusterAutoscalingConfig.newBuilder().setAutoscalingLimits(autoscalingLimits).setAutoscalingTargets(autoscalingTargets).build();
    com.google.bigtable.admin.v2.CreateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.CreateInstanceRequest.newBuilder().setParent(PROJECT_NAME).setInstanceId(INSTANCE_ID).setInstance(com.google.bigtable.admin.v2.Instance.newBuilder().setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT).setDisplayName(INSTANCE_ID)).putClusters("cluster1", com.google.bigtable.admin.v2.Cluster.newBuilder().setLocation("projects/my-project/locations/us-east1-c").setClusterConfig(com.google.bigtable.admin.v2.Cluster.ClusterConfig.newBuilder().setClusterAutoscalingConfig(clusterAutoscalingConfig).build()).setDefaultStorageType(com.google.bigtable.admin.v2.StorageType.SSD).build()).build();
    com.google.bigtable.admin.v2.Instance expectedResponse = com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).build();
    mockOperationResult(mockCreateInstanceCallable, expectedRequest, expectedResponse);
    // Execute
    ClusterAutoscalingConfig autoscalingConfig = ClusterAutoscalingConfig.of(INSTANCE_ID, "cluster1").setCpuUtilizationTargetPercent(49).setMaxNodes(5).setMinNodes(1);
    Instance actualResult = adminClient.createInstance(CreateInstanceRequest.of(INSTANCE_ID).setType(Instance.Type.DEVELOPMENT).addCluster("cluster1", "us-east1-c", autoscalingConfig, StorageType.SSD));
    // Verify
    assertThat(actualResult).isEqualTo(Instance.fromProto(expectedResponse));
}
Also used : AutoscalingTargets(com.google.bigtable.admin.v2.AutoscalingTargets) AutoscalingLimits(com.google.bigtable.admin.v2.AutoscalingLimits) Instance(com.google.cloud.bigtable.admin.v2.models.Instance) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) ClusterAutoscalingConfig(com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Cluster (com.google.bigtable.admin.v2.Cluster)2 CreateInstanceRequest (com.google.bigtable.admin.v2.CreateInstanceRequest)2 Instance (com.google.bigtable.admin.v2.Instance)2 Operation (com.google.longrunning.Operation)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ByteString (com.google.protobuf.ByteString)2 HashMap (java.util.HashMap)2 AutoscalingLimits (com.google.bigtable.admin.v2.AutoscalingLimits)1 AutoscalingTargets (com.google.bigtable.admin.v2.AutoscalingTargets)1 ProjectName (com.google.bigtable.admin.v2.ProjectName)1 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)1 ClusterAutoscalingConfig (com.google.cloud.bigtable.admin.v2.models.ClusterAutoscalingConfig)1 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)1