QueryProcessorWrapper extends AbstractEventProcessor { public void processPrepared(CQLStatement statement, QueryState queryState, QueryOptions options, long startTime, ResultMessage result, ConcurrentLinkedHashMap<MD5Digest, ParsedStatement.Prepared> preparedStatements) { final long execTime = System.currentTimeMillis() - startTime; report(startTime, execTime, null, statement, queryState, options, preparedStatements); } QueryProcessorWrapper(QueryReporter queryReporter, ConnectorConfiguration configuration); void processPrepared(CQLStatement statement, QueryState queryState, QueryOptions options, long startTime,
            ResultMessage result, ConcurrentLinkedHashMap<MD5Digest, ParsedStatement.Prepared> preparedStatements); void process(String queryString, QueryState queryState, QueryOptions options, long startTime,
            ResultMessage result); void storePrepared(String queryString, String keyspace, boolean forThrift,
            ParsedStatement.Prepared prepared,
            ConcurrentLinkedHashMap<MD5Digest, ParsedStatement.Prepared> preparedStatements);  }
@Test public void connector_reporter_does_not_report_internal_query_with_all_data() throws Exception { QueryReporter queryReporter = new QueryReporter() { @Override public void report(Query query) { reportedQuery = query; lock.countDown(); } }; ConnectorConfiguration configuration = new ConnectorConfiguration(); QueryProcessorWrapper wrapper = new QueryProcessorWrapper(queryReporter, configuration); SelectStatement statement = mock(SelectStatement.class); when(statement.keyspace()).thenReturn("test_keyspace"); when(statement.columnFamily()).thenReturn("test_table"); QueryState queryState = mock(QueryState.class); suppress(constructorsDeclaredIn(ClientState.class)); ClientState clientState = ClientState.forInternalCalls(); setFinal(clientState, clientState.getClass().getDeclaredField("isInternal"), true); when(queryState.getClientState()).thenReturn(clientState); QueryOptions options = mock(QueryOptions.class); wrapper.processPrepared(statement, queryState, options, System.currentTimeMillis(), null, null); lock.await(1000, TimeUnit.MILLISECONDS); assertThat(reportedQuery).isEqualTo(null); }
@Test public void wrapper_intercepts_query_with_all_data() throws NoSuchFieldException, SecurityException, Exception { QueryReporter queryReporter = new QueryReporter() { @Override public void report(Query query) { reportedQuery = query; lock.countDown(); } }; ConnectorConfiguration configuration = new ConnectorConfiguration(); QueryProcessorWrapper wrapper = new QueryProcessorWrapper(queryReporter, configuration); SelectStatement statement = mock(SelectStatement.class); when(statement.keyspace()).thenReturn("test_keyspace"); when(statement.columnFamily()).thenReturn("test_table"); QueryState queryState = mock(QueryState.class); suppress(constructorsDeclaredIn(ClientState.class)); ClientState clientState = ClientState.forInternalCalls(); setFinal(clientState, clientState.getClass().getDeclaredField("isInternal"), false); setFinal(clientState, clientState.getClass().getDeclaredField("remoteAddress"), new InetSocketAddress("172.31.0.1", 1000)); when(queryState.getClientState()).thenReturn(clientState); QueryOptions options = mock(QueryOptions.class); when(options.getConsistency()).thenReturn(ConsistencyLevel.ONE); wrapper.processPrepared(statement, queryState, options, System.currentTimeMillis(), null, null); lock.await(1000, TimeUnit.MILLISECONDS); assertThat(reportedQuery.clientAddress()).isEqualTo(new InetSocketAddress("172.31.0.1", 1000).toString()); assertThat(reportedQuery.statementType()).isEqualTo(Query.StatementType.SELECT); assertThat(reportedQuery.keyspace()).isEqualTo("test_keyspace"); assertThat(reportedQuery.tableName()).isEqualTo("test_table"); assertThat(reportedQuery.consistencyLevel()).isEqualTo(Query.ConsistencyLevel.ONE); }