use of com.google.spanner.admin.instance.v1.Instance in project java-docs-samples by GoogleCloudPlatform.
the class GetDeleteProtection method getDeleteProtection.
// Returns the state of delete protection flag of given instance.
public static boolean getDeleteProtection(String projectId, String zone, String instanceName) throws IOException {
try (InstancesClient instancesClient = InstancesClient.create()) {
Instance instance = instancesClient.get(projectId, zone, instanceName);
boolean deleteProtection = instance.getDeletionProtection();
System.out.printf("Retrieved Delete Protection setting for instance: %s : %s", instanceName, deleteProtection);
return deleteProtection;
}
}
use of com.google.spanner.admin.instance.v1.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method createInstanceExceptionTest.
@Test
public void createInstanceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtableInstanceAdmin.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
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());
}
}
use of com.google.spanner.admin.instance.v1.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method partialUpdateInstanceTest.
@Test
public void partialUpdateInstanceTest() 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("partialUpdateInstanceTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockBigtableInstanceAdmin.addResponse(resultOperation);
Instance instance = Instance.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
Instance actualResponse = client.partialUpdateInstanceAsync(instance, updateMask).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
PartialUpdateInstanceRequest actualRequest = ((PartialUpdateInstanceRequest) actualRequests.get(0));
Assert.assertEquals(instance, actualRequest.getInstance());
Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.instance.v1.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method getInstanceTest2.
@Test
public void getInstanceTest2() 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);
String name = "name3373707";
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, actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.instance.v1.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method partialUpdateInstanceExceptionTest.
@Test
public void partialUpdateInstanceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtableInstanceAdmin.addException(exception);
try {
Instance instance = Instance.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
client.partialUpdateInstanceAsync(instance, updateMask).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