@Test public void testWhenSpotsPresentSingleCall() { Function<SpotInstanceRequest, AWSRunningInstance> converter = Functions.forMap(ImmutableMap.of(spot1, instance1, spot2, instance2)); AWSEC2Api client = createMock(AWSEC2Api.class); SpotInstanceApi spotApi = createMock(SpotInstanceApi.class); expect(client.getSpotInstanceApi()).andReturn((Optional) Optional.of(spotApi)); expect(spotApi.describeSpotInstanceRequestsInRegion("us-east-1", "sir-aaaa", "sir-bbbb")).andReturn( ImmutableSet.of(spot1, spot2)); replay(client, spotApi); PresentSpotRequestsAndInstances fn = new PresentSpotRequestsAndInstances(client, converter); assertEquals(fn.apply(ImmutableSet.of(new RegionAndName("us-east-1", "sir-aaaa"), new RegionAndName("us-east-1", "sir-bbbb"))), ImmutableSet.of(instance1, instance2)); verify(client, spotApi); }
@Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); if (any(regionAndIds, Predicates.compose(containsPattern("sir-"), nameFunction()))) return getSpots(regionAndIds); return super.apply(regionAndIds); }
PresentSpotRequestsAndInstances extends PresentInstances { @Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); if (any(regionAndIds, Predicates.compose(containsPattern("sir-"), nameFunction()))) return getSpots(regionAndIds); return super.apply(regionAndIds); } }
PresentSpotRequestsAndInstances extends PresentInstances { @Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); if (any(regionAndIds, Predicates.compose(containsPattern("sir-"), nameFunction()))) return getSpots(regionAndIds); return super.apply(regionAndIds); } @Inject  PresentSpotRequestsAndInstances(AWSEC2Api client, Function<SpotInstanceRequest, AWSRunningInstance> spotConverter); }
PresentSpotRequestsAndInstances extends PresentInstances { @Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); if (any(regionAndIds, Predicates.compose(containsPattern("sir-"), nameFunction()))) return getSpots(regionAndIds); return super.apply(regionAndIds); } @Inject  PresentSpotRequestsAndInstances(AWSEC2Api client, Function<SpotInstanceRequest, AWSRunningInstance> spotConverter); @Override Set<RunningInstance> apply(Set<RegionAndName> regionAndIds); @Override String toString(); }
PresentSpotRequestsAndInstances extends PresentInstances { @Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); if (any(regionAndIds, Predicates.compose(containsPattern("sir-"), nameFunction()))) return getSpots(regionAndIds); return super.apply(regionAndIds); } @Inject  PresentSpotRequestsAndInstances(AWSEC2Api client, Function<SpotInstanceRequest, AWSRunningInstance> spotConverter); @Override Set<RunningInstance> apply(Set<RegionAndName> regionAndIds); @Override String toString();  }