Search in sources :

Example 1 with CqlQuery

use of com.palantir.atlasdb.keyvalue.cassandra.CqlQuery in project atlasdb by palantir.

the class CheckAndSetQueriesTest method valuesCreatedAtCorrectLogSafetyLevelsForUpdates.

@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 = new HashMap<>();
    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(// the table wasn't marked as safe
    "tableRef");
    assertThat(query.toString()).isEqualTo("UPDATE \"ns__table\" SET value=0x626262" + " WHERE key=0x616263 AND column1=0x313233 AND column2=-1 IF value=0x616161;");
}
Also used : HashMap(java.util.HashMap) Arg(com.palantir.logsafe.Arg) AtomicReference(java.util.concurrent.atomic.AtomicReference) CqlQuery(com.palantir.atlasdb.keyvalue.cassandra.CqlQuery) Test(org.junit.Test)

Example 2 with CqlQuery

use of com.palantir.atlasdb.keyvalue.cassandra.CqlQuery in project atlasdb by palantir.

the class CheckAndSetQueriesTest method valuesCreatedAtCorrectLogSafetyLevelsForNewCells.

@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 = new HashMap<>();
    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(// the table wasn't marked as safe
    "tableRef");
    assertThat(query.toString()).isEqualTo("INSERT INTO \"ns__table\" (key, column1, column2, value)" + " VALUES (0x616263, 0x313233, -1, 0x70747074) IF NOT EXISTS;");
}
Also used : HashMap(java.util.HashMap) Arg(com.palantir.logsafe.Arg) AtomicReference(java.util.concurrent.atomic.AtomicReference) CqlQuery(com.palantir.atlasdb.keyvalue.cassandra.CqlQuery) Test(org.junit.Test)

Aggregations

CqlQuery (com.palantir.atlasdb.keyvalue.cassandra.CqlQuery)2 Arg (com.palantir.logsafe.Arg)2 HashMap (java.util.HashMap)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.Test)2