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 2, 2024
1 parent eade6b6 commit 2100859
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions scylla/src/statement/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ impl From<&str> for BatchStatement {
}
}

impl From<String> for BatchStatement {
fn from(s: String) -> Self {
BatchStatement::Query(Query::from(s))
}
}

impl From<Query> for BatchStatement {
fn from(q: Query) -> Self {
BatchStatement::Query(q)
Expand Down
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 = Arc::new(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 2100859

Please sign in to comment.