/** * like {@link #retry(Predicate, long, long, long, TimeUnit)} where {@code maxPeriod} is 10x {@code period} */ public static <T> Predicate<T> retry(Predicate<T> findOrBreak, long timeout, long period, TimeUnit unit) { return retry(findOrBreak, timeout, period, period * 10l, unit); }
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); }
@Provides @Singleton protected Predicate<String> jobComplete(JobComplete jobComplete) { return retry(jobComplete, 1200, 1, 5, SECONDS); }
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_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); }
@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); }
@Provides @Singleton protected Predicate<DriveInfo> supplyDriveUnclaimed(DriveClaimed driveClaimed, Timeouts timeouts) { return retry(Predicates.not(driveClaimed), timeouts.nodeRunning, 1000, MILLISECONDS); } }
@Provides @Singleton @Named(TIMEOUT_SCRIPT_COMPLETE) protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero statusRunning, Timeouts timeouts) { return timeouts.scriptComplete == 0 ? not(statusRunning) : retry(not(statusRunning), timeouts.scriptComplete); }
/** * Wait until a Volume is Available. * * @param volumeApi The VolumeApi in the zone where your Volume resides. * @return RetryablePredicate That will check the status every 5 seconds for a maxiumum of 10 minutes. */ public static Predicate<Volume> awaitAvailable(VolumeApi volumeApi) { StatusUpdatedPredicate statusPredicate = new StatusUpdatedPredicate(volumeApi, Volume.Status.AVAILABLE); return retry(statusPredicate, 600, 5, 5, SECONDS); }
/** * Wait until a Volume no longer exists. * * @param volumeApi The VolumeApi in the zone where your Volume resides. * @return RetryablePredicate That will check the whether the Volume exists * every 5 seconds for a maxiumum of 10 minutes. */ public static Predicate<Volume> awaitDeleted(VolumeApi volumeApi) { DeletedPredicate deletedPredicate = new DeletedPredicate(volumeApi); return retry(deletedPredicate, 600, 5, 5, SECONDS); }
public static Predicate<Volume> awaitStatus( VolumeApi volumeApi, Volume.Status status, long maxWaitInSec, long periodInSec) { StatusUpdatedPredicate statusPredicate = new StatusUpdatedPredicate(volumeApi, status); return retry(statusPredicate, maxWaitInSec, periodInSec, periodInSec, SECONDS); }
/** * Wait until a Snapshot is Available. * * @param snapshotApi The SnapshotApi in the zone where your Snapshot resides. * @return RetryablePredicate That will check the status every 5 seconds for a maxiumum of 20 minutes. */ public static Predicate<Snapshot> awaitAvailable(SnapshotApi snapshotApi) { StatusUpdatedPredicate statusPredicate = new StatusUpdatedPredicate(snapshotApi, Volume.Status.AVAILABLE); return retry(statusPredicate, 1200, 5, 5, SECONDS); }
@Inject protected GoGridComputeServiceAdapter(GoGridClient client, Function<Hardware, String> sizeToRam, Timeouts timeouts) { this.client = checkNotNull(client, "client"); this.sizeToRam = checkNotNull(sizeToRam, "sizeToRam"); this.serverLatestJobCompleted = retry(new ServerLatestJobCompleted(client.getJobServices()), timeouts.nodeRunning * 9l / 10l); this.serverLatestJobCompletedShort = retry(new ServerLatestJobCompleted(client.getJobServices()), timeouts.nodeRunning * 1l / 10l); }
@Provides @Singleton protected Predicate<String> jobComplete(JobComplete jobComplete) { return retry(jobComplete, 1200, 1, 5, SECONDS); }
@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())); }
@Test(dependsOnMethods = "testCreateArchive") public void testResizeArchive() throws Exception { archiveApi.resize(archiveUser, 20); assertTrue(retry(new Predicate<String>() { public boolean apply(String value) { return archiveApi.get(archiveUser) != null && value.equals(archiveApi.get(archiveUser).getTotalSize()); } }, 30, 1, SECONDS).apply("20 GB")); }
@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); }
@BeforeClass(groups = { "integration", "live" }) public void setupContext() { super.setupContext(); Injector injector = view.utils().injector(); client = injector.getInstance(EC2Client.class); sshFactory = injector.getInstance(SshClient.Factory.class); runningTester = retry(new InstanceStateRunning(client), 180, 5,SECONDS); hasIpTester = retry(new InstanceHasIpAddress(client), 180, 5, SECONDS); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); socketTester = retry(socketOpen, 180, 1, SECONDS); }
@BeforeClass(groups = { "integration", "live" }) public void setup() { super.setup(); archiveApi = api.getArchiveApi(); archiveUser = identity.toLowerCase() + "_test9"; archiveCounter = retry(new Predicate<Integer>() { public boolean apply(Integer value) { return archiveApi.list().size() == value.intValue(); } }, 30, 1, SECONDS); }
protected void createDomain(String domain) { final DomainApi domainApi = api.getDomainApi(); int before = domainApi.list().size(); domainApi.create(domain); Predicate<Integer> result = retry(new Predicate<Integer>() { public boolean apply(Integer value) { return domainApi.list().size() == value.intValue(); } }, 30, 1, SECONDS); assertTrue(result.apply(before + 1)); }