Skip to content

Commit

Permalink
tests: add test case for result_metadata update
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Feb 7, 2024
1 parent 746a6e1 commit aa2ff61
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions scylla/src/transport/session_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,87 @@ async fn test_unprepared_reprepare_in_execute() {
assert_eq!(all_rows, vec![(1, 2, 3), (1, 3, 2)]);
}

#[tokio::test]
async fn test_use_prepared_result_metadata() {
let _ = tracing_subscriber::fmt::try_init();

let session = create_new_session_builder()
.skip_prepared_statement_result_metadata(true)
.build()
.await
.unwrap();
let ks = unique_keyspace_name();

session.query(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks), &[]).await.unwrap();
session.use_keyspace(ks, false).await.unwrap();

session
.query(
"CREATE TABLE IF NOT EXISTS tab (a int PRIMARY KEY, b int, c int)",
&[],
)
.await
.unwrap();

let insert_a_b_c = session
.prepare("INSERT INTO tab (a, b, c) VALUES (?, ?, ?)")
.await
.unwrap();
let select_star = session.prepare("SELECT * FROM tab").await.unwrap();

let select_col_types = select_star
.get_result_metadata()
.col_specs
.iter()
.map(|c| c.typ.clone())
.collect::<Vec<_>>();

assert_eq!(
vec![ColumnType::Int, ColumnType::Int, ColumnType::Int],
select_col_types
);

session.execute(&insert_a_b_c, (1, 2, 3)).await.unwrap();
session.execute(&insert_a_b_c, (3, 4, -1)).await.unwrap();

session
.query("ALTER TABLE tab ALTER c TYPE blob", &[])
.await
.unwrap();

// The type of `c` should change to blob after reprepare.
let all_rows: Vec<(i32, i32, Vec<u8>)> = session
.execute(&select_star, &[])
.await
.unwrap()
.rows_typed::<(i32, i32, Vec<u8>)>()
.unwrap()
.map(|r| r.unwrap())
.collect();

// Third column deserialized as raw bytes.
assert_eq!(
vec![
(1, 2, vec![0x00, 0x00, 0x00, 0x03]),
(3, 4, vec![0xff, 0xff, 0xff, 0xff])
],
all_rows
);

// Verify that result_metadata of the SELECT query got updated.
let select_col_types = select_star
.get_result_metadata()
.col_specs
.iter()
.map(|c| c.typ.clone())
.collect::<Vec<_>>();

assert_eq!(
vec![ColumnType::Int, ColumnType::Int, ColumnType::Blob],
select_col_types
);
}

#[tokio::test]
async fn test_unusual_valuelists() {
let _ = tracing_subscriber::fmt::try_init();
Expand Down

0 comments on commit aa2ff61

Please sign in to comment.