use of org.apache.cassandra.fql.FullQueryLogger.Batch in project cassandra by apache.
the class FullQueryLoggerTest method assertRoundTripBatch.
private void assertRoundTripBatch(@Nullable String keyspace) {
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
ExcerptTailer tailer = queue.createTailer();
assertTrue(tailer.readDocument(wire -> {
assertEquals(0, wire.read(VERSION).int16());
assertEquals(BATCH, wire.read(TYPE).text());
assertEquals(1L, wire.read(QUERY_START_TIME).int64());
ProtocolVersion protocolVersion = ProtocolVersion.decode(wire.read(PROTOCOL_VERSION).int32(), true);
assertEquals(ProtocolVersion.CURRENT, protocolVersion);
QueryOptions queryOptions = QueryOptions.codec.decode(Unpooled.wrappedBuffer(wire.read(QUERY_OPTIONS).bytes()), protocolVersion);
compareQueryOptions(QueryOptions.DEFAULT, queryOptions);
assertEquals(Long.MIN_VALUE, wire.read(GENERATED_TIMESTAMP).int64());
assertEquals(Integer.MIN_VALUE, wire.read(GENERATED_NOW_IN_SECONDS).int32());
assertEquals(keyspace, wire.read(FullQueryLogger.KEYSPACE).text());
assertEquals("UNLOGGED", wire.read(BATCH_TYPE).text());
ValueIn in = wire.read(QUERIES);
assertEquals(2, in.int32());
assertEquals("foo1", in.text());
assertEquals("foo2", in.text());
in = wire.read(VALUES);
assertEquals(2, in.int32());
assertEquals(2, in.int32());
assertTrue(Arrays.equals(new byte[1], in.bytes()));
assertTrue(Arrays.equals(new byte[2], in.bytes()));
assertEquals(0, in.int32());
}));
}
}
use of org.apache.cassandra.fql.FullQueryLogger.Batch in project cassandra by apache.
the class FullQueryLoggerTest method testBatchWeight.
@Test
public void testBatchWeight() {
// An empty batch should have weight
Batch batch = new Batch(Type.UNLOGGED, new ArrayList<>(), new ArrayList<>(), QueryOptions.DEFAULT, queryState(), 1);
assertTrue(batch.weight() > 0);
// make sure that a batch with keyspace set has a higher weight
Batch batch2 = new Batch(Type.UNLOGGED, new ArrayList<>(), new ArrayList<>(), QueryOptions.DEFAULT, queryState("ABABA"), 1);
assertTrue(batch.weight() < batch2.weight());
StringBuilder sb = new StringBuilder();
for (int ii = 0; ii < 1024 * 1024; ii++) {
sb.append('a');
}
// The weight of the list containing queries should be reflected
List<String> bigList = new ArrayList(100000);
for (int ii = 0; ii < 100000; ii++) {
bigList.add("");
}
batch = new Batch(Type.UNLOGGED, bigList, new ArrayList<>(), QueryOptions.DEFAULT, queryState(), 1);
assertTrue(batch.weight() > ObjectSizes.measureDeep(bigList));
// The size of the query should be reflected
bigList = new ArrayList(1);
bigList.add(sb.toString());
batch = new Batch(Type.UNLOGGED, bigList, new ArrayList<>(), QueryOptions.DEFAULT, queryState(), 1);
assertTrue(batch.weight() > ObjectSizes.measureDeep(bigList));
bigList = null;
// The size of the list of values should be reflected
List<List<ByteBuffer>> bigValues = new ArrayList<>(100000);
for (int ii = 0; ii < 100000; ii++) {
bigValues.add(new ArrayList<>(0));
}
bigValues.get(0).add(ByteBuffer.allocate(1024 * 1024 * 5));
batch = new Batch(Type.UNLOGGED, new ArrayList<>(), bigValues, QueryOptions.DEFAULT, queryState(), 1);
assertTrue(batch.weight() > ObjectSizes.measureDeep(bigValues));
// As should the size of the values
QueryOptions largeOptions = QueryOptions.forInternalCalls(Arrays.asList(ByteBuffer.allocate(1024 * 1024)));
batch = new Batch(Type.UNLOGGED, new ArrayList<>(), new ArrayList<>(), largeOptions, queryState(), 1);
assertTrue(batch.weight() > 1024 * 1024);
}
Aggregations