Skip to content

Commit

Permalink
treewide: switch tests to use the new framework
Browse files Browse the repository at this point in the history
This is a large commit which goes over all existing tests that haven't
been migrated in previous commits and adjusts them to use the new
deserialization framework.

There were lots of changes to be made, but they are mostly independent
from each other and very simple.
  • Loading branch information
wprzytula committed Sep 19, 2024
1 parent d00ed84 commit 4e0ea90
Show file tree
Hide file tree
Showing 22 changed files with 366 additions and 385 deletions.
7 changes: 3 additions & 4 deletions scylla/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ mod tests {
use crate::test_utils::create_new_session_builder;
use assert_matches::assert_matches;
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
use futures::StreamExt;
use scylla_cql::Consistency;

// Set a single time for all timestamps within StructuredHistory.
Expand Down Expand Up @@ -917,7 +916,7 @@ mod tests {
#[tokio::test]
async fn successful_query_history() {
setup_tracing();
let session = create_new_session_builder().build_legacy().await.unwrap();
let session = create_new_session_builder().build().await.unwrap();

let mut query = Query::new("SELECT * FROM system.local");
let history_collector = Arc::new(HistoryCollector::new());
Expand Down Expand Up @@ -984,7 +983,7 @@ mod tests {
#[tokio::test]
async fn failed_query_history() {
setup_tracing();
let session = create_new_session_builder().build_legacy().await.unwrap();
let session = create_new_session_builder().build().await.unwrap();

let mut query = Query::new("This isnt even CQL");
let history_collector = Arc::new(HistoryCollector::new());
Expand Down Expand Up @@ -1021,7 +1020,7 @@ mod tests {
#[tokio::test]
async fn iterator_query_history() {
setup_tracing();
let session = create_new_session_builder().build_legacy().await.unwrap();
let session = create_new_session_builder().build().await.unwrap();
let ks = unique_keyspace_name();
session
.query_unpaged(format!("CREATE KEYSPACE {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks), &[])
Expand Down
4 changes: 2 additions & 2 deletions scylla/src/transport/authenticate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn authenticate_superuser() {
let session = crate::SessionBuilder::new()
.known_node(uri)
.user("cassandra", "cassandra")
.build_legacy()
.build()
.await
.unwrap();
let ks = unique_keyspace_name();
Expand Down Expand Up @@ -75,7 +75,7 @@ async fn custom_authentication() {
let session = crate::SessionBuilder::new()
.known_node(uri)
.authenticator_provider(Arc::new(CustomAuthenticatorProvider))
.build_legacy()
.build()
.await
.unwrap();
let ks = unique_keyspace_name();
Expand Down
7 changes: 6 additions & 1 deletion scylla/src/transport/caching_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,12 @@ mod tests {
.unwrap()
.into_stream();

let rows = iter.try_collect::<Vec<_>>().await.unwrap().len();
let rows = iter
.into_stream()
.try_collect::<Vec<_>>()
.await
.unwrap()
.len();

assert_eq!(1, rows);
assert_eq!(1, session.cache.len());
Expand Down
8 changes: 3 additions & 5 deletions scylla/src/transport/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,7 @@ mod tests {
// Preparation phase
let session = SessionBuilder::new()
.known_node_addr(addr)
.build_legacy()
.build()
.await
.unwrap();
session.query_unpaged(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks.clone()), &[]).await.unwrap();
Expand Down Expand Up @@ -2529,7 +2529,7 @@ mod tests {
// Preparation phase
let session = SessionBuilder::new()
.known_node_addr(addr)
.build_legacy()
.build()
.await
.unwrap();
session.query_unpaged(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks.clone()), &[]).await.unwrap();
Expand Down Expand Up @@ -2606,9 +2606,7 @@ mod tests {
.query_unpaged("SELECT p, v FROM t")
.await
.unwrap()
.into_legacy_result()
.unwrap()
.rows_typed::<(i32, Vec<u8>)>()
.rows::<(i32, Vec<u8>)>()
.unwrap()
.collect::<Result<Vec<_>, _>>()
.unwrap();
Expand Down
26 changes: 14 additions & 12 deletions scylla/src/transport/cql_collections_test.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use crate::cql_to_rust::FromCqlVal;
use crate::transport::session::Session;
use scylla_cql::types::deserialize::value::DeserializeValue;

use crate::frame::response::result::CqlValue;
use crate::test_utils::{create_new_session_builder, setup_tracing};
use crate::utils::test_utils::unique_keyspace_name;
use crate::{frame::response::result::CqlValue, LegacySession};
use scylla_cql::types::serialize::value::SerializeValue;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};

async fn connect() -> LegacySession {
let session = create_new_session_builder().build_legacy().await.unwrap();
async fn connect() -> Session {
let session = create_new_session_builder().build().await.unwrap();
let ks = unique_keyspace_name();
session.query_unpaged(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks), &[]).await.unwrap();
session.use_keyspace(ks, false).await.unwrap();

session
}

async fn create_table(session: &LegacySession, table_name: &str, value_type: &str) {
async fn create_table(session: &Session, table_name: &str, value_type: &str) {
session
.query_unpaged(
format!(
Expand All @@ -28,13 +30,13 @@ async fn create_table(session: &LegacySession, table_name: &str, value_type: &st
}

async fn insert_and_select<InsertT, SelectT>(
session: &LegacySession,
session: &Session,
table_name: &str,
to_insert: &InsertT,
expected: &SelectT,
) where
InsertT: SerializeValue,
SelectT: FromCqlVal<Option<CqlValue>> + PartialEq + std::fmt::Debug,
SelectT: for<'r> DeserializeValue<'r> + PartialEq + std::fmt::Debug,
{
session
.query_unpaged(
Expand All @@ -48,7 +50,7 @@ async fn insert_and_select<InsertT, SelectT>(
.query_unpaged(format!("SELECT val FROM {} WHERE p = 0", table_name), ())
.await
.unwrap()
.single_row_typed::<(SelectT,)>()
.single_row::<(SelectT,)>()
.unwrap()
.0;

Expand All @@ -58,7 +60,7 @@ async fn insert_and_select<InsertT, SelectT>(
#[tokio::test]
async fn test_cql_list() {
setup_tracing();
let session: LegacySession = connect().await;
let session: Session = connect().await;

let table_name: &str = "test_cql_list_tab";
create_table(&session, table_name, "list<int>").await;
Expand Down Expand Up @@ -91,7 +93,7 @@ async fn test_cql_list() {
#[tokio::test]
async fn test_cql_set() {
setup_tracing();
let session: LegacySession = connect().await;
let session: Session = connect().await;

let table_name: &str = "test_cql_set_tab";
create_table(&session, table_name, "set<int>").await;
Expand Down Expand Up @@ -155,7 +157,7 @@ async fn test_cql_set() {
#[tokio::test]
async fn test_cql_map() {
setup_tracing();
let session: LegacySession = connect().await;
let session: Session = connect().await;

let table_name: &str = "test_cql_map_tab";
create_table(&session, table_name, "map<int, int>").await;
Expand Down Expand Up @@ -206,7 +208,7 @@ async fn test_cql_map() {
#[tokio::test]
async fn test_cql_tuple() {
setup_tracing();
let session: LegacySession = connect().await;
let session: Session = connect().await;

let table_name: &str = "test_cql_tuple_tab";
create_table(&session, table_name, "tuple<int, int, text>").await;
Expand Down
Loading

0 comments on commit 4e0ea90

Please sign in to comment.