use of com.google.cloud.redis.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.redis.v1beta1.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.cloud.redis.v1beta1.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();
}
use of com.google.cloud.redis.v1beta1.Instance in project java-notebooks by googleapis.
the class ITNotebookServiceClientTest method testGetInstance.
@Test
public void testGetInstance() {
GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(INSTANCE_NAME).build();
Instance actualNotebookInstance = client.getInstance(request);
assertEquals(expectedNotebookInstance.getContainerImage(), actualNotebookInstance.getContainerImage());
assertEquals(expectedNotebookInstance.getName(), actualNotebookInstance.getName());
assertEquals(expectedNotebookInstance.getNetwork(), actualNotebookInstance.getNetwork());
assertEquals(expectedNotebookInstance.getSubnet(), actualNotebookInstance.getSubnet());
}
use of com.google.cloud.redis.v1beta1.Instance in project java-notebooks by googleapis.
the class ITNotebookServiceClientTest method stopInstance.
private String stopInstance() throws ExecutionException, InterruptedException {
StopInstanceRequest request = StopInstanceRequest.newBuilder().setName(INSTANCE_NAME).build();
Instance response = client.stopInstanceAsync(request).get();
return response.getState().name();
}
Aggregations