use of com.google.common.util.concurrent.UncheckedTimeoutException in project zipkin by openzipkin.
the class HttpCallTest method propagatesOnDispatcherThreadWhenFatal.
@Test
public void propagatesOnDispatcherThreadWhenFatal() throws Exception {
mws.enqueue(new MockResponse());
http.newCall(request, b -> {
throw new LinkageError();
}).submit(callback);
SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter();
try {
timeLimiter.callWithTimeout(callback::get, 100, TimeUnit.MILLISECONDS, true);
failBecauseExceptionWasNotThrown(UncheckedTimeoutException.class);
} catch (UncheckedTimeoutException expected) {
}
}
use of com.google.common.util.concurrent.UncheckedTimeoutException in project presto by prestodb.
the class Validator method executeQuery.
private QueryResult executeQuery(String url, String username, String password, Query query, String sql, Duration timeout, Map<String, String> sessionProperties) {
String queryId = null;
try (Connection connection = DriverManager.getConnection(url, username, password)) {
trySetConnectionProperties(query, connection);
for (Map.Entry<String, String> entry : sessionProperties.entrySet()) {
connection.unwrap(PrestoConnection.class).setSessionProperty(entry.getKey(), entry.getValue());
}
try (Statement statement = connection.createStatement()) {
TimeLimiter limiter = new SimpleTimeLimiter();
Stopwatch stopwatch = Stopwatch.createStarted();
Statement limitedStatement = limiter.newProxy(statement, Statement.class, timeout.toMillis(), TimeUnit.MILLISECONDS);
if (explainOnly) {
sql = "EXPLAIN " + sql;
}
long start = System.nanoTime();
PrestoStatement prestoStatement = limitedStatement.unwrap(PrestoStatement.class);
ProgressMonitor progressMonitor = new ProgressMonitor();
prestoStatement.setProgressMonitor(progressMonitor);
try {
boolean isSelectQuery = limitedStatement.execute(sql);
List<List<Object>> results = null;
if (isSelectQuery) {
results = limiter.callWithTimeout(getResultSetConverter(limitedStatement.getResultSet()), timeout.toMillis() - stopwatch.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, true);
} else {
results = ImmutableList.of(ImmutableList.of(limitedStatement.getLargeUpdateCount()));
}
prestoStatement.clearProgressMonitor();
QueryStats queryStats = progressMonitor.getFinalQueryStats();
if (queryStats == null) {
throw new VerifierException("Cannot fetch query stats");
}
Duration queryCpuTime = new Duration(queryStats.getCpuTimeMillis(), TimeUnit.MILLISECONDS);
queryId = queryStats.getQueryId();
return new QueryResult(State.SUCCESS, null, nanosSince(start), queryCpuTime, queryId, results);
} catch (AssertionError e) {
if (e.getMessage().startsWith("unimplemented type:")) {
return new QueryResult(State.INVALID, null, null, null, queryId, ImmutableList.of());
}
throw e;
} catch (SQLException | VerifierException e) {
throw e;
} catch (UncheckedTimeoutException e) {
return new QueryResult(State.TIMEOUT, null, null, null, queryId, ImmutableList.of());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Throwables.propagate(e);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
} catch (SQLException e) {
Exception exception = e;
if (("Error executing query".equals(e.getMessage()) || "Error fetching results".equals(e.getMessage())) && (e.getCause() instanceof Exception)) {
exception = (Exception) e.getCause();
}
State state = isPrestoQueryInvalid(e) ? State.INVALID : State.FAILED;
return new QueryResult(state, exception, null, null, null, null);
} catch (VerifierException e) {
return new QueryResult(State.TOO_MANY_ROWS, e, null, null, null, null);
}
}
use of com.google.common.util.concurrent.UncheckedTimeoutException in project graylog2-server by Graylog2.
the class LdapConnector method connect.
public LdapNetworkConnection connect(LdapConnectionConfig config) throws LdapException {
final LdapNetworkConnection connection = new LdapNetworkConnection(config);
connection.setTimeOut(connectionTimeout);
if (LOG.isTraceEnabled()) {
LOG.trace("Connecting to LDAP server {}:{}, binding with user {}", config.getLdapHost(), config.getLdapPort(), config.getName());
}
// this will perform an anonymous bind if there were no system credentials
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("ldap-connector-%d").build();
final SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter(Executors.newSingleThreadExecutor(threadFactory));
@SuppressWarnings("unchecked") final Callable<Boolean> timeLimitedConnection = timeLimiter.newProxy(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return connection.connect();
}
}, Callable.class, connectionTimeout, TimeUnit.MILLISECONDS);
try {
final Boolean connected = timeLimitedConnection.call();
if (!connected) {
return null;
}
} catch (UncheckedTimeoutException e) {
LOG.error("Timed out connecting to LDAP server", e);
throw new LdapException("Could not connect to LDAP server", e.getCause());
} catch (LdapException e) {
throw e;
} catch (Exception e) {
// unhandled different exception, should really not happen here.
throw new LdapException("Unexpected error connecting to LDAP", e);
}
connection.bind();
return connection;
}
Aggregations