Skip to content

Commit

Permalink
tests: add timeuuid runtime ordering test
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Jan 10, 2024
1 parent e5b0382 commit fd6a50f
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions scylla/src/transport/cql_types_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,72 @@ async fn test_timeuuid() {
}
}

#[tokio::test]
async fn test_timeuuid_ordering() {
let session: Session = create_new_session_builder().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 tab (p int, t timeuuid, PRIMARY KEY (p, t))",
(),
)
.await
.unwrap();

// Timeuuid values, sorted in the same order as Scylla/Cassandra sorts them.
let sorted_timeuuid_vals: Vec<CqlTimeuuid> = vec![
CqlTimeuuid::from_str("00000000-0000-1000-8080-808080808080").unwrap(),
CqlTimeuuid::from_str("00000000-0000-1000-ffff-ffffffffffff").unwrap(),
CqlTimeuuid::from_str("00000000-0000-1000-0000-000000000000").unwrap(),
CqlTimeuuid::from_str("fed35080-0efb-11ee-a1ca-00006490e9a4").unwrap(),
CqlTimeuuid::from_str("00000257-0efc-11ee-9547-00006490e9a6").unwrap(),
CqlTimeuuid::from_str("ffffffff-ffff-1fff-ffff-ffffffffffef").unwrap(),
CqlTimeuuid::from_str("ffffffff-ffff-1fff-ffff-ffffffffffff").unwrap(),
CqlTimeuuid::from_str("ffffffff-ffff-1fff-0000-000000000000").unwrap(),
CqlTimeuuid::from_str("ffffffff-ffff-1fff-7f7f-7f7f7f7f7f7f").unwrap(),
];

// Verify that Scylla really sorts timeuuids as defined in sorted_timeuuid_vals
let prepared = session
.prepare("INSERT INTO tab (p, t) VALUES (0, ?)")
.await
.unwrap();
for timeuuid_val in &sorted_timeuuid_vals {
session.execute(&prepared, (timeuuid_val,)).await.unwrap();
}

let scylla_order_timeuuids: Vec<CqlTimeuuid> = session
.query("SELECT t FROM tab WHERE p = 0", ())
.await
.unwrap()
.rows_typed::<(CqlTimeuuid,)>()
.unwrap()
.map(|r| r.unwrap().0)
.collect();

assert_eq!(sorted_timeuuid_vals, scylla_order_timeuuids);

// Test if rust timeuuid values are sorted in the same way as in Scylla
let mut rust_sorted_timeuuids: Vec<CqlTimeuuid> = sorted_timeuuid_vals.clone();
rust_sorted_timeuuids.sort();

assert_eq!(sorted_timeuuid_vals, rust_sorted_timeuuids);
}

#[tokio::test]
async fn test_inet() {
let session: Session = init_test("inet_tests", "inet").await;
Expand Down

0 comments on commit fd6a50f

Please sign in to comment.