@Test public void testUpdateDriverStatusRetriesExhaust() throws LensException { Configuration conf = new Configuration(); List<LensDriver> drivers = MockQueryContext.getDrivers(conf); MockQueryContext ctx = new MockQueryContext("simulate status failure", new LensConf(), conf, drivers); BackOffRetryHandler waitingHandler = new FibonacciExponentialBackOffRetryHandler(10, 10000, 1000); BackOffRetryHandler noWaitingHandler = new FibonacciExponentialBackOffRetryHandler(10, 0, 0); for (int i = 0; i < 18; i++) { if (i % 2 == 0) { ctx.updateDriverStatus(noWaitingHandler); } else { ctx.updateDriverStatus(waitingHandler); } } try { ctx.updateDriverStatus(noWaitingHandler); fail("Should throw exception"); } catch (LensException e) { } }
public synchronized void updateDriverStatus(BackOffRetryHandler statusUpdateRetryHandler) throws LensException { if (statusUpdateRetryHandler.canTryOpNow(statusUpdateFailures)) { try { getSelectedDriver().updateStatus(this); statusUpdateFailures.clear(); } catch (LensException exc) { if (LensUtil.isSocketException(exc)) { statusUpdateFailures.updateFailure(); if (!statusUpdateRetryHandler.hasExhaustedRetries(statusUpdateFailures)) { log.warn("Exception during update status from driver and update will be tried again at {}", statusUpdateRetryHandler.getOperationNextTime(statusUpdateFailures), exc); return; } } throw exc; } } }
QueryContext extends AbstractQueryContext implements FailureContext { public synchronized void updateDriverStatus(BackOffRetryHandler statusUpdateRetryHandler) throws LensException { if (statusUpdateRetryHandler.canTryOpNow(statusUpdateFailures)) { try { getSelectedDriver().updateStatus(this); statusUpdateFailures.clear(); } catch (LensException exc) { if (LensUtil.isSocketException(exc)) { statusUpdateFailures.updateFailure(); if (!statusUpdateRetryHandler.hasExhaustedRetries(statusUpdateFailures)) { log.warn("Exception during update status from driver and update will be tried again at {}", statusUpdateRetryHandler.getOperationNextTime(statusUpdateFailures), exc); return; } } throw exc; } } } }
QueryContext extends AbstractQueryContext implements FailureContext { public synchronized void updateDriverStatus(BackOffRetryHandler statusUpdateRetryHandler) throws LensException { if (statusUpdateRetryHandler.canTryOpNow(statusUpdateFailures)) { try { getSelectedDriver().updateStatus(this); statusUpdateFailures.clear(); } catch (LensException exc) { if (LensUtil.isSocketException(exc)) { statusUpdateFailures.updateFailure(); if (!statusUpdateRetryHandler.hasExhaustedRetries(statusUpdateFailures)) { log.warn("Exception during update status from driver and update will be tried again at {}", statusUpdateRetryHandler.getOperationNextTime(statusUpdateFailures), exc); return; } } throw exc; } } } QueryContext(String query, String user, LensConf qconf, Configuration conf, Collection<LensDriver> drivers);  QueryContext(PreparedQueryContext prepared, String user, LensConf qconf, Configuration conf);   QueryContext(String userQuery, String user, LensConf qconf, Configuration conf, Collection<LensDriver> drivers,
    LensDriver selectedDriver, boolean mergeDriverConf);   QueryContext(String userQuery, String user, LensConf qconf, Configuration conf, Collection<LensDriver> drivers,
    LensDriver selectedDriver, long submissionTime, boolean mergeDriverConf); }
