@Override public String toString() { return cqlQuery.toString(); } };
@Override public CqlResult execute_cql3_query(CqlQuery cqlQuery, Compression compression, ConsistencyLevel consistency) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException { ByteBuffer queryBytes = ByteBuffer.wrap(cqlQuery.toString().getBytes(StandardCharsets.UTF_8)); return executeHandlingExceptions(() -> client.execute_cql3_query(queryBytes, compression, consistency)); }
private ArgumentMatcher<CqlQuery> cqlQueryMatcher(String expected) { return argument -> { if (argument == null) { return false; } return expected.equals(argument.toString()); }; }
public void logSlowResult(KvsProfilingLogger.LoggingFunction log, Stopwatch timer) { Object[] allArgs = new Object[args().size() + 3]; allArgs[0] = SafeArg.of("queryFormat", safeQueryFormat()); allArgs[1] = UnsafeArg.of("fullQuery", toString()); allArgs[2] = LoggingArgs.durationMillis(timer); System.arraycopy(args().toArray(), 0, allArgs, 3, args().size()); log.log("A CQL query was slow: queryFormat = [{}], fullQuery = [{}], durationMillis = {}", allArgs); }
@Test public void canGetSelectQuery() { CqlQuery query = CassandraTimestampUtils.constructSelectFromTimestampTableQuery(); assertThat(query.toString()).isEqualTo("SELECT column1, value FROM \"_timestamp\" WHERE key=0x7473;"); }
@Test public void checkAndSetIsUpdateIfEqualIfExpectedIsNotNull() { CqlQuery query = CassandraTimestampUtils.constructCheckAndSetMultipleQuery( ImmutableMap.of(COLUMN_NAME_1, Pair.create(VALUE_1, VALUE_2))); assertThat(query.toString()).contains("UPDATE").contains("IF " + CassandraTimestampUtils.VALUE_COLUMN + "="); }
@Test public void checkAndSetIsInsertIfNotExistsIfExpectedIsNull() { CqlQuery query = CassandraTimestampUtils.constructCheckAndSetMultipleQuery( ImmutableMap.of(COLUMN_NAME_1, Pair.create(null, VALUE_1))); assertThat(query.toString()).contains("INSERT").contains("IF NOT EXISTS;"); }
@Test public void checkAndSetGeneratesBatchedStatements() { CqlQuery query = CassandraTimestampUtils.constructCheckAndSetMultipleQuery( ImmutableMap.of(COLUMN_NAME_1, Pair.create(VALUE_1, VALUE_2), COLUMN_NAME_2, Pair.create(VALUE_2, VALUE_1))); assertThat(query.toString()).contains("BEGIN UNLOGGED BATCH").contains("APPLY BATCH;"); }
@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 String toString() { return cqlQuery.toString(); } };
@Override public CqlResult execute_cql3_query(CqlQuery cqlQuery, Compression compression, ConsistencyLevel consistency) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException { ByteBuffer queryBytes = ByteBuffer.wrap(cqlQuery.toString().getBytes(StandardCharsets.UTF_8)); return executeHandlingExceptions(() -> client.execute_cql3_query(queryBytes, compression, consistency)); }
public void logSlowResult(KvsProfilingLogger.LoggingFunction log, Stopwatch timer) { Object[] allArgs = new Object[args().size() + 3]; allArgs[0] = SafeArg.of("queryFormat", safeQueryFormat()); allArgs[1] = UnsafeArg.of("fullQuery", toString()); allArgs[2] = LoggingArgs.durationMillis(timer); System.arraycopy(args().toArray(), 0, allArgs, 3, args().size()); log.log("A CQL query was slow: queryFormat = [{}], fullQuery = [{}], durationMillis = {}", allArgs); }