Tests for warning and error lines in logfile when user executes big batch (above preconfigured thresholds in scylla.yaml). Signed-off-by: Lukasz Sojka <lukasz.sojka@scylladb.com> Closes #10232
53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2022-present ScyllaDB
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
#############################################################################
|
|
# Tests for batch operations
|
|
#############################################################################
|
|
from cassandra import InvalidRequest
|
|
|
|
from util import new_test_table
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def table1(cql, test_keyspace):
|
|
with new_test_table(cql, test_keyspace, "k int primary key, t text") as table:
|
|
yield table
|
|
|
|
|
|
def generate_big_batch(table, size_in_kb):
|
|
statements = [f"INSERT INTO {table} (k, t) VALUES ({idx}, '{'x' * 743}')" for idx in range(size_in_kb)]
|
|
return "BEGIN BATCH\n" + "\n".join(statements) + "\n APPLY BATCH\n"
|
|
|
|
|
|
@pytest.mark.xfail(reason="Scylla does not send warnings for batch: https://github.com/scylladb/scylla/issues/10196")
|
|
def test_warnings_are_returned_in_response(cql, table1):
|
|
"""Verifies if response contains warning messages.
|
|
Because warning message threshold is different for Scylla and Cassandra,
|
|
test tries several sizes until warning appears.
|
|
"""
|
|
for size_in_kb in [10, 129, 256]:
|
|
over_sized_batch = generate_big_batch(table1, size_in_kb)
|
|
response_future = cql.execute_async(over_sized_batch)
|
|
response_future.result()
|
|
if response_future.warnings:
|
|
break
|
|
else:
|
|
pytest.fail('Oversized batch did not generate a warning')
|
|
|
|
# example message for Cassandra:
|
|
# 'Batch for [cql_test_1647006065554.cql_test_1647006065623] is of size 7590,
|
|
# exceeding specified threshold of 5120 by 2470.'
|
|
assert "exceeding specified" in response_future.warnings[0]
|
|
|
|
|
|
def test_error_is_raised_for_batch_size_above_threshold(cql, table1):
|
|
"""Verifies cql returns error for batch that exceeds size provided in batch_size_fail_threshold_in_kb setting
|
|
from scylla.yaml."""
|
|
with pytest.raises(InvalidRequest, match="Batch too large"):
|
|
cql.execute(generate_big_batch(table1, 1025))
|