use of com.google.cloud.notebooks.v1beta1.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.cloud.notebooks.v1beta1.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());
}
}
use of com.google.cloud.notebooks.v1beta1.Instance in project java-redis by googleapis.
the class ITSystemTest method cleanUpOldInstances.
public static void cleanUpOldInstances() throws ParseException {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -1);
Timestamp cutoff = Timestamp.of(calendar.getTime());
List<Instance> instances = Lists.newArrayList(client.listInstances(PARENT).iterateAll());
for (Instance old_instance : instances) {
Timestamp createdAt = Timestamp.ofTimeSecondsAndNanos(old_instance.getCreateTime().getSeconds(), old_instance.getCreateTime().getNanos());
if (createdAt.compareTo(cutoff) < 0) {
client.deleteInstanceAsync(old_instance.getName());
LOG.info("redis instance " + old_instance.getName() + " deleted successfully.");
}
}
}
use of com.google.cloud.notebooks.v1beta1.Instance in project java-redis by googleapis.
the class ITSystemTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
CloudRedisSettings.Builder cloudRedisSettingsBuilder = CloudRedisSettings.newBuilder();
cloudRedisSettingsBuilder.getInstanceSettings().setRetrySettings(cloudRedisSettingsBuilder.getInstanceSettings().getRetrySettings().toBuilder().setTotalTimeout(Duration.ofSeconds(900)).build());
CloudRedisSettings cloudRedisSettings = cloudRedisSettingsBuilder.build();
client = CloudRedisClient.create(cloudRedisSettings);
/* Clean up old instances that were not deleted. */
cleanUpOldInstances();
/* Creates a Redis instance based on the specified tier and memory size. */
Instance instance = Instance.newBuilder().setTier(TIER).setMemorySizeGb(1).setAuthorizedNetwork(AUTHORIZED_NETWORK).build();
client.createInstanceAsync(PARENT, INSTANCE, instance).get();
LOG.info("redis instance created successfully.");
}
use of com.google.cloud.notebooks.v1beta1.Instance in project java-redis by googleapis.
the class ITSystemTest method testGetInstance.
@Test
public void testGetInstance() {
Instance response = client.getInstance(INSTANCE_NAME);
assertEquals(TIER, response.getTier());
assertEquals(INSTANCE_NAME.toString(), response.getName());
}
Aggregations