@Provides @Singleton @Named(TIMEOUT_IMAGE_AVAILABLE) protected Predicate<AtomicReference<Image>> imageAvailable(AtomicImageAvailable statusAvailable, Timeouts timeouts, PollPeriod period) { return timeouts.imageAvailable == 0 ? statusAvailable : retry(statusAvailable, timeouts.imageAvailable, period.pollInitialPeriod, period.pollMaxPeriod); }
protected Set<String> getFormValuesWithKeysPrefixedBy(final String prefix) { Builder<String> values = ImmutableSet.builder(); for (String key : Iterables.filter(formParameters.keySet(), Predicates2.startsWith(prefix))) { values.add(Iterables.get(formParameters.get(key), 0)); } return values.build(); }
@Test(dependsOnMethods = { "testApplyTag", "testApplyTagWithValue" }) protected void testList() { assertTrue(retry(new Predicate<Iterable<Tag>>() { public boolean apply(Iterable<Tag> input) { return api().list().filter(new Predicate<Tag>() { @Override public boolean apply(Tag in) { return in.getResourceId().equals(resource.id); } }).toSet().equals(input); } }, 600, 200, 200, MILLISECONDS).apply(ImmutableSet.of(tag, tag2))); }
@Singleton @Iso3166 @Override public Map<String, Supplier<Set<String>>> get() { Map<String, String> stringsBoundWithRegionOrZonePrefix = filterStringsBoundByName.apply(Predicates.<String>or( Predicates2.startsWith(PROPERTY_REGION), Predicates2.startsWith(PROPERTY_ZONE))); Builder<String, Supplier<Set<String>>> codes = ImmutableMap.builder(); for (String key : ImmutableSet.of(PROPERTY_REGION, PROPERTY_ZONE)) { String regionOrZoneString = stringsBoundWithRegionOrZonePrefix.get(key + "s"); if (regionOrZoneString == null) continue; for (String region : Splitter.on(',').split(regionOrZoneString)) { String isoCodes = stringsBoundWithRegionOrZonePrefix.get(key + "." + region + "." + ISO3166_CODES); if (isoCodes != null) codes.put(region, Suppliers.<Set<String>> ofInstance(ImmutableSet.copyOf(Splitter.on(',') .split(isoCodes)))); } } return codes.build(); } }
protected void assertEventuallyImageStateEquals(ServerImage image, final ServerImageState state) { assertTrue(retry(new Predicate<ServerImage>() { public boolean apply(ServerImage input) { return Iterables.getOnlyElement(api.getImageServices().getImagesById(input.getId())) .getState() == state; } }, 600, 1, SECONDS).apply(image)); } }
@Test void testRetryAlwaysFalseMillis() { // maxWait=3; period=1; maxPeriod defaults to 1*10 // will call at 0, 1, 1+(1*1.5), 3 RepeatedAttemptsPredicate rawPredicate = new RepeatedAttemptsPredicate(Integer.MAX_VALUE); Predicate<String> predicate = retry(rawPredicate, 3, 1, SECONDS); stopwatch.start(); assertFalse(predicate.apply("")); long duration = stopwatch.elapsed(MILLISECONDS); assertOrdered(3000 - EARLY_RETURN_GRACE, duration, 3000 + SLOW_BUILD_SERVER_GRACE); assertCallTimes(rawPredicate.callTimes, 0, 1000, 1000 + 1500, 3000); }
protected void deletePathAndEnsureGone(String path) { checkState(retry(new Predicate<String>() { public boolean apply(String in) { try { clearContainer(in, recursive()); return deleteAndVerifyContainerGone(in); } catch (ContainerNotFoundException e) { return true; } } }, 30000).apply(path), "%s still exists after deleting!", path); }
@Test(dependsOnMethods = { "testApplyTag", "testApplyTagWithValue" }) protected void testList() { assertTrue(retry(new Predicate<Iterable<Tag>>() { public boolean apply(Iterable<Tag> input) { return api().list().filter(new Predicate<Tag>() { @Override public boolean apply(Tag in) { return in.getResourceId().equals(resource.id); } }).toSet().equals(input); } }, 600, 200, 200, MILLISECONDS).apply(ImmutableSet.of(tag, tag2))); }
@Singleton @Iso3166 @Override public Map<String, Supplier<Set<String>>> get() { Map<String, String> stringsBoundWithRegionOrZonePrefix = filterStringsBoundByName.apply(Predicates.<String>or( Predicates2.startsWith(PROPERTY_REGION), Predicates2.startsWith(PROPERTY_ZONE))); Builder<String, Supplier<Set<String>>> codes = ImmutableMap.builder(); for (String key : ImmutableSet.of(PROPERTY_REGION, PROPERTY_ZONE)) { String regionOrZoneString = stringsBoundWithRegionOrZonePrefix.get(key + "s"); if (regionOrZoneString == null) continue; for (String region : Splitter.on(',').split(regionOrZoneString)) { String isoCodes = stringsBoundWithRegionOrZonePrefix.get(key + "." + region + "." + ISO3166_CODES); if (isoCodes != null) codes.put(region, Suppliers.<Set<String>> ofInstance(ImmutableSet.copyOf(Splitter.on(',') .split(isoCodes)))); } } return codes.build(); } }
protected void assertEventuallyImageStateEquals(ServerImage image, final ServerImageState state) { assertTrue(retry(new Predicate<ServerImage>() { public boolean apply(ServerImage input) { return Iterables.getOnlyElement(api.getImageServices().getImagesById(input.getId())) .getState() == state; } }, 600, 1, SECONDS).apply(image)); } }
@Test void testAlwaysFalseMillis() { // maxWait=3; period=1; maxPeriod defaults to 1*10 // will call at 0, 1, 1+(1*1.5), 3 Predicate<String> predicate = retry(Predicates.<String> alwaysFalse(), 3, 1, SECONDS); stopwatch.start(); predicate.apply(""); long duration = stopwatch.elapsed(MILLISECONDS); assertOrdered(3000-EARLY_RETURN_GRACE, duration, 3000+SLOW_BUILD_SERVER_GRACE); }
protected void deletePathAndEnsureGone(String path) { checkState(retry(new Predicate<String>() { public boolean apply(String in) { try { blobUtils.clearContainer(in, recursive()); return deleteAndVerifyContainerGone(in); } catch (ContainerNotFoundException e) { return true; } } }, 30000).apply(path), "%s still exists after deleting!", path); }
@Provides @Singleton @Named(TIMEOUT_NODE_TERMINATED) protected Predicate<AtomicReference<NodeMetadata>> serverTerminated(AtomicNodeTerminated statusTerminated, Timeouts timeouts, PollPeriod period) { return timeouts.nodeTerminated == 0 ? statusTerminated : retry(statusTerminated, timeouts.nodeTerminated, period.pollInitialPeriod, period.pollMaxPeriod); }
@Test public void testFilterWhenNotFound() { assertTrue(retry(new Predicate<Iterable<Subnet>>() { public boolean apply(Iterable<Subnet> input) { return api().filter(new SubnetFilterBuilder().subnetId("subnet-pants").build()) .toSet().equals(input); } }, 600, 200, 200, MILLISECONDS).apply(ImmutableSet.<Subnet> of())); }
@Singleton @Iso3166 @Override public Map<String, Supplier<Set<String>>> get() { Map<String, String> stringsBoundWithRegionOrZonePrefix = filterStringsBoundByName.apply(Predicates.<String>or( Predicates2.startsWith(PROPERTY_REGION), Predicates2.startsWith(PROPERTY_ZONE))); Builder<String, Supplier<Set<String>>> codes = ImmutableMap.builder(); for (String key : ImmutableSet.of(PROPERTY_REGION, PROPERTY_ZONE)) { String regionOrZoneString = stringsBoundWithRegionOrZonePrefix.get(key + "s"); if (regionOrZoneString == null) continue; for (String region : Splitter.on(',').split(regionOrZoneString)) { String isoCodes = stringsBoundWithRegionOrZonePrefix.get(key + "." + region + "." + ISO3166_CODES); if (isoCodes != null) codes.put(region, Suppliers.<Set<String>> ofInstance(ImmutableSet.copyOf(Splitter.on(',') .split(isoCodes)))); } } return codes.build(); } }
private void destroyMachine(final VirtualGuest virtualGuest) { checkState(retry(new Predicate<VirtualGuest>() { public boolean apply(VirtualGuest guest) { guest = api().getVirtualGuest(virtualGuest.getId()); return guest.getActiveTransactionCount() == 0; } }, 5 * 60 * 1000).apply(virtualGuest), "%s still has active transactions!", virtualGuest); assertTrue(api().deleteVirtualGuest(virtualGuest.getId())); }