Skip to content

Commit 0db6583

Browse files
committed
tests: add timeuuid runtime ordering test
1 parent 5432eba commit 0db6583

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

scylla/src/transport/cql_types_test.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::transport::session::IntoTypedRows;
88
use crate::transport::session::Session;
99
use crate::utils::test_utils::unique_keyspace_name;
1010
use bigdecimal::BigDecimal;
11+
use itertools::Itertools;
1112
use num_bigint::BigInt;
1213
use scylla_cql::frame::value::CqlTimeuuid;
1314
use scylla_cql::types::serialize::value::SerializeCql;
@@ -1149,6 +1150,84 @@ async fn test_timeuuid() {
11491150
}
11501151
}
11511152

1153+
#[tokio::test]
1154+
async fn test_timeuuid_ordering() {
1155+
let session: Session = create_new_session_builder().build().await.unwrap();
1156+
let ks = unique_keyspace_name();
1157+
1158+
session
1159+
.query(
1160+
format!(
1161+
"CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = \
1162+
{{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}",
1163+
ks
1164+
),
1165+
&[],
1166+
)
1167+
.await
1168+
.unwrap();
1169+
session.use_keyspace(ks, false).await.unwrap();
1170+
1171+
session
1172+
.query(
1173+
"CREATE TABLE tab (p int, t timeuuid, PRIMARY KEY (p, t))",
1174+
(),
1175+
)
1176+
.await
1177+
.unwrap();
1178+
1179+
// Timeuuid values, sorted in the same order as Scylla/Cassandra sorts them.
1180+
let sorted_timeuuid_vals: Vec<CqlTimeuuid> = vec![
1181+
CqlTimeuuid::from_str("00000000-0000-1000-8080-808080808080").unwrap(),
1182+
CqlTimeuuid::from_str("00000000-0000-1000-ffff-ffffffffffff").unwrap(),
1183+
CqlTimeuuid::from_str("00000000-0000-1000-0000-000000000000").unwrap(),
1184+
CqlTimeuuid::from_str("fed35080-0efb-11ee-a1ca-00006490e9a4").unwrap(),
1185+
CqlTimeuuid::from_str("00000257-0efc-11ee-9547-00006490e9a6").unwrap(),
1186+
CqlTimeuuid::from_str("ffffffff-ffff-1fff-ffff-ffffffffffef").unwrap(),
1187+
CqlTimeuuid::from_str("ffffffff-ffff-1fff-ffff-ffffffffffff").unwrap(),
1188+
CqlTimeuuid::from_str("ffffffff-ffff-1fff-0000-000000000000").unwrap(),
1189+
CqlTimeuuid::from_str("ffffffff-ffff-1fff-7f7f-7f7f7f7f7f7f").unwrap(),
1190+
];
1191+
1192+
// Generate all permutations.
1193+
let perms = Itertools::permutations(sorted_timeuuid_vals.iter(), sorted_timeuuid_vals.len())
1194+
.collect::<Vec<_>>();
1195+
// Ensure that all of the permutations were generated.
1196+
assert_eq!(362880, perms.len());
1197+
1198+
// Verify that Scylla really sorts timeuuids as defined in sorted_timeuuid_vals
1199+
let prepared = session
1200+
.prepare("INSERT INTO tab (p, t) VALUES (0, ?)")
1201+
.await
1202+
.unwrap();
1203+
for timeuuid_val in &perms[0] {
1204+
session.execute(&prepared, (timeuuid_val,)).await.unwrap();
1205+
}
1206+
1207+
let scylla_order_timeuuids: Vec<CqlTimeuuid> = session
1208+
.query("SELECT t FROM tab WHERE p = 0", ())
1209+
.await
1210+
.unwrap()
1211+
.rows_typed::<(CqlTimeuuid,)>()
1212+
.unwrap()
1213+
.map(|r| r.unwrap().0)
1214+
.collect();
1215+
1216+
assert_eq!(sorted_timeuuid_vals, scylla_order_timeuuids);
1217+
1218+
for perm in perms {
1219+
// Test if rust timeuuid values are sorted in the same way as in Scylla
1220+
let mut rust_sorted_timeuuids: Vec<CqlTimeuuid> = perm
1221+
.clone()
1222+
.into_iter()
1223+
.map(|x| x.to_owned())
1224+
.collect::<Vec<_>>();
1225+
rust_sorted_timeuuids.sort();
1226+
1227+
assert_eq!(sorted_timeuuid_vals, rust_sorted_timeuuids);
1228+
}
1229+
}
1230+
11521231
#[tokio::test]
11531232
async fn test_inet() {
11541233
let session: Session = init_test("inet_tests", "inet").await;

0 commit comments

Comments
 (0)