@Test public void testExecuteAsync() throws Exception { createTable("execute_async_test"); insertData("execute_async_test"); final String query = "SELECT * FROM execute_async_test"; QueryContext context = createQueryContext(query); System.out.println("@@@ Test_execute_async:" + context.getQueryHandle()); final CountDownLatch listenerNotificationLatch = new CountDownLatch(1); QueryCompletionListener listener = new QueryCompletionListener() { @Override public void onError(QueryHandle handle, String error) { fail("Query failed " + handle + " message" + error); } @Override public void onCompletion(QueryHandle handle) { System.out.println("@@@@ Query is complete " + handle); listenerNotificationLatch.countDown(); } }; executeAsync(context); QueryHandle handle = context.getQueryHandle(); driver.registerForCompletionNotification(context, 0, listener); while (true) { driver.updateStatus(context); System.out.println("Query: " + handle + " Status: " + context.getDriverStatus()); if (context.getDriverStatus().isFinished()) { assertEquals(context.getDriverStatus().getState(), DriverQueryState.SUCCESSFUL); assertEquals(context.getDriverStatus().getProgress(), 1.0); break; } Thread.sleep(500); } assertTrue(context.getDriverStatus().getDriverStartTime() > 0); assertTrue(context.getDriverStatus().getDriverFinishTime() > 0); try { listenerNotificationLatch.await(1, TimeUnit.SECONDS); } catch (Exception e) { fail("Query completion listener was not notified - " + e.getMessage()); log.error("Query completion listener was not notified.", e); } LensResultSet grs = driver.fetchResultSet(context); for (int i = 0; i < 5; i++) { assertTrue(grs == driver.fetchResultSet(context)); } assertNotNull(grs); if (grs instanceof InMemoryResultSet) { InMemoryResultSet rs = (InMemoryResultSet) grs; LensResultSetMetadata rsMeta = rs.getMetadata(); assertEquals(rsMeta.getColumns().size(), 1); ColumnDescriptor col1 = rsMeta.getColumns().get(0); assertEquals(col1.getTypeName().toLowerCase(), "int"); assertEquals(col1.getName(), "ID"); System.out.println("Matched metadata"); while (rs.hasNext()) { List<Object> vals = rs.next().getValues(); assertEquals(vals.size(), 1); assertEquals(vals.get(0).getClass(), Integer.class); } driver.closeQuery(handle); } else { fail("Only in memory result set is supported as of now"); } }
@Override public void executeAsync(QueryContext context) throws LensException { checkConfigured(); String rewrittenQuery = rewriteQuery(context); JdbcQueryContext jdbcCtx = new JdbcQueryContext(context); jdbcCtx.setRewrittenQuery(rewrittenQuery); try { Future<QueryResult> future = asyncQueryPool.submit(new QueryCallable(jdbcCtx, logSegregationContext)); jdbcCtx.setResultFuture(future); } catch (RejectedExecutionException e) { log.error("Query execution rejected: {} reason:{}", context.getQueryHandle(), e.getMessage(), e); throw new LensException("Query execution rejected: " + context.getQueryHandle() + " reason:" + e.getMessage(), e); } queryContextMap.put(context.getQueryHandle(), jdbcCtx); log.info("{} ExecuteAsync: {}", getFullyQualifiedName(), context.getQueryHandle()); }
JDBCDriver extends AbstractLensDriver { @Override public void executeAsync(QueryContext context) throws LensException { checkConfigured(); String rewrittenQuery = rewriteQuery(context); JdbcQueryContext jdbcCtx = new JdbcQueryContext(context); jdbcCtx.setRewrittenQuery(rewrittenQuery); try { Future<QueryResult> future = asyncQueryPool.submit(new QueryCallable(jdbcCtx, logSegregationContext)); jdbcCtx.setResultFuture(future); } catch (RejectedExecutionException e) { log.error("Query execution rejected: {} reason:{}", context.getQueryHandle(), e.getMessage(), e); throw new LensException("Query execution rejected: " + context.getQueryHandle() + " reason:" + e.getMessage(), e); } queryContextMap.put(context.getQueryHandle(), jdbcCtx); log.info("{} ExecuteAsync: {}", getFullyQualifiedName(), context.getQueryHandle()); } }
JDBCDriver extends AbstractLensDriver { @Override public void executeAsync(QueryContext context) throws LensException { checkConfigured(); String rewrittenQuery = rewriteQuery(context); JdbcQueryContext jdbcCtx = new JdbcQueryContext(context); jdbcCtx.setRewrittenQuery(rewrittenQuery); try { Future<QueryResult> future = asyncQueryPool.submit(new QueryCallable(jdbcCtx, logSegregationContext)); jdbcCtx.setResultFuture(future); } catch (RejectedExecutionException e) { log.error("Query execution rejected: {} reason:{}", context.getQueryHandle(), e.getMessage(), e); throw new LensException("Query execution rejected: " + context.getQueryHandle() + " reason:" + e.getMessage(), e); } queryContextMap.put(context.getQueryHandle(), jdbcCtx); log.info("{} ExecuteAsync: {}", getFullyQualifiedName(), context.getQueryHandle()); }  }
JDBCDriver extends AbstractLensDriver { @Override public void executeAsync(QueryContext context) throws LensException { checkConfigured(); String rewrittenQuery = rewriteQuery(context); JdbcQueryContext jdbcCtx = new JdbcQueryContext(context); jdbcCtx.setRewrittenQuery(rewrittenQuery); try { Future<QueryResult> future = asyncQueryPool.submit(new QueryCallable(jdbcCtx, logSegregationContext)); jdbcCtx.setResultFuture(future); } catch (RejectedExecutionException e) { log.error("Query execution rejected: {} reason:{}", context.getQueryHandle(), e.getMessage(), e); throw new LensException("Query execution rejected: " + context.getQueryHandle() + " reason:" + e.getMessage(), e); } queryContextMap.put(context.getQueryHandle(), jdbcCtx); log.info("{} ExecuteAsync: {}", getFullyQualifiedName(), context.getQueryHandle()); }  @Override void configure(Configuration conf, String driverType, String driverName); void init(); QueryCost calculateQueryCost(AbstractQueryContext qctx); @Override QueryCost estimate(AbstractQueryContext qctx); @Override DriverQueryPlan explain(AbstractQueryContext explainCtx); void validate(AbstractQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); @Override LensResultSet execute(QueryContext context); @Override void executeAsync(QueryContext context); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override void readExternal(ObjectInput arg0); @Override void writeExternal(ObjectOutput arg0); @Override StatusUpdateMethod getStatusUpdateMethod(); }
JDBCDriver extends AbstractLensDriver { @Override public void executeAsync(QueryContext context) throws LensException { checkConfigured(); String rewrittenQuery = rewriteQuery(context); JdbcQueryContext jdbcCtx = new JdbcQueryContext(context); jdbcCtx.setRewrittenQuery(rewrittenQuery); try { Future<QueryResult> future = asyncQueryPool.submit(new QueryCallable(jdbcCtx, logSegregationContext)); jdbcCtx.setResultFuture(future); } catch (RejectedExecutionException e) { log.error("Query execution rejected: {} reason:{}", context.getQueryHandle(), e.getMessage(), e); throw new LensException("Query execution rejected: " + context.getQueryHandle() + " reason:" + e.getMessage(), e); } queryContextMap.put(context.getQueryHandle(), jdbcCtx); log.info("{} ExecuteAsync: {}", getFullyQualifiedName(), context.getQueryHandle()); }  @Override void configure(Configuration conf, String driverType, String driverName); void init(); QueryCost calculateQueryCost(AbstractQueryContext qctx); @Override QueryCost estimate(AbstractQueryContext qctx); @Override DriverQueryPlan explain(AbstractQueryContext explainCtx); void validate(AbstractQueryContext pContext); @Override void prepare(PreparedQueryContext pContext); @Override DriverQueryPlan explainAndPrepare(PreparedQueryContext pContext); @Override void closePreparedQuery(QueryPrepareHandle handle); @Override LensResultSet execute(QueryContext context); @Override void executeAsync(QueryContext context); @Override void updateStatus(QueryContext context); @Override void closeResultSet(QueryHandle handle); @Override boolean cancelQuery(QueryHandle handle); @Override void closeQuery(QueryHandle handle); @Override void close(); @Override void registerDriverEventListener(LensEventListener<DriverEvent> driverEventListener); @Override void readExternal(ObjectInput arg0); @Override void writeExternal(ObjectOutput arg0); @Override StatusUpdateMethod getStatusUpdateMethod(); static final AtomicInteger THID; }