Verify correctness of receivers' data values.
| 527 | |
| 528 | // Verify correctness of receivers' data values. |
| 529 | void CheckReceivers(TPartitionType::type stream_type, int num_senders, |
| 530 | int num_batches = NUM_BATCHES) { |
| 531 | int64_t total = 0; |
| 532 | multiset<int64_t> all_data_values; |
| 533 | for (int i = 0; i < receiver_info_.size(); ++i) { |
| 534 | ReceiverInfo* info = receiver_info_[i].get(); |
| 535 | EXPECT_OK(info->status); |
| 536 | total += info->data_values.size(); |
| 537 | ASSERT_EQ(info->stream_type, stream_type); |
| 538 | ASSERT_EQ(info->num_senders, num_senders); |
| 539 | if (stream_type == TPartitionType::UNPARTITIONED) { |
| 540 | EXPECT_EQ( |
| 541 | num_batches * BATCH_CAPACITY * num_senders, info->data_values.size()); |
| 542 | } |
| 543 | all_data_values.insert(info->data_values.begin(), info->data_values.end()); |
| 544 | |
| 545 | int k = 0; |
| 546 | for (multiset<int64_t>::iterator j = info->data_values.begin(); |
| 547 | j != info->data_values.end(); ++j, ++k) { |
| 548 | if (stream_type == TPartitionType::UNPARTITIONED) { |
| 549 | // unpartitioned streams contain all values as many times as there are |
| 550 | // senders |
| 551 | EXPECT_EQ(k / num_senders, *j); |
| 552 | } else if (stream_type == TPartitionType::HASH_PARTITIONED) { |
| 553 | // hash-partitioned streams send values to the right partition |
| 554 | int64_t value = *j; |
| 555 | uint64_t hash_val = RawValue::GetHashValueFastHash( |
| 556 | &value, ColumnType(TYPE_BIGINT), |
| 557 | GetExchangeHashSeed(runtime_state_->query_id())); |
| 558 | EXPECT_EQ(hash_val % receiver_info_.size(), info->receiver_num); |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | if (stream_type == TPartitionType::HASH_PARTITIONED) { |
| 564 | EXPECT_EQ(num_batches * BATCH_CAPACITY * num_senders, total); |
| 565 | |
| 566 | int k = 0; |
| 567 | for (multiset<int64_t>::iterator j = all_data_values.begin(); |
| 568 | j != all_data_values.end(); ++j, ++k) { |
| 569 | // each sender sent all values |
| 570 | EXPECT_EQ(k / num_senders, *j); |
| 571 | if (k/num_senders != *j) break; |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | // Returns a map of reciever to all it's data values. |
| 577 | unordered_map<int, multiset<int64_t>> GetHashPartitionedReceiversDataMap( |