use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class BinAuditLoggerTest method testSelectRoundTripQuery.
@Test
public void testSelectRoundTripQuery() throws Throwable {
createTable("CREATE TABLE %s (id int primary key, v1 text, v2 text)");
execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 1, "Apache", "Cassandra");
execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 2, "trace", "test");
String cql = "SELECT id, v1, v2 FROM " + KEYSPACE + '.' + currentTable() + " WHERE id = ?";
Session session = sessionNet();
PreparedStatement pstmt = session.prepare(cql);
ResultSet rs = session.execute(pstmt.bind(1));
assertEquals(1, rs.all().size());
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
ExcerptTailer tailer = queue.createTailer();
assertTrue(tailer.readDocument(wire -> {
assertEquals(0L, wire.read("version").int16());
assertEquals("audit", wire.read("type").text());
assertThat(wire.read("message").text(), containsString(AuditLogEntryType.PREPARE_STATEMENT.toString()));
}));
assertTrue(tailer.readDocument(wire -> {
assertEquals(0L, wire.read("version").int16());
assertEquals("audit", wire.read("type").text());
assertThat(wire.read("message").text(), containsString(AuditLogEntryType.SELECT.toString()));
}));
assertFalse(tailer.readDocument(wire -> {
}));
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class Replay method replay.
public static void replay(String keyspace, List<String> arguments, List<String> targetHosts, List<File> resultPaths, String queryStorePath, boolean replayDDLStatements) {
// how many fql queries should we read in to memory to be able to sort them?
int readAhead = 200;
List<ChronicleQueue> readQueues = null;
List<FQLQueryIterator> iterators = null;
List<Predicate<FQLQuery>> filters = new ArrayList<>();
if (keyspace != null)
filters.add(fqlQuery -> fqlQuery.keyspace() == null || fqlQuery.keyspace().equals(keyspace));
if (!replayDDLStatements)
filters.add(fqlQuery -> {
boolean notDDLStatement = !fqlQuery.isDDLStatement();
if (!notDDLStatement)
logger.info("Excluding DDL statement from replaying: {}", ((FQLQuery.Single) fqlQuery).query);
return notDDLStatement;
});
try {
readQueues = arguments.stream().map(s -> SingleChronicleQueueBuilder.single(s).readOnly(true).build()).collect(Collectors.toList());
iterators = readQueues.stream().map(ChronicleQueue::createTailer).map(tailer -> new FQLQueryIterator(tailer, readAhead)).collect(Collectors.toList());
try (MergeIterator<FQLQuery, List<FQLQuery>> iter = MergeIterator.get(iterators, FQLQuery::compareTo, new Reducer());
QueryReplayer replayer = new QueryReplayer(iter, targetHosts, resultPaths, filters, queryStorePath)) {
replayer.replay();
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (iterators != null)
iterators.forEach(AbstractIterator::close);
if (readQueues != null)
readQueues.forEach(Closeable::close);
}
}
use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class FQLReplayTest method testQueryIterator.
@Test
public void testQueryIterator() throws IOException {
File f = generateQueries(100, false);
int queryCount = 0;
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(f).build();
FQLQueryIterator iter = new FQLQueryIterator(queue.createTailer(), 1)) {
long last = -1;
while (iter.hasNext()) {
FQLQuery q = iter.next();
assertTrue(q.queryStartTime >= last);
last = q.queryStartTime;
queryCount++;
}
}
assertEquals(100, queryCount);
}
use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class FQLReplayTest method readResultFile.
private static List<Pair<FQLQuery, ResultHandler.ComparableResultSet>> readResultFile(File dir, File queryDir) {
List<Pair<FQLQuery, ResultHandler.ComparableResultSet>> resultSets = new ArrayList<>();
try (ChronicleQueue q = SingleChronicleQueueBuilder.single(dir).build();
ChronicleQueue queryQ = SingleChronicleQueueBuilder.single(queryDir).build()) {
ExcerptTailer queryTailer = queryQ.createTailer();
FQLQueryReader queryReader = new FQLQueryReader();
Compare.StoredResultSetIterator resultSetIterator = new Compare.StoredResultSetIterator(q.createTailer());
// we need to materialize the rows in-memory to compare them easier in these tests
while (resultSetIterator.hasNext()) {
ResultHandler.ComparableResultSet resultSetFromDisk = resultSetIterator.next();
Iterator<ResultHandler.ComparableRow> rowIterFromDisk = resultSetFromDisk.iterator();
queryTailer.readDocument(queryReader);
FQLQuery query = queryReader.getQuery();
List<ResultHandler.ComparableRow> rows = new ArrayList<>();
while (rowIterFromDisk.hasNext()) {
rows.add(rowIterFromDisk.next());
}
resultSets.add(Pair.create(query, new StoredResultSet(resultSetFromDisk.getColumnDefinitions(), resultSetIterator.hasNext(), resultSetFromDisk.wasFailed(), resultSetFromDisk.getFailureException(), rows::iterator)));
}
}
return resultSets;
}
use of net.openhft.chronicle.queue.ChronicleQueue in project cassandra by apache.
the class FQLReplayTest method testOrderedReplay.
@Test
public void testOrderedReplay() throws IOException {
File f = generateQueries(100, true);
int queryCount = 0;
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(f).build();
FQLQueryIterator iter = new FQLQueryIterator(queue.createTailer(), 101)) {
long last = -1;
while (iter.hasNext()) {
FQLQuery q = iter.next();
assertTrue(q.queryStartTime >= last);
last = q.queryStartTime;
queryCount++;
}
}
assertEquals(100, queryCount);
}
Aggregations