@Override public CqlResult execute_cql3_query(CqlQuery cqlQuery, Compression compression, ConsistencyLevel consistency) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException { long startTime = System.currentTimeMillis(); return KvsProfilingLogger.maybeLog( (KvsProfilingLogger.CallableCheckedException<CqlResult, TException>) () -> client.execute_cql3_query(cqlQuery, compression, consistency), (logger, timer) -> cqlQuery.logSlowResult(logger, timer), (logger, cqlResult) -> { if (cqlResult.getRows() == null) { // different from an empty list logger.log("and returned null rows. The query was started at time {}", LoggingArgs.startTimeMillis(startTime)); } else { logger.log("and returned {} rows. The query was started at time {}", SafeArg.of("numRows", cqlResult.getRows().size()), LoggingArgs.startTimeMillis(startTime)); } }); } }
@Test public void valuesCreatedAtCorrectLogSafetyLevelsForNewCells() { CqlQuery query = CheckAndSetQueries.getQueryForRequest(NEW_CELL_REQUEST); AtomicReference<Object[]> objects = new AtomicReference<>(); query.logSlowResult((format, args) -> objects.set(args), Stopwatch.createStarted()); Object[] loggedObjects = objects.get(); Map<String, Boolean> argumentSafety = Maps.newHashMap(); Arrays.stream(loggedObjects) .forEach(object -> { Arg<?> arg = (Arg) object; argumentSafety.put(arg.getName(), arg.isSafeForLogging()); }); assertThat(argumentSafety) .containsEntry("row", false) .containsEntry("column", false) .containsEntry("cassandraTimestamp", true) .containsEntry("newValue", false) .containsEntry("unsafeTableRef", false) .doesNotContainKey("tableRef"); // the table wasn't marked as safe assertThat(query.toString()) .isEqualTo("INSERT INTO \"ns__table\" (key, column1, column2, value)" + " VALUES (0x616263, 0x313233, -1, 0x70747074) IF NOT EXISTS;"); }
@Test public void valuesCreatedAtCorrectLogSafetyLevelsForUpdates() { CqlQuery query = CheckAndSetQueries.getQueryForRequest(UPDATE_REQUEST); AtomicReference<Object[]> objects = new AtomicReference<>(); query.logSlowResult((format, args) -> objects.set(args), Stopwatch.createStarted()); Object[] loggedObjects = objects.get(); Map<String, Boolean> argumentSafety = Maps.newHashMap(); Arrays.stream(loggedObjects) .forEach(object -> { Arg<?> arg = (Arg) object; argumentSafety.put(arg.getName(), arg.isSafeForLogging()); }); assertThat(argumentSafety) .containsEntry("row", false) .containsEntry("column", false) .containsEntry("cassandraTimestamp", true) .containsEntry("oldValue", false) .containsEntry("newValue", false) .containsEntry("unsafeTableRef", false) .doesNotContainKey("tableRef"); // the table wasn't marked as safe assertThat(query.toString()) .isEqualTo("UPDATE \"ns__table\" SET value=0x626262" + " WHERE key=0x616263 AND column1=0x313233 AND column2=-1 IF value=0x616161;"); } }
@Override public CqlResult execute_cql3_query(CqlQuery cqlQuery, Compression compression, ConsistencyLevel consistency) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException { long startTime = System.currentTimeMillis(); return KvsProfilingLogger.maybeLog( (KvsProfilingLogger.CallableCheckedException<CqlResult, TException>) () -> client.execute_cql3_query(cqlQuery, compression, consistency), (logger, timer) -> cqlQuery.logSlowResult(logger, timer), (logger, cqlResult) -> { if (cqlResult.getRows() == null) { // different from an empty list logger.log("and returned null rows. The query was started at time {}", LoggingArgs.startTimeMillis(startTime)); } else { logger.log("and returned {} rows. The query was started at time {}", SafeArg.of("numRows", cqlResult.getRows().size()), LoggingArgs.startTimeMillis(startTime)); } }); } }