| 333 | typedef brpc::policy::LocalityAwareLoadBalancer LALB; |
| 334 | |
| 335 | static void ValidateWeightTree( |
| 336 | std::vector<LALB::ServerInfo> & weight_tree) { |
| 337 | std::vector<int64_t> weight_sum; |
| 338 | weight_sum.resize(weight_tree.size()); |
| 339 | for (ssize_t i = weight_tree.size() - 1; i >= 0; --i) { |
| 340 | const size_t left_child = i * 2 + 1; |
| 341 | const size_t right_child = i * 2 + 2; |
| 342 | weight_sum[i] = weight_tree[i].weight->volatile_value(); |
| 343 | if (left_child < weight_sum.size()) { |
| 344 | weight_sum[i] += weight_sum[left_child]; |
| 345 | } |
| 346 | if (right_child < weight_sum.size()) { |
| 347 | weight_sum[i] += weight_sum[right_child]; |
| 348 | } |
| 349 | } |
| 350 | for (size_t i = 0; i < weight_tree.size(); ++i) { |
| 351 | const int64_t left = weight_tree[i].left->load(butil::memory_order_relaxed); |
| 352 | size_t left_child = i * 2 + 1; |
| 353 | if (left_child < weight_tree.size()) { |
| 354 | ASSERT_EQ(weight_sum[left_child], left) << "i=" << i; |
| 355 | } else { |
| 356 | ASSERT_EQ(0, left); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | static void ValidateLALB(LALB& lalb, size_t N) { |
| 362 | LALB::Servers* d = lalb._db_servers._data; |
no test coverage detected