@SuppressWarnings("unchecked") @Test public void testWhenInstancesPresentSingleCall() { AWSEC2Api client = createMock(AWSEC2Api.class); AWSInstanceApi instanceApi = createMock(AWSInstanceApi.class); Function<SpotInstanceRequest, AWSRunningInstance> converter = createMock(Function.class); expect(client.getInstanceApi()).andReturn((Optional) Optional.of(instanceApi)); expect(instanceApi.describeInstancesInRegion("us-east-1", "i-aaaa", "i-bbbb")).andReturn( Set.class.cast(ImmutableSet.of(Reservation.<AWSRunningInstance> builder().region("us-east-1") .instances(ImmutableSet.of(instance1, instance2)).build()))); replay(client, instanceApi, converter); PresentSpotRequestsAndInstances fn = new PresentSpotRequestsAndInstances(client, converter); assertEquals(fn.apply(ImmutableSet.of(new RegionAndName("us-east-1", "i-aaaa"), new RegionAndName("us-east-1", "i-bbbb"))), ImmutableSet.of(instance1, instance2)); verify(client, instanceApi, converter); }
@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();  }