Skip to content

Commit 693c9db

Browse files
committed
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.
1 parent b1517fe commit 693c9db

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

scylla/src/transport/session_test.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ async fn test_batch() {
457457
.await
458458
.unwrap();
459459

460-
// TODO: Add API, that supports binding values to statements in batch creation process,
460+
// TODO: Add API that supports binding values to statements in batch creation process,
461461
// to avoid problem of statements/values count mismatch
462462
use crate::batch::Batch;
463463
let mut batch: Batch = Default::default();
@@ -537,6 +537,42 @@ async fn test_batch() {
537537
assert_eq!(results, vec![(4, 20, String::from("foobar"))]);
538538
}
539539

540+
// This is a regression test for #1134.
541+
#[tokio::test]
542+
async fn test_batch_to_multiple_tables() {
543+
setup_tracing();
544+
let session = create_new_session_builder().build().await.unwrap();
545+
let ks = unique_keyspace_name();
546+
547+
session.ddl(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks)).await.unwrap();
548+
session.use_keyspace(&ks, true).await.unwrap();
549+
session
550+
.ddl("CREATE TABLE IF NOT EXISTS t_batch1 (a int, b int, c text, primary key (a, b))")
551+
.await
552+
.unwrap();
553+
session
554+
.ddl("CREATE TABLE IF NOT EXISTS t_batch2 (a int, b int, c text, primary key (a, b))")
555+
.await
556+
.unwrap();
557+
558+
let prepared_statement = session
559+
.prepare(
560+
"
561+
BEGIN BATCH
562+
INSERT INTO t_batch1 (a, b, c) VALUES (?, ?, ?);
563+
INSERT INTO t_batch2 (a, b, c) VALUES (?, ?, ?);
564+
APPLY BATCH;
565+
",
566+
)
567+
.await
568+
.unwrap();
569+
570+
session
571+
.execute_unpaged(&prepared_statement, (1, 2, "ala", 4, 5, "ma"))
572+
.await
573+
.unwrap();
574+
}
575+
540576
#[tokio::test]
541577
async fn test_token_calculation() {
542578
setup_tracing();

0 commit comments

Comments
 (0)