@Test public void testNewServerWithoutHostIdSetsRegionAsLocation() { Set<Image> images = ImmutableSet.<Image> of(); Set<Hardware> hardwares = ImmutableSet.<Hardware> of(); Server serverToConvert = expectedServer(); ServerInRegion serverInRegionToConvert = new ServerInRegion(serverToConvert, "az-1.region-a.geo-1"); ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .<Set<? extends Image>> ofInstance(images), Suppliers .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention); NodeMetadata convertedNodeMetadata = converter.apply(serverInRegionToConvert); assertEquals(serverInRegionToConvert.slashEncode(), convertedNodeMetadata.getId()); assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId()); assertEquals(convertedNodeMetadata.getLocation(), region); URI expectedURI = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v2/37936628937291/servers/71752"); assertEquals(convertedNodeMetadata.getUri(), expectedURI); }
@Test public void testWhenComputeServiceSaysAllNodesAreDeadBothGroupsAreReturned() { ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1"); ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention); Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost)); assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysTrue()).apply(set), ImmutableMultimap .<String, String> builder().putAll("az-1.region-a.geo-1", "sample", "test").build()); }
@Test public void testWhenComputeServiceSaysAllNodesAreDeadNoGroupsAreReturned() { ServerInRegion withoutHost = new ServerInRegion(new ServerInRegionToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1"); ServerInRegion withHost = new ServerInRegion(new ParseServerTest().expected(), "az-1.region-a.geo-1"); ServerInRegionToNodeMetadata converter = new ServerInRegionToNodeMetadata( NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention); Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost)); assertEquals(new OrphanedGroupsByRegionId(Predicates.<RegionAndName> alwaysFalse()).apply(set), ImmutableMultimap .<String, String> of()); } }