QueryContext extends AbstractQueryContext implements FailureContext { public synchronized void updateDriverStatus(BackOffRetryHandler statusUpdateRetryHandler) throws LensException { if (statusUpdateRetryHandler.canTryOpNow(statusUpdateFailures)) { try { getSelectedDriver().updateStatus(this); statusUpdateFailures.clear(); } catch (LensException exc) { if (LensUtil.isSocketException(exc)) { statusUpdateFailures.updateFailure(); if (!statusUpdateRetryHandler.hasExhaustedRetries(statusUpdateFailures)) { log.warn("Exception during update status from driver and update will be tried again at {}", statusUpdateRetryHandler.getOperationNextTime(statusUpdateFailures), exc); return; } } throw exc; } } } QueryContext(String query, String user, LensConf qconf, Configuration conf, Collection<LensDriver> drivers);  QueryContext(PreparedQueryContext prepared, String user, LensConf qconf, Configuration conf);   QueryContext(String userQuery, String user, LensConf qconf, Configuration conf, Collection<LensDriver> drivers,
    LensDriver selectedDriver, boolean mergeDriverConf);   QueryContext(String userQuery, String user, LensConf qconf, Configuration conf, Collection<LensDriver> drivers,
    LensDriver selectedDriver, long submissionTime, boolean mergeDriverConf); static QueryContext createContextWithSingleDriver(String query, String user, LensConf qconf,
    Configuration conf, LensDriver driver, String lensSessionPublicId, boolean mergeDriverConf); void initTransientState(); String getResultSetParentDir(); Path getHDFSResultDir(); LensQuery toLensQuery(); boolean isResultAvailableInDriver(); void unSetDriverPersistent(); void setStatusSkippingTransitionTest(final QueryStatus newStatus); synchronized void setStatus(final QueryStatus newStatus); synchronized void updateDriverStatus(BackOffRetryHandler statusUpdateRetryHandler); String getResultHeader(); String getResultFooter(); String getResultEncoding(); String getOuptutFileExtn(); boolean getCompressOutput(); long getMaxResultSplitRows(); boolean splitResultIntoMultipleFiles(); String getClusterUser(); @Override String getLogHandle(); String getQueryHandleString(); void validateTransition(final QueryStatus newStatus); boolean finished(); boolean successful(); boolean executed(); boolean launched(); boolean running(); boolean queued(); ImmutableSet<QueryLaunchingConstraint> getSelectedDriverQueryConstraints(); synchronized void registerDriverResult(LensResultSet result); void setDriverStatus(DriverQueryStatus.DriverQueryState state, String message); String toString(); void setDriverStatus(DriverQueryStatus.DriverQueryState state); void registerStatusUpdateListener(QueryDriverStatusUpdateListener driverStatusUpdateListener); @Override long getLastFailedTime(); @Override int getFailCount(); BackOffRetryHandler<QueryContext> getRetryPolicy(); void extractFailedAttempt(); void extractFailedAttempt(LensDriver selectedDriver); boolean hasTimedout(); }
QueryContext extends AbstractQueryContext implements FailureContext { public synchronized void updateDriverStatus(BackOffRetryHandler statusUpdateRetryHandler) throws LensException { if (statusUpdateRetryHandler.canTryOpNow(statusUpdateFailures)) { try { getSelectedDriver().updateStatus(this); statusUpdateFailures.clear(); } catch (LensException exc) { if (LensUtil.isSocketException(exc)) { statusUpdateFailures.updateFailure(); if (!statusUpdateRetryHandler.hasExhaustedRetries(statusUpdateFailures)) { log.warn("Exception during update status from driver and update will be tried again at {}", statusUpdateRetryHandler.getOperationNextTime(statusUpdateFailures), exc); return; } } throw exc; } } } QueryContext(String query, String user, LensConf qconf, Configuration conf, Collection<LensDriver> drivers);  QueryContext(PreparedQueryContext prepared, String user, LensConf qconf, Configuration conf);   QueryContext(String userQuery, String user, LensConf qconf, Configuration conf, Collection<LensDriver> drivers,
    LensDriver selectedDriver, boolean mergeDriverConf);   QueryContext(String userQuery, String user, LensConf qconf, Configuration conf, Collection<LensDriver> drivers,
    LensDriver selectedDriver, long submissionTime, boolean mergeDriverConf); static QueryContext createContextWithSingleDriver(String query, String user, LensConf qconf,
    Configuration conf, LensDriver driver, String lensSessionPublicId, boolean mergeDriverConf); void initTransientState(); String getResultSetParentDir(); Path getHDFSResultDir(); LensQuery toLensQuery(); boolean isResultAvailableInDriver(); void unSetDriverPersistent(); void setStatusSkippingTransitionTest(final QueryStatus newStatus); synchronized void setStatus(final QueryStatus newStatus); synchronized void updateDriverStatus(BackOffRetryHandler statusUpdateRetryHandler); String getResultHeader(); String getResultFooter(); String getResultEncoding(); String getOuptutFileExtn(); boolean getCompressOutput(); long getMaxResultSplitRows(); boolean splitResultIntoMultipleFiles(); String getClusterUser(); @Override String getLogHandle(); String getQueryHandleString(); void validateTransition(final QueryStatus newStatus); boolean finished(); boolean successful(); boolean executed(); boolean launched(); boolean running(); boolean queued(); ImmutableSet<QueryLaunchingConstraint> getSelectedDriverQueryConstraints(); synchronized void registerDriverResult(LensResultSet result); void setDriverStatus(DriverQueryStatus.DriverQueryState state, String message); String toString(); void setDriverStatus(DriverQueryStatus.DriverQueryState state); void registerStatusUpdateListener(QueryDriverStatusUpdateListener driverStatusUpdateListener); @Override long getLastFailedTime(); @Override int getFailCount(); BackOffRetryHandler<QueryContext> getRetryPolicy(); void extractFailedAttempt(); void extractFailedAttempt(LensDriver selectedDriver); boolean hasTimedout();  }