use of com.google.spanner.admin.instance.v1.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.spanner.admin.instance.v1.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.spanner.admin.instance.v1.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());
}
use of com.google.spanner.admin.instance.v1.Instance in project java-redis by googleapis.
the class ITSystemTest method testListInstances.
@Test
public void testListInstances() {
List<Instance> instances = Lists.newArrayList(client.listInstances(PARENT).iterateAll());
for (Instance instance : instances) {
if (INSTANCE_NAME.toString().equals(instance.getName())) {
assertEquals(TIER, instance.getTier());
assertEquals(INSTANCE_NAME.toString(), instance.getName());
}
}
}
use of com.google.spanner.admin.instance.v1.Instance in project java-notebooks by googleapis.
the class ITNotebookServiceClientTest method setUp.
@BeforeClass
public static void setUp() throws IOException, ExecutionException, InterruptedException {
// Create Test Notebook Instance
client = NotebookServiceClient.create();
ContainerImage containerImage = ContainerImage.newBuilder().setRepository(FieldBehavior.OPTIONAL.name()).build();
Environment environment = Environment.newBuilder().setName(ENVIRONMENT_NAME).setContainerImage(containerImage).build();
CreateEnvironmentRequest environmentRequest = CreateEnvironmentRequest.newBuilder().setParent(PARENT).setEnvironmentId(ENVIRONMENT_ID).setEnvironment(environment).build();
expectedEnvironmentResponse = client.createEnvironmentAsync(environmentRequest).get();
Instance notebookInstance = Instance.newBuilder().setContainerImage(containerImage).setMachineType(MACHINE_TYPE_A).build();
CreateInstanceRequest instanceRequest = CreateInstanceRequest.newBuilder().setParent(PARENT).setInstanceId(NOTEBOOK_INSTANCE_ID).setInstance(notebookInstance).build();
expectedNotebookInstance = client.createInstanceAsync(instanceRequest).get();
}
Aggregations