Skip to content

Commit

Permalink
tests: additional unit test cases for lbp config
Browse files Browse the repository at this point in the history
Added test cases for rack-awareness, and extended dc-awareness
tests by empty and nullptr parameters checks.
  • Loading branch information
muzarski committed Oct 17, 2024
1 parent b647d48 commit 6b33262
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions scylla-rust-wrapper/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,11 +886,13 @@ mod tests {
let cluster = ptr_to_ref(cluster_raw);
{
assert_matches!(cluster.load_balancing_config.dc_awareness, None);
assert_matches!(cluster.load_balancing_config.rack_awareness, None);
assert!(cluster.load_balancing_config.token_awareness_enabled);
assert!(!cluster.load_balancing_config.latency_awareness_enabled);
}
{
cass_cluster_set_token_aware_routing(cluster_raw, 0);
// Just for the test purposes we enable both dc and rack+dc awareness.
assert_cass_error_eq!(
cass_cluster_set_load_balance_dc_aware(
cluster_raw,
Expand All @@ -900,6 +902,14 @@ mod tests {
),
CassError::CASS_OK
);
assert_cass_error_eq!(
cass_cluster_set_load_balance_rack_aware(
cluster_raw,
"eu-east\0".as_ptr() as *const i8,
"rack1\0".as_ptr() as *const i8,
),
CassError::CASS_OK
);
cass_cluster_set_latency_aware_routing(cluster_raw, 1);
// These values cannot currently be tested to be set properly in the latency awareness builder,
// but at least we test that the function completed successfully.
Expand All @@ -914,6 +924,13 @@ mod tests {

let dc_awareness = cluster.load_balancing_config.dc_awareness.as_ref().unwrap();
assert_eq!(dc_awareness.local_dc, "eu");
let rack_awareness = cluster
.load_balancing_config
.rack_awareness
.as_ref()
.unwrap();
assert_eq!(rack_awareness.local_dc, "eu-east");
assert_eq!(rack_awareness.local_rack, "rack1");
assert!(!cluster.load_balancing_config.token_awareness_enabled);
assert!(cluster.load_balancing_config.latency_awareness_enabled);
}
Expand All @@ -938,6 +955,51 @@ mod tests {
),
CassError::CASS_ERROR_LIB_BAD_PARAMS
);

// null pointers
assert_cass_error_eq!(
cass_cluster_set_load_balance_dc_aware(cluster_raw, std::ptr::null(), 0, 0),
CassError::CASS_ERROR_LIB_BAD_PARAMS
);
assert_cass_error_eq!(
cass_cluster_set_load_balance_rack_aware(
cluster_raw,
"eu\0".as_ptr() as *const i8,
std::ptr::null(),
),
CassError::CASS_ERROR_LIB_BAD_PARAMS
);
assert_cass_error_eq!(
cass_cluster_set_load_balance_rack_aware(
cluster_raw,
std::ptr::null(),
"rack\0".as_ptr() as *const i8,
),
CassError::CASS_ERROR_LIB_BAD_PARAMS
);

// empty strings
let empty_str = "\0".as_ptr() as *const i8;
assert_cass_error_eq!(
cass_cluster_set_load_balance_dc_aware(cluster_raw, std::ptr::null(), 0, 0),
CassError::CASS_ERROR_LIB_BAD_PARAMS
);
assert_cass_error_eq!(
cass_cluster_set_load_balance_rack_aware(
cluster_raw,
"eu\0".as_ptr() as *const i8,
empty_str,
),
CassError::CASS_ERROR_LIB_BAD_PARAMS
);
assert_cass_error_eq!(
cass_cluster_set_load_balance_rack_aware(
cluster_raw,
empty_str,
"rack\0".as_ptr() as *const i8,
),
CassError::CASS_ERROR_LIB_BAD_PARAMS
);
}
}

Expand Down

0 comments on commit 6b33262

Please sign in to comment.