Search in sources :

Example 6 with Zone

use of com.google.api.services.compute.model.Zone in project pipeline5 by hartwigmedical.

the class InstanceLifecycleManagerTest method shouldReturnExistingInstance.

@Test
public void shouldReturnExistingInstance() throws Exception {
    Compute.Instances.List zoneOneInstances = mock(Compute.Instances.List.class);
    Compute.Instances.List zoneTwoInstances = mock(Compute.Instances.List.class);
    InstanceList zoneOneInstanceList = mock(InstanceList.class);
    InstanceList zoneTwoInstanceList = mock(InstanceList.class);
    when(instances.list(ARGUMENTS.project(), zoneOne)).thenReturn(zoneOneInstances);
    when(instances.list(ARGUMENTS.project(), zoneTwo)).thenReturn(zoneTwoInstances);
    when(zoneOneInstances.execute()).thenReturn(zoneOneInstanceList);
    when(zoneTwoInstances.execute()).thenReturn(zoneTwoInstanceList);
    Instance vmInstance = namedInstance(vmName);
    Instance someInstance = namedInstance();
    Instance someOtherInstance = namedInstance();
    when(zoneOneInstanceList.getItems()).thenReturn(singletonList(someInstance));
    when(zoneTwoInstanceList.getItems()).thenReturn(asList(someOtherInstance, vmInstance));
    Compute.Zones zones = mock(Compute.Zones.class);
    Compute.Zones.List zonesList = mock(Compute.Zones.List.class);
    List<Zone> stubbedZones = asList(zone(zoneOne), zone(zoneTwo));
    when(zonesList.execute()).thenReturn(new ZoneList().setItems(stubbedZones));
    when(compute.zones()).thenReturn(zones);
    when(zones.list(ARGUMENTS.project())).thenReturn(zonesList);
    Optional<Instance> found = victim.findExistingInstance(vmName);
    assertThat(found).isNotEmpty();
    assertThat(found.get()).isEqualTo(vmInstance);
}
Also used : Instance(com.google.api.services.compute.model.Instance) Zone(com.google.api.services.compute.model.Zone) Compute(com.google.api.services.compute.Compute) InstanceList(com.google.api.services.compute.model.InstanceList) ZoneList(com.google.api.services.compute.model.ZoneList) Test(org.junit.Test)

Aggregations

Zone (com.google.api.services.compute.model.Zone)6 Instance (com.google.api.services.compute.model.Instance)4 ZoneList (com.google.api.services.compute.model.ZoneList)4 Compute (com.google.api.services.compute.Compute)3 InstanceList (com.google.api.services.compute.model.InstanceList)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 Image (com.google.api.services.compute.model.Image)2 Operation (com.google.api.services.compute.model.Operation)2 Scheduling (com.google.api.services.compute.model.Scheduling)2 Tags (com.google.api.services.compute.model.Tags)2 PipelineStatus (com.hartwig.pipeline.execution.PipelineStatus)2 AttachedDisk (com.google.api.services.compute.model.AttachedDisk)1 NetworkInterface (com.google.api.services.compute.model.NetworkInterface)1 Lists (com.google.common.collect.Lists)1 Arguments (com.hartwig.pipeline.Arguments)1 ResultsDirectory (com.hartwig.pipeline.ResultsDirectory)1 State (com.hartwig.pipeline.execution.vm.BucketCompletionWatcher.State)1 LocalSsdStorageStrategy (com.hartwig.pipeline.execution.vm.storage.LocalSsdStorageStrategy)1 PersistentStorageStrategy (com.hartwig.pipeline.execution.vm.storage.PersistentStorageStrategy)1