@Test public void testProcessBatchSuccessful() { queryHandler.processBatch(mockBatchStatement, mockQueryState, mockBatchOptions, customPayload); verify(mockAdapter, times(1)).auditBatch(eq(mockBatchStatement), any(UUID.class), eq(mockClientState), eq(mockBatchOptions), eq(Status.ATTEMPT), longThat(isCloseToNow())); verify(mockAdapter, times(1)).auditBatch(eq(mockBatchStatement), any(UUID.class), eq(mockClientState), eq(mockBatchOptions), eq(Status.SUCCEEDED), longThat(isCloseToNow())); verify(mockHandler, times(1)).processBatch(eq(mockBatchStatement), eq(mockQueryState), eq(mockBatchOptions), eq(customPayload)); }
@Override public ResultMessage processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { UUID uuid = UUIDGen.getTimeUUID(); long timestamp = System.currentTimeMillis(); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.processBatch(statement, state, options, customPayload); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.FAILED, timestamp); throw e; } }
AuditQueryHandler implements QueryHandler { @Override public ResultMessage processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { UUID uuid = UUIDGen.getTimeUUID(); long timestamp = System.currentTimeMillis(); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.processBatch(statement, state, options, customPayload); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.FAILED, timestamp); throw e; } } }
AuditQueryHandler implements QueryHandler { @Override public ResultMessage processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { UUID uuid = UUIDGen.getTimeUUID(); long timestamp = System.currentTimeMillis(); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.processBatch(statement, state, options, customPayload); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.FAILED, timestamp); throw e; } } AuditQueryHandler();  AuditQueryHandler(QueryHandler queryHandler); @VisibleForTesting  AuditQueryHandler(QueryHandler queryHandler, AuditAdapter auditAdapter); }
AuditQueryHandler implements QueryHandler { @Override public ResultMessage processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { UUID uuid = UUIDGen.getTimeUUID(); long timestamp = System.currentTimeMillis(); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.processBatch(statement, state, options, customPayload); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, 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 processBatch(BatchStatement statement, QueryState state, BatchQueryOptions options, Map<String, ByteBuffer> customPayload) throws RequestExecutionException, RequestValidationException { UUID uuid = UUIDGen.getTimeUUID(); long timestamp = System.currentTimeMillis(); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.ATTEMPT, timestamp); try { ResultMessage result = wrappedQueryHandler.processBatch(statement, state, options, customPayload); auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, Status.SUCCEEDED, timestamp); return result; } catch (RuntimeException e) { auditAdapter.auditBatch(statement, uuid, state.getClientState(), options, 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);  }