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 f8e9f3f commit ea3e77e
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions scylla-rust-wrapper/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,49 @@ mod tests {
}
assert!(!cluster.load_balancing_config.token_awareness_enabled);
assert!(cluster.load_balancing_config.latency_awareness_enabled);

// set preferred rack+dc
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
);

let node_location_preference =
&cluster.load_balancing_config.node_location_preference;
match node_location_preference {
NodeLocationPreference::DatacenterAndRack {
local_dc,
local_rack,
} => {
assert_eq!(local_dc, "eu-east");
assert_eq!(local_rack, "rack1");
}
_ => panic!("Expected preferred dc and rack"),
}

// set back to preferred dc
assert_cass_error_eq!(
cass_cluster_set_load_balance_dc_aware(
cluster_raw,
"eu\0".as_ptr() as *const i8,
0,
0
),
CassError::CASS_OK
);

let node_location_preference =
&cluster.load_balancing_config.node_location_preference;
match node_location_preference {
NodeLocationPreference::Datacenter { local_dc } => {
assert_eq!(local_dc, "eu")
}
_ => panic!("Expected preferred dc"),
}
}
/* Test invalid configurations */
{
Expand All @@ -951,6 +994,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 ea3e77e

Please sign in to comment.