@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "region eu-central-1 is not in the configured region to zone mappings: .*") public void zoneToRegionMappingsInconsistentOnKeys() { Map<String, Supplier<URI>> regionIdToURIs = Maps.newLinkedHashMap(); regionIdToURIs.put("us-east-1", Suppliers.ofInstance(URI.create("ec2.us-east-1.amazonaws.com"))); regionIdToURIs.put("eu-central-1", Suppliers.ofInstance(URI.create("ec2.eu-central-1.amazonaws.com"))); Map<String, Supplier<Set<String>>> regionIdToZoneIds = Maps.newLinkedHashMap(); regionIdToZoneIds.put("us-east-1", supplyZoneIds("us-east-1a", "us-east-1b")); new ZoneIdToURIFromJoinOnRegionIdToURI(Suppliers.ofInstance(regionIdToURIs), Suppliers.ofInstance(regionIdToZoneIds)).get(); }
@Override public Map<String, Supplier<URI>> get() { Map<String, Supplier<Set<String>>> regionIdToZoneIds = this.regionIdToZoneIds.get(); Builder<String, Supplier<URI>> builder = ImmutableMap.builder(); for (Entry<String, Supplier<URI>> regionToURI : regionIdToURIs.get().entrySet()) { Supplier<Set<String>> zoneIds = regionIdToZoneIds.get(regionToURI.getKey()); checkState(zoneIds != null, "region %s is not in the configured region to zone mappings: %s", regionToURI.getKey(), regionIdToZoneIds); for (String zone : zoneIds.get()) { builder.put(zone, regionToURI.getValue()); } } return builder.build(); }
ZoneIdToURIFromJoinOnRegionIdToURI implements ZoneIdToURISupplier { @Override public Map<String, Supplier<URI>> get() { Map<String, Supplier<Set<String>>> regionIdToZoneIds = this.regionIdToZoneIds.get(); Builder<String, Supplier<URI>> builder = ImmutableMap.builder(); for (Entry<String, Supplier<URI>> regionToURI : regionIdToURIs.get().entrySet()) { Supplier<Set<String>> zoneIds = regionIdToZoneIds.get(regionToURI.getKey()); checkState(zoneIds != null, "region %s is not in the configured region to zone mappings: %s", regionToURI.getKey(), regionIdToZoneIds); for (String zone : zoneIds.get()) { builder.put(zone, regionToURI.getValue()); } } return builder.build(); } }
ZoneIdToURIFromJoinOnRegionIdToURI implements ZoneIdToURISupplier { @Override public Map<String, Supplier<URI>> get() { Map<String, Supplier<Set<String>>> regionIdToZoneIds = this.regionIdToZoneIds.get(); Builder<String, Supplier<URI>> builder = ImmutableMap.builder(); for (Entry<String, Supplier<URI>> regionToURI : regionIdToURIs.get().entrySet()) { Supplier<Set<String>> zoneIds = regionIdToZoneIds.get(regionToURI.getKey()); checkState(zoneIds != null, "region %s is not in the configured region to zone mappings: %s", regionToURI.getKey(), regionIdToZoneIds); for (String zone : zoneIds.get()) { builder.put(zone, regionToURI.getValue()); } } return builder.build(); } @Inject  ZoneIdToURIFromJoinOnRegionIdToURI(@Region Supplier<Map<String, Supplier<URI>>> regionIdToURIs,
         @Zone Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIds); }
ZoneIdToURIFromJoinOnRegionIdToURI implements ZoneIdToURISupplier { @Override public Map<String, Supplier<URI>> get() { Map<String, Supplier<Set<String>>> regionIdToZoneIds = this.regionIdToZoneIds.get(); Builder<String, Supplier<URI>> builder = ImmutableMap.builder(); for (Entry<String, Supplier<URI>> regionToURI : regionIdToURIs.get().entrySet()) { Supplier<Set<String>> zoneIds = regionIdToZoneIds.get(regionToURI.getKey()); checkState(zoneIds != null, "region %s is not in the configured region to zone mappings: %s", regionToURI.getKey(), regionIdToZoneIds); for (String zone : zoneIds.get()) { builder.put(zone, regionToURI.getValue()); } } return builder.build(); } @Inject  ZoneIdToURIFromJoinOnRegionIdToURI(@Region Supplier<Map<String, Supplier<URI>>> regionIdToURIs,
         @Zone Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIds); @Override Map<String, Supplier<URI>> get(); }
ZoneIdToURIFromJoinOnRegionIdToURI implements ZoneIdToURISupplier { @Override public Map<String, Supplier<URI>> get() { Map<String, Supplier<Set<String>>> regionIdToZoneIds = this.regionIdToZoneIds.get(); Builder<String, Supplier<URI>> builder = ImmutableMap.builder(); for (Entry<String, Supplier<URI>> regionToURI : regionIdToURIs.get().entrySet()) { Supplier<Set<String>> zoneIds = regionIdToZoneIds.get(regionToURI.getKey()); checkState(zoneIds != null, "region %s is not in the configured region to zone mappings: %s", regionToURI.getKey(), regionIdToZoneIds); for (String zone : zoneIds.get()) { builder.put(zone, regionToURI.getValue()); } } return builder.build(); } @Inject  ZoneIdToURIFromJoinOnRegionIdToURI(@Region Supplier<Map<String, Supplier<URI>>> regionIdToURIs,
         @Zone Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIds); @Override Map<String, Supplier<URI>> get();  }