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()));
}
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()));
}
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));
}
Aggregations