Skip to content

Commit

Permalink
Add tests for query API for errors/no results
Browse files Browse the repository at this point in the history
  • Loading branch information
sylwiaszunejko committed Feb 11, 2025
1 parent e07c606 commit 4bf8e6e
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions scylla/tests/integration/query_result.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use assert_matches::assert_matches;
use futures::TryStreamExt;
use scylla::errors::PagerExecutionError;
use scylla::{
batch::{Batch, BatchType},
client::session::Session,
Expand Down Expand Up @@ -136,6 +138,44 @@ async fn query_should_iterate_over_all_pages_asynchronously_cross_partition() {
assert_eq!(i, 2 * ROWS_PER_PARTITION);
}

#[tokio::test]
async fn query_iter_no_results() {
let (session, ks) = initialize_cluster_two_partitions().await;

let query = Query::new(format!("SELECT * FROM {}.t where k0 = ?", ks));

let query_result = session.query_iter(query, ("part3",)).await.unwrap();
let mut iter = query_result.rows_stream::<(String, i32, i32)>().unwrap();

assert_eq!(iter.try_next().await.unwrap(), None);
}

#[tokio::test]
async fn query_iter_prepare_error() {
let (session, ks) = initialize_cluster_two_partitions().await;

// Wrong table name
let query = Query::new(format!("SELECT * FROM {}.test where k0 = ?", ks));

match session.query_iter(query, (PARTITION_KEY1,)).await {
Ok(_) => panic!("the query should have failed due to a prepare error"),
Err(e) => assert_matches!(e, PagerExecutionError::PrepareError(_)),
}
}

#[tokio::test]
async fn query_iter_serialization_error() {
let (session, ks) = initialize_cluster_two_partitions().await;

let query = Query::new(format!("SELECT * FROM {}.t where k0 = ?", ks));

// Wrong value type
match session.query_iter(query, (1,)).await {
Ok(_) => panic!("the query should have failed due to a serialization error"),
Err(e) => assert_matches!(e, PagerExecutionError::SerializationError(_)),
}
}

#[tokio::test]
async fn execute_should_only_iterate_over_rows_in_current_page() {
let (session, ks) = initialize_cluster_two_partitions().await;
Expand Down Expand Up @@ -221,3 +261,37 @@ async fn execute_should_iterate_over_all_pages_asynchronously_cross_partition()
}
assert_eq!(i, 2 * ROWS_PER_PARTITION);
}

#[tokio::test]
async fn execute_iter_no_results() {
let (session, ks) = initialize_cluster_two_partitions().await;

let prepared_query = session
.prepare(format!("SELECT * FROM {}.t where k0 = ?", ks))
.await
.unwrap();

let query_result = session
.execute_iter(prepared_query, ("part3",))
.await
.unwrap();
let mut iter = query_result.rows_stream::<(String, i32, i32)>().unwrap();

assert_eq!(iter.try_next().await.unwrap(), None);
}

#[tokio::test]
async fn execute_iter_serialization_error() {
let (session, ks) = initialize_cluster_two_partitions().await;

let prepared_query = session
.prepare(format!("SELECT * FROM {}.t where k0 = ?", ks))
.await
.unwrap();

// Wrong value type
match session.execute_iter(prepared_query, (1,)).await {
Ok(_) => panic!("the query should have failed due to a serialization error"),
Err(e) => assert_matches!(e, PagerExecutionError::SerializationError(_)),
}
}

0 comments on commit 4bf8e6e

Please sign in to comment.