From e5d3f8c80dd4cd4f1959510d39776c0334be4443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przytu=C5=82a?= Date: Mon, 2 Dec 2024 15:53:15 +0100 Subject: [PATCH] regression test for batches to multiple tables The previous commit fixed the bug described in #1134. This commit adds a regression test for that particular case, that is, for preparing a batch that operates on multiple tables. --- scylla/src/transport/session_test.rs | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/scylla/src/transport/session_test.rs b/scylla/src/transport/session_test.rs index 280b14917..318848c57 100644 --- a/scylla/src/transport/session_test.rs +++ b/scylla/src/transport/session_test.rs @@ -457,7 +457,7 @@ async fn test_batch() { .await .unwrap(); - // TODO: Add API, that supports binding values to statements in batch creation process, + // TODO: Add API that supports binding values to statements in batch creation process, // to avoid problem of statements/values count mismatch use crate::batch::Batch; let mut batch: Batch = Default::default(); @@ -537,6 +537,42 @@ async fn test_batch() { assert_eq!(results, vec![(4, 20, String::from("foobar"))]); } +// This is a regression test for #1134. +#[tokio::test] +async fn test_batch_to_multiple_tables() { + setup_tracing(); + let session = create_new_session_builder().build().await.unwrap(); + let ks = unique_keyspace_name(); + + session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks)).await.unwrap(); + session.use_keyspace(&ks, true).await.unwrap(); + session + .ddl("CREATE TABLE IF NOT EXISTS t_batch1 (a int, b int, c text, primary key (a, b))") + .await + .unwrap(); + session + .ddl("CREATE TABLE IF NOT EXISTS t_batch2 (a int, b int, c text, primary key (a, b))") + .await + .unwrap(); + + let prepared_statement = session + .prepare( + " + BEGIN BATCH + INSERT INTO t_batch1 (a, b, c) VALUES (?, ?, ?); + INSERT INTO t_batch2 (a, b, c) VALUES (?, ?, ?); + APPLY BATCH; + ", + ) + .await + .unwrap(); + + session + .execute_unpaged(&prepared_statement, (1, 2, "ala", 4, 5, "ma")) + .await + .unwrap(); +} + #[tokio::test] async fn test_token_calculation() { setup_tracing();