From 35832d900173e2f77b0983e34b0923d49cfaf3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Mon, 19 Aug 2024 14:07:17 +0200 Subject: [PATCH] tests: disable tablets in CQL Counters tests As tablets don't support counters yet, they need to be disabled in Counter type tests. See https://github.com/scylladb/scylladb/commit/c70f321c6f581357afdf3fd8b4fe8e5c5bb9736e. --- scylla/src/transport/cql_types_test.rs | 41 ++++++++++++++++---------- scylla/src/transport/session_test.rs | 9 +++++- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index 1beea8b3fd..778666f490 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -3,7 +3,7 @@ use crate::cql_to_rust::FromCqlVal; use crate::frame::response::result::CqlValue; use crate::frame::value::{Counter, CqlDate, CqlTime, CqlTimestamp}; use crate::macros::FromUserType; -use crate::test_utils::{create_new_session_builder, setup_tracing}; +use crate::test_utils::{create_new_session_builder, scylla_supports_tablets, setup_tracing}; use crate::transport::session::Session; use crate::utils::test_utils::unique_keyspace_name; use itertools::Itertools; @@ -16,23 +16,27 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use std::str::FromStr; // Used to prepare a table for test -// Creates a new keyspace +// Creates a new keyspace, without tablets if requested and the ScyllaDB instance supports them. // Drops and creates table {table_name} (id int PRIMARY KEY, val {type_name}) -async fn init_test(table_name: &str, type_name: &str) -> Session { +async fn init_test_maybe_without_tablets( + table_name: &str, + type_name: &str, + supports_tablets: bool, +) -> Session { let session: Session = create_new_session_builder().build().await.unwrap(); let ks = unique_keyspace_name(); - session - .query( - format!( - "CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = \ - {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", - ks - ), - &[], - ) - .await - .unwrap(); + let mut create_ks = format!( + "CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = \ + {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", + ks + ); + + if !supports_tablets && scylla_supports_tablets(&session).await { + create_ks += " AND TABLETS = {'enabled': false}" + } + + session.query(create_ks, &[]).await.unwrap(); session.use_keyspace(ks, false).await.unwrap(); session @@ -54,6 +58,13 @@ async fn init_test(table_name: &str, type_name: &str) -> Session { session } +// Used to prepare a table for test +// Creates a new keyspace +// Drops and creates table {table_name} (id int PRIMARY KEY, val {type_name}) +async fn init_test(table_name: &str, type_name: &str) -> Session { + init_test_maybe_without_tablets(table_name, type_name, true).await +} + // This function tests serialization and deserialization mechanisms by sending insert and select // queries to running Scylla instance. // To do so, it: @@ -267,7 +278,7 @@ async fn test_counter() { // Can't use run_tests, because counters are special and can't be inserted let type_name = "counter"; - let session: Session = init_test(type_name, type_name).await; + let session: Session = init_test_maybe_without_tablets(type_name, type_name, false).await; for (i, test) in tests.iter().enumerate() { let update_bound_value = format!("UPDATE {} SET val = val + ? WHERE id = ?", type_name); diff --git a/scylla/src/transport/session_test.rs b/scylla/src/transport/session_test.rs index 22ce02ae84..617f3535b4 100644 --- a/scylla/src/transport/session_test.rs +++ b/scylla/src/transport/session_test.rs @@ -363,7 +363,14 @@ async fn test_counter_batch() { let session = Arc::new(create_new_session_builder().build().await.unwrap()); let ks = unique_keyspace_name(); - session.query(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks), &[]).await.unwrap(); + // Need to disable tablets in this test because they don't support counters yet. + // (https://github.com/scylladb/scylladb/commit/c70f321c6f581357afdf3fd8b4fe8e5c5bb9736e). + let mut create_ks = format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks); + if scylla_supports_tablets(&session).await { + create_ks += " AND TABLETS = {'enabled': false}" + } + + session.query(create_ks, &[]).await.unwrap(); session .query( format!(