@Test public void testFindMyInterface() { NetworkInterface networkInterface1 = new NetworkInterface( "id1", "subnet1", "vpc", ImmutableList.of(), ImmutableList.of(new PrivateIpAddress(true, Ip.parse("1.1.1.1"), null)), LOAD_BALANCER_INTERFACE_DESCRIPTION_PREFIX + _loadBalancerArnSuffix, null, ImmutableMap.of()); NetworkInterface networkInterface2 = new NetworkInterface( "id2", "subnet2", "vpc", ImmutableList.of(), ImmutableList.of(new PrivateIpAddress(true, Ip.parse("1.1.1.1"), null)), LOAD_BALANCER_INTERFACE_DESCRIPTION_PREFIX + _loadBalancerArnSuffix, null, ImmutableMap.of()); Region region = Region.builder("r1") .setNetworkInterfaces( ImmutableMap.of( networkInterface1.getId(), networkInterface1, networkInterface2.getId(), networkInterface2)) .build(); assertThat( LoadBalancer.findMyInterface("subnet1", _loadBalancerArn, region), equalTo(Optional.of(networkInterface1))); assertThat( LoadBalancer.findMyInterface("subnet2", _loadBalancerArn, region), equalTo(Optional.of(networkInterface2))); assertThat( LoadBalancer.findMyInterface("nosubnet", _loadBalancerArn, region), equalTo(Optional.empty())); assertThat(LoadBalancer.findMyInterface("subnet1", "noarn", region), equalTo(Optional.empty())); }
@VisibleForTesting static Optional<NetworkInterface> findMyInterface(String subnetId, String arn, Region region) { Matcher matcher = LOAD_BALANCER_ARN_PATTERN.matcher(arn); if (!matcher.matches()) { return Optional.empty(); } String matchString = matcher.group(1); return region.getNetworkInterfaces().values().stream() .filter( iface -> iface .getDescription() .equals(LOAD_BALANCER_INTERFACE_DESCRIPTION_PREFIX + matchString) && iface.getSubnetId().equals(subnetId)) .findAny(); }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting static Optional<NetworkInterface> findMyInterface(String subnetId, String arn, Region region) { Matcher matcher = LOAD_BALANCER_ARN_PATTERN.matcher(arn); if (!matcher.matches()) { return Optional.empty(); } String matchString = matcher.group(1); return region.getNetworkInterfaces().values().stream() .filter( iface -> iface .getDescription() .equals(LOAD_BALANCER_INTERFACE_DESCRIPTION_PREFIX + matchString) && iface.getSubnetId().equals(subnetId)) .findAny(); } }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting static Optional<NetworkInterface> findMyInterface(String subnetId, String arn, Region region) { Matcher matcher = LOAD_BALANCER_ARN_PATTERN.matcher(arn); if (!matcher.matches()) { return Optional.empty(); } String matchString = matcher.group(1); return region.getNetworkInterfaces().values().stream() .filter( iface -> iface .getDescription() .equals(LOAD_BALANCER_INTERFACE_DESCRIPTION_PREFIX + matchString) && iface.getSubnetId().equals(subnetId)) .findAny(); } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting static Optional<NetworkInterface> findMyInterface(String subnetId, String arn, Region region) { Matcher matcher = LOAD_BALANCER_ARN_PATTERN.matcher(arn); if (!matcher.matches()) { return Optional.empty(); } String matchString = matcher.group(1); return region.getNetworkInterfaces().values().stream() .filter( iface -> iface .getDescription() .equals(LOAD_BALANCER_INTERFACE_DESCRIPTION_PREFIX + matchString) && iface.getSubnetId().equals(subnetId)) .findAny(); } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); @Override String getId(); @Nonnull List<AvailabilityZone> getAvailabilityZones(); @Nonnull String getDnsName(); @Nonnull String getName(); @Nonnull Scheme getScheme(); @Nonnull Type getType(); @Nonnull String getVpcId(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting static Optional<NetworkInterface> findMyInterface(String subnetId, String arn, Region region) { Matcher matcher = LOAD_BALANCER_ARN_PATTERN.matcher(arn); if (!matcher.matches()) { return Optional.empty(); } String matchString = matcher.group(1); return region.getNetworkInterfaces().values().stream() .filter( iface -> iface .getDescription() .equals(LOAD_BALANCER_INTERFACE_DESCRIPTION_PREFIX + matchString) && iface.getSubnetId().equals(subnetId)) .findAny(); } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); @Override String getId(); @Nonnull List<AvailabilityZone> getAvailabilityZones(); @Nonnull String getDnsName(); @Nonnull String getName(); @Nonnull Scheme getScheme(); @Nonnull Type getType(); @Nonnull String getVpcId(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }