/** * @return the default instance of {@link WaitForOptions} */ public static WaitForOptions defaults() { return new WaitForOptions().setInterval(DEFAULT_INTERVAL).setTimeoutMs(NEVER); }
throw new IllegalStateException("Unrecognized job status: " + jobInfo.getStatus()); }, WaitForOptions.defaults().setInterval(1000)); } catch (IOException e) { LOG.warn("Failed to close job master client: {}", e.toString());
.setInterval(interval)); } catch (InterruptedException e) { Thread.currentThread().interrupt();
/** * Waits for all nodes to be registered. * * @param timeoutMs maximum amount of time to wait, in milliseconds */ public synchronized void waitForAllNodesRegistered(int timeoutMs) throws TimeoutException, InterruptedException { MetaMasterClient metaMasterClient = getMetaMasterClient(); CommonUtils.waitFor("all nodes registered", () -> { try { MasterInfo masterInfo = metaMasterClient.getMasterInfo(Collections.emptySet()); int liveNodeNum = masterInfo.getMasterAddressesList().size() + masterInfo.getWorkerAddressesList().size(); if (liveNodeNum == (mNumMasters + mNumWorkers)) { return true; } else { LOG.info("Master addresses: {}. Worker addresses: {}", masterInfo.getMasterAddressesList(), masterInfo.getWorkerAddressesList()); return false; } } catch (UnavailableException e) { return false; } catch (Exception e) { throw new RuntimeException(e); } }, WaitForOptions.defaults().setInterval(200).setTimeoutMs(timeoutMs)); }
/** * Persists the given file to the under file system. * * @param fs {@link FileSystem} to carry out Alluxio operations * @param fsContext the {@link FileSystemContext} linked to the {@link FileSystem} client * @param uri the uri of the file to persist */ public static void persistFile(final FileSystem fs, final FileSystemContext fsContext, final AlluxioURI uri) throws IOException, TimeoutException, InterruptedException { FileSystemMasterClient client = fsContext.acquireMasterClient(); try { client.scheduleAsyncPersist(uri); } finally { fsContext.releaseMasterClient(client); } CommonUtils.waitFor(String.format("%s to be persisted", uri) , () -> { try { return fs.getStatus(uri).isPersisted(); } catch (Exception e) { Throwables.propagateIfPossible(e); throw new RuntimeException(e); } }, WaitForOptions.defaults().setTimeoutMs(20 * Constants.MINUTE_MS) .setInterval(Constants.SECOND_MS)); }
private void testNthSuccess(int n) throws Exception { CountCondition cond = new CountCondition(n); int intervalMs = 10; WaitForOptions opts = WaitForOptions.defaults().setInterval(intervalMs); long start = System.currentTimeMillis(); CommonUtils.waitFor("", cond, opts); long durationMs = System.currentTimeMillis() - start; assertThat((int) durationMs, Matchers.greaterThanOrEqualTo((n - 1) * intervalMs)); assertEquals(n, cond.invocations()); }
/** * Tests getting and setting fields. */ @Test public void fields() { Random random = new Random(); int interval = random.nextInt(); int timeout = random.nextInt(); WaitForOptions options = WaitForOptions.defaults(); options.setInterval(interval); options.setTimeoutMs(timeout); Assert.assertEquals(interval, options.getInterval()); Assert.assertEquals(timeout, options.getTimeoutMs()); }
stateMachine.getLastPrimaryStartSequenceNumber() == gainPrimacySN, WaitForOptions.defaults() .setInterval(Constants.SECOND_MS) .setTimeoutMs(5 * Constants.SECOND_MS)); } catch (TimeoutException e) {
@Test(expected = TimeoutException.class) public void waitForTimeout() throws Exception { CountCondition cond = new CountCondition(100); WaitForOptions opts = WaitForOptions.defaults().setInterval(3).setTimeoutMs(100); CommonUtils.waitFor("", cond, opts); } }
/** * @return the default instance of {@link WaitForOptions} */ public static WaitForOptions defaults() { return new WaitForOptions().setInterval(DEFAULT_INTERVAL).setTimeoutMs(NEVER) .setThrowOnTimeout(true); }