Skip to content

Commit 754f1a2

Browse files
committed
tests: move cql_value.rs tests into serialization.rs
1 parent c84ce79 commit 754f1a2

File tree

3 files changed

+147
-152
lines changed

3 files changed

+147
-152
lines changed

scylla/tests/integration/cql_value.rs

Lines changed: 0 additions & 150 deletions
This file was deleted.

scylla/tests/integration/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod authenticate;
22
mod batch;
33
mod consistency;
44
mod cql_collections;
5-
mod cql_value;
65
mod default_policy;
76
mod execution_profiles;
87
mod history;

scylla/tests/integration/serialization.rs

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use assert_matches::assert_matches;
12
use itertools::Itertools;
23
use scylla::client::session::Session;
34
use scylla::serialize::value::SerializeValue;
4-
use scylla::value::{Counter, CqlDate, CqlTime, CqlTimestamp, CqlTimeuuid, CqlValue, CqlVarint};
5+
use scylla::value::{Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlValue, CqlVarint};
56
use scylla::{DeserializeValue, SerializeValue};
67
use std::cmp::PartialEq;
78
use std::fmt::Debug;
@@ -1863,3 +1864,148 @@ async fn test_udt_with_missing_field() {
18631864
)
18641865
.await;
18651866
}
1867+
1868+
1869+
#[tokio::test]
1870+
async fn test_cqlvalue_udt() {
1871+
setup_tracing();
1872+
let session: Session = create_new_session_builder().build().await.unwrap();
1873+
let ks = unique_keyspace_name();
1874+
session
1875+
.ddl(format!(
1876+
"CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = \
1877+
{{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}",
1878+
ks
1879+
))
1880+
.await
1881+
.unwrap();
1882+
session.use_keyspace(&ks, false).await.unwrap();
1883+
1884+
session
1885+
.ddl("CREATE TYPE IF NOT EXISTS cqlvalue_udt_type (int_val int, text_val text)")
1886+
.await
1887+
.unwrap();
1888+
session.ddl("CREATE TABLE IF NOT EXISTS cqlvalue_udt_test (k int, my cqlvalue_udt_type, primary key (k))").await.unwrap();
1889+
1890+
let udt_cql_value = CqlValue::UserDefinedType {
1891+
keyspace: ks,
1892+
name: "cqlvalue_udt_type".to_string(),
1893+
fields: vec![
1894+
("int_val".to_string(), Some(CqlValue::Int(42))),
1895+
("text_val".to_string(), Some(CqlValue::Text("hi".into()))),
1896+
],
1897+
};
1898+
1899+
session
1900+
.query_unpaged(
1901+
"INSERT INTO cqlvalue_udt_test (k, my) VALUES (5, ?)",
1902+
(&udt_cql_value,),
1903+
)
1904+
.await
1905+
.unwrap();
1906+
1907+
let rows_result = session
1908+
.query_unpaged("SELECT my FROM cqlvalue_udt_test", &[])
1909+
.await
1910+
.unwrap()
1911+
.into_rows_result()
1912+
.unwrap();
1913+
1914+
let (received_udt_cql_value,) = rows_result.single_row::<(CqlValue,)>().unwrap();
1915+
1916+
assert_eq!(received_udt_cql_value, udt_cql_value);
1917+
}
1918+
1919+
#[tokio::test]
1920+
async fn test_cqlvalue_duration() {
1921+
setup_tracing();
1922+
let session: Session = create_new_session_builder().build().await.unwrap();
1923+
1924+
let ks = unique_keyspace_name();
1925+
session
1926+
.ddl(format!(
1927+
"CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = \
1928+
{{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}",
1929+
ks
1930+
))
1931+
.await
1932+
.unwrap();
1933+
session.use_keyspace(&ks, false).await.unwrap();
1934+
1935+
let duration_cql_value = CqlValue::Duration(CqlDuration {
1936+
months: 6,
1937+
days: 9,
1938+
nanoseconds: 21372137,
1939+
});
1940+
1941+
session.ddl("CREATE TABLE IF NOT EXISTS cqlvalue_duration_test (pk int, ck int, v duration, primary key (pk, ck))").await.unwrap();
1942+
let fixture_queries = vec![
1943+
(
1944+
"INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 0, ?)",
1945+
vec![&duration_cql_value],
1946+
),
1947+
(
1948+
"INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 1, 89h4m48s)",
1949+
vec![],
1950+
),
1951+
(
1952+
"INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 2, PT89H8M53S)",
1953+
vec![],
1954+
),
1955+
(
1956+
"INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 3, P0000-00-00T89:09:09)",
1957+
vec![],
1958+
),
1959+
];
1960+
1961+
for query in fixture_queries {
1962+
session.query_unpaged(query.0, query.1).await.unwrap();
1963+
}
1964+
1965+
let rows_result = session
1966+
.query_unpaged(
1967+
"SELECT v FROM cqlvalue_duration_test WHERE pk = ?",
1968+
(CqlValue::Int(0),),
1969+
)
1970+
.await
1971+
.unwrap()
1972+
.into_rows_result()
1973+
.unwrap();
1974+
1975+
let mut rows_iter = rows_result.rows::<(CqlValue,)>().unwrap();
1976+
1977+
let (first_value,) = rows_iter.next().unwrap().unwrap();
1978+
assert_eq!(first_value, duration_cql_value);
1979+
1980+
let (second_value,) = rows_iter.next().unwrap().unwrap();
1981+
assert_eq!(
1982+
second_value,
1983+
CqlValue::Duration(CqlDuration {
1984+
months: 0,
1985+
days: 0,
1986+
nanoseconds: 320_688_000_000_000,
1987+
})
1988+
);
1989+
1990+
let (third_value,) = rows_iter.next().unwrap().unwrap();
1991+
assert_eq!(
1992+
third_value,
1993+
CqlValue::Duration(CqlDuration {
1994+
months: 0,
1995+
days: 0,
1996+
nanoseconds: 320_933_000_000_000,
1997+
})
1998+
);
1999+
2000+
let (fourth_value,) = rows_iter.next().unwrap().unwrap();
2001+
assert_eq!(
2002+
fourth_value,
2003+
CqlValue::Duration(CqlDuration {
2004+
months: 0,
2005+
days: 0,
2006+
nanoseconds: 320_949_000_000_000,
2007+
})
2008+
);
2009+
2010+
assert_matches!(rows_iter.next(), None);
2011+
}

0 commit comments

Comments
 (0)