Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
01458e1
integration: merge batch tests into a single file
wprzytula May 10, 2025
798cae9
integration: move test_shard_out_of_range to shards.rs
wprzytula May 10, 2025
7ebdc4c
integration: rename load_balancing.rs -> latency_awareness.rs
wprzytula May 10, 2025
8bb526e
integration: move vector tests to cql_collections.rs
wprzytula May 10, 2025
91c04a2
integration: move test_deserialize_empty_collections to cql_collectio…
wprzytula May 10, 2025
985ed9f
integration: extract simple_strategy_test
wprzytula May 10, 2025
cbb0a7b
integration: introduce metadata/configuration.rs
wprzytula May 26, 2025
4a6e5f8
integration: move test_refresh_metadata_after_schema_agreement
wprzytula May 10, 2025
8775a77
integration: extract metadata/contents.rs
wprzytula May 10, 2025
d03d4b4
integration: move test_views_in_schema_info() into contents.rs
wprzytula May 10, 2025
34e2bc4
integration: move batch LWT tests to batch.rs
wprzytula May 10, 2025
3a3f248
integration: move batch prepare tests to batch.rs
wprzytula May 10, 2025
6a1989a
integration: move turn_off_schema_fetching test
wprzytula May 10, 2025
9f32dfa
integration: extract tracing.rs
wprzytula May 10, 2025
8d16098
integration: extract use_keyspace.rs
wprzytula May 10, 2025
2012f82
integration: extract token_awareness.rs
wprzytula May 10, 2025
74528ab
integration: move test_fetch_system_keyspace to metadata/contents
wprzytula May 10, 2025
c455d22
integration: fix test_fetch_system_keyspace()
wprzytula May 10, 2025
a3b4802
integration: extract test_unusual_valuelists
wprzytula May 10, 2025
7dd382c
integration: move test_get_keyspace_name() to use_keyspace.rs
wprzytula May 10, 2025
520d5c0
integration: move keyspace_filtering test
wprzytula May 10, 2025
904e1d7
integration: extract timestamps.rs
wprzytula May 10, 2025
beb82aa
integration: extract transparent_reprepare.rs
wprzytula May 10, 2025
02cb460
integration: extract test_unprepared_statement
wprzytula May 10, 2025
7f5e970
integration: extract test_prepared_statement
wprzytula May 10, 2025
a6b8648
integration: extract macros/complex_pk
wprzytula May 26, 2025
6b58c09
integration: move test_batch to batch.rs
wprzytula May 10, 2025
2a908ed
integration: move test_counter_batch() to batch.rs
wprzytula May 10, 2025
119ef4f
integration: extract test_batch_to_multiple_tables()
wprzytula May 10, 2025
10b490d
integration: extract test_prepared_config()
wprzytula May 10, 2025
f4c4234
integration: move test_connection_failure to new_session.rs
wprzytula May 10, 2025
b8a89ff
integration: extract pager.rs tests
wprzytula May 10, 2025
f2cf33e
integration: extract test_prepared_partitioner()
wprzytula May 10, 2025
189f4b8
integration: extract test_token_calculation()
wprzytula May 10, 2025
6b022b4
integration: extract test_request_timeout()
wprzytula May 10, 2025
98d0b41
integration: delete test_await_schema_agreement()
wprzytula May 10, 2025
1423fe9
integration: extract test_named_bind_markers()
wprzytula May 10, 2025
f191efd
integration: rename session.rs -> db_errors.rs
wprzytula May 10, 2025
b5f4101
integration: extract test_prepared_statement_col_specs()
wprzytula May 10, 2025
8ef8b57
integration: statement.rs -> enforce_coordinator.rs
wprzytula May 10, 2025
12ed9f0
integration: move silent_prepare_query() to unprepared.rs
wprzytula May 26, 2025
7b4dadb
integration: move skip_metadata_optimization to prepared
wprzytula May 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
integration: move test_batch to batch.rs
Test `test_batch()` is extracted into `statements/batch.rs`.
  • Loading branch information
wprzytula committed May 26, 2025
commit 6b58c09401c38f8385b85efbf62d0d883aa3e01c
102 changes: 0 additions & 102 deletions scylla/tests/integration/session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,108 +105,6 @@ async fn test_counter_batch() {
.unwrap();
}

#[tokio::test]
async fn test_batch() {
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
.ddl(format!(
"CREATE TABLE IF NOT EXISTS {}.t_batch (a int, b int, c text, primary key (a, b))",
ks
))
.await
.unwrap();

let prepared_statement = session
.prepare(format!(
"INSERT INTO {}.t_batch (a, b, c) VALUES (?, ?, ?)",
ks
))
.await
.unwrap();

// TODO: Add API that supports binding values to statements in batch creation process,
// to avoid problem of statements/values count mismatch
let mut batch: Batch = Default::default();
batch.append_statement(&format!("INSERT INTO {}.t_batch (a, b, c) VALUES (?, ?, ?)", ks)[..]);
batch.append_statement(&format!("INSERT INTO {}.t_batch (a, b, c) VALUES (7, 11, '')", ks)[..]);
batch.append_statement(prepared_statement.clone());

let four_value: i32 = 4;
let hello_value: String = String::from("hello");
let session_clone = session.clone();
// We're spawning to a separate task here to test that it works even in that case, because in some scenarios
// (specifically if the `BatchValuesIter` associated type is not dropped before await boundaries)
// the implicit auto trait propagation on batch will be such that the returned future is not Send (depending on
// some lifetime for some unknown reason), so can't be spawned on tokio.
// See https://github.com/scylladb/scylla-rust-driver/issues/599 for more details
tokio::spawn(async move {
let values = (
(1_i32, 2_i32, "abc"),
(),
(1_i32, &four_value, hello_value.as_str()),
);
session_clone.batch(&batch, values).await.unwrap();
})
.await
.unwrap();

let mut results: Vec<(i32, i32, String)> = session
.query_unpaged(format!("SELECT a, b, c FROM {}.t_batch", ks), &[])
.await
.unwrap()
.into_rows_result()
.unwrap()
.rows::<(i32, i32, String)>()
.unwrap()
.collect::<Result<_, _>>()
.unwrap();

results.sort();
assert_eq!(
results,
vec![
(1, 2, String::from("abc")),
(1, 4, String::from("hello")),
(7, 11, String::from(""))
]
);

// Test repreparing statement inside a batch
let mut batch: Batch = Default::default();
batch.append_statement(prepared_statement);
let values = ((4_i32, 20_i32, "foobar"),);

// This statement flushes the prepared statement cache
session
.ddl(format!(
"ALTER TABLE {}.t_batch WITH gc_grace_seconds = 42",
ks
))
.await
.unwrap();
session.batch(&batch, values).await.unwrap();

let results: Vec<(i32, i32, String)> = session
.query_unpaged(
format!("SELECT a, b, c FROM {}.t_batch WHERE a = 4", ks),
&[],
)
.await
.unwrap()
.into_rows_result()
.unwrap()
.rows::<(i32, i32, String)>()
.unwrap()
.collect::<Result<_, _>>()
.unwrap();

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() {
Expand Down
103 changes: 103 additions & 0 deletions scylla/tests/integration/statements/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use scylla::statement::batch::{Batch, BatchStatement, BatchType};
use scylla::statement::prepared::PreparedStatement;
use scylla::statement::unprepared::Statement;
use std::collections::BTreeSet;
use std::sync::Arc;

#[tokio::test]
#[ntest::timeout(60000)]
Expand Down Expand Up @@ -458,3 +459,105 @@ async fn test_prepare_batch() {
assert!(session.prepare_batch(&bad_batch).await.is_err());
}
}

#[tokio::test]
async fn test_batch() {
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
.ddl(format!(
"CREATE TABLE IF NOT EXISTS {}.t_batch (a int, b int, c text, primary key (a, b))",
ks
))
.await
.unwrap();

let prepared_statement = session
.prepare(format!(
"INSERT INTO {}.t_batch (a, b, c) VALUES (?, ?, ?)",
ks
))
.await
.unwrap();

// TODO: Add API that supports binding values to statements in batch creation process,
// to avoid problem of statements/values count mismatch
let mut batch: Batch = Default::default();
batch.append_statement(&format!("INSERT INTO {}.t_batch (a, b, c) VALUES (?, ?, ?)", ks)[..]);
batch.append_statement(&format!("INSERT INTO {}.t_batch (a, b, c) VALUES (7, 11, '')", ks)[..]);
batch.append_statement(prepared_statement.clone());

let four_value: i32 = 4;
let hello_value: String = String::from("hello");
let session_clone = session.clone();
// We're spawning to a separate task here to test that it works even in that case, because in some scenarios
// (specifically if the `BatchValuesIter` associated type is not dropped before await boundaries)
// the implicit auto trait propagation on batch will be such that the returned future is not Send (depending on
// some lifetime for some unknown reason), so can't be spawned on tokio.
// See https://github.com/scylladb/scylla-rust-driver/issues/599 for more details
tokio::spawn(async move {
let values = (
(1_i32, 2_i32, "abc"),
(),
(1_i32, &four_value, hello_value.as_str()),
);
session_clone.batch(&batch, values).await.unwrap();
})
.await
.unwrap();

let mut results: Vec<(i32, i32, String)> = session
.query_unpaged(format!("SELECT a, b, c FROM {}.t_batch", ks), &[])
.await
.unwrap()
.into_rows_result()
.unwrap()
.rows::<(i32, i32, String)>()
.unwrap()
.collect::<Result<_, _>>()
.unwrap();

results.sort();
assert_eq!(
results,
vec![
(1, 2, String::from("abc")),
(1, 4, String::from("hello")),
(7, 11, String::from(""))
]
);

// Test repreparing statement inside a batch
let mut batch: Batch = Default::default();
batch.append_statement(prepared_statement);
let values = ((4_i32, 20_i32, "foobar"),);

// This statement flushes the prepared statement cache
session
.ddl(format!(
"ALTER TABLE {}.t_batch WITH gc_grace_seconds = 42",
ks
))
.await
.unwrap();
session.batch(&batch, values).await.unwrap();

let results: Vec<(i32, i32, String)> = session
.query_unpaged(
format!("SELECT a, b, c FROM {}.t_batch WHERE a = 4", ks),
&[],
)
.await
.unwrap()
.into_rows_result()
.unwrap()
.rows::<(i32, i32, String)>()
.unwrap()
.collect::<Result<_, _>>()
.unwrap();

assert_eq!(results, vec![(4, 20, String::from("foobar"))]);
}