use of com.google.bigtable.admin.v2.Instance 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.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method getClusterTest.
@Test
public void getClusterTest() throws Exception {
Cluster expectedResponse = Cluster.newBuilder().setName(ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]").toString()).setLocation(LocationName.of("[PROJECT]", "[LOCATION]").toString()).setServeNodes(-1288838783).setDefaultStorageType(StorageType.forNumber(0)).setEncryptionConfig(Cluster.EncryptionConfig.newBuilder().build()).build();
mockBigtableInstanceAdmin.addResponse(expectedResponse);
ClusterName name = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
Cluster actualResponse = client.getCluster(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetClusterRequest actualRequest = ((GetClusterRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method listAppProfilesExceptionTest.
@Test
public void listAppProfilesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtableInstanceAdmin.addException(exception);
try {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
client.listAppProfiles(parent);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.bigtable.admin.v2.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method getInstanceTest.
@Test
public void getInstanceTest() throws Exception {
Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
mockBigtableInstanceAdmin.addResponse(expectedResponse);
InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
Instance actualResponse = client.getInstance(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetInstanceRequest actualRequest = ((GetInstanceRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method createInstanceExceptionTest2.
@Test
public void createInstanceExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtableInstanceAdmin.addException(exception);
try {
String parent = "parent-995424086";
String instanceId = "instanceId902024336";
Instance instance = Instance.newBuilder().build();
Map<String, Cluster> clusters = new HashMap<>();
client.createInstanceAsync(parent, instanceId, instance, clusters).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());
}
}
Aggregations