Skip to content

Commit

Permalink
regression test for batches to multiple tables
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wprzytula committed Dec 5, 2024
1 parent 6844bc9 commit e5d3f8c
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion scylla/src/transport/session_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e5d3f8c

Please sign in to comment.