@Test public void testProcessSuccessful() { String query = "select * from ks.ts"; queryHandler.process(query, mockQueryState, mockOptions, customPayload); verify(mockAdapter, times(1)).auditRegular(eq(query), eq(mockClientState), eq(Status.ATTEMPT), longThat(isCloseToNow())); verify(mockAdapter, times(1)).auditRegular(eq(query), eq(mockClientState), eq(Status.SUCCEEDED), longThat(isCloseToNow())); verify(mockHandler, times(1)).process(eq(query), eq(mockQueryState), eq(mockOptions), eq(customPayload)); }
@Override public ResultMessage process(String query, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { long timestamp = System.currentTimeMillis(); auditAdapter.auditRegular(query, state.getClientState(), Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.process(query, state, options, customPayload); auditAdapter.auditRegular(query, state.getClientState(), Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditRegular(query, state.getClientState(), Status.FAILED, timestamp); throw e; } }
AuditQueryHandler implements QueryHandler { @Override public ResultMessage process(String query, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { long timestamp = System.currentTimeMillis(); auditAdapter.auditRegular(query, state.getClientState(), Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.process(query, state, options, customPayload); auditAdapter.auditRegular(query, state.getClientState(), Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditRegular(query, state.getClientState(), Status.FAILED, timestamp); throw e; } } }
AuditQueryHandler implements QueryHandler { @Override public ResultMessage process(String query, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { long timestamp = System.currentTimeMillis(); auditAdapter.auditRegular(query, state.getClientState(), Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.process(query, state, options, customPayload); auditAdapter.auditRegular(query, state.getClientState(), Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditRegular(query, state.getClientState(), Status.FAILED, timestamp); throw e; } } AuditQueryHandler();  AuditQueryHandler(QueryHandler queryHandler); @VisibleForTesting  AuditQueryHandler(QueryHandler queryHandler, AuditAdapter auditAdapter); }
AuditQueryHandler implements QueryHandler { @Override public ResultMessage process(String query, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { long timestamp = System.currentTimeMillis(); auditAdapter.auditRegular(query, state.getClientState(), Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.process(query, state, options, customPayload); auditAdapter.auditRegular(query, state.getClientState(), Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditRegular(query, state.getClientState(), Status.FAILED, timestamp); throw e; } } AuditQueryHandler();  AuditQueryHandler(QueryHandler queryHandler); @VisibleForTesting  AuditQueryHandler(QueryHandler queryHandler, AuditAdapter auditAdapter); @Override ResultMessage process(String query, QueryState state, QueryOptions options,
                                 Map<String, ByteBuffer> customPayload); @Override ResultMessage processPrepared(CQLStatement statement, QueryState state, QueryOptions options,
                                         Map<String, ByteBuffer> customPayload); @Override ResultMessage processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options,
                                      Map<String, ByteBuffer> customPayload); @Override Prepared prepare(String query, QueryState state, Map<String, ByteBuffer> customPayload); @Override ParsedStatement.Prepared getPrepared(MD5Digest id); @Override ParsedStatement.Prepared getPreparedForThrift(Integer id); }
AuditQueryHandler implements QueryHandler { @Override public ResultMessage process(String query, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { long timestamp = System.currentTimeMillis(); auditAdapter.auditRegular(query, state.getClientState(), Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.process(query, state, options, customPayload); auditAdapter.auditRegular(query, state.getClientState(), Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditRegular(query, state.getClientState(), Status.FAILED, timestamp); throw e; } } AuditQueryHandler();  AuditQueryHandler(QueryHandler queryHandler); @VisibleForTesting  AuditQueryHandler(QueryHandler queryHandler, AuditAdapter auditAdapter); @Override ResultMessage process(String query, QueryState state, QueryOptions options,
                                 Map<String, ByteBuffer> customPayload); @Override ResultMessage processPrepared(CQLStatement statement, QueryState state, QueryOptions options,
                                         Map<String, ByteBuffer> customPayload); @Override ResultMessage processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options,
                                      Map<String, ByteBuffer> customPayload); @Override Prepared prepare(String query, QueryState state, Map<String, ByteBuffer> customPayload); @Override ParsedStatement.Prepared getPrepared(MD5Digest id); @Override ParsedStatement.Prepared getPreparedForThrift(Integer id);  }