| 30 | namespace rpc { |
| 31 | |
| 32 | TEST(RequestTrackerTest, TestSequenceNumberGeneration) { |
| 33 | const int MAX = 10; |
| 34 | |
| 35 | scoped_refptr<RequestTracker> tracker_(new RequestTracker("test_client")); |
| 36 | |
| 37 | // A new tracker should have no incomplete RPCs |
| 38 | RequestTracker::SequenceNumber seq_no = tracker_->FirstIncomplete(); |
| 39 | ASSERT_EQ(seq_no, RequestTracker::kNoSeqNo); |
| 40 | |
| 41 | vector<RequestTracker::SequenceNumber> generated_seq_nos; |
| 42 | |
| 43 | // Generate MAX in flight RPCs, making sure they are correctly returned. |
| 44 | for (int i = 0; i < MAX; i++) { |
| 45 | ASSERT_OK(tracker_->NewSeqNo(&seq_no)); |
| 46 | generated_seq_nos.push_back(seq_no); |
| 47 | } |
| 48 | |
| 49 | // Now we should get a first incomplete. |
| 50 | ASSERT_EQ(generated_seq_nos[0], tracker_->FirstIncomplete()); |
| 51 | |
| 52 | // Marking 'first_incomplete' as done, should advance the first incomplete. |
| 53 | tracker_->RpcCompleted(tracker_->FirstIncomplete()); |
| 54 | |
| 55 | ASSERT_EQ(generated_seq_nos[1], tracker_->FirstIncomplete()); |
| 56 | |
| 57 | // Marking a 'middle' rpc, should not advance 'first_incomplete'. |
| 58 | tracker_->RpcCompleted(generated_seq_nos[5]); |
| 59 | ASSERT_EQ(generated_seq_nos[1], tracker_->FirstIncomplete()); |
| 60 | |
| 61 | // Marking half the rpc as complete should advance FirstIncomplete. |
| 62 | // Note that this also tests that RequestTracker::RpcCompleted() is idempotent, i.e. that |
| 63 | // marking the same sequence number as complete twice is a no-op. |
| 64 | for (int i = 0; i < MAX / 2; i++) { |
| 65 | tracker_->RpcCompleted(generated_seq_nos[i]); |
| 66 | } |
| 67 | |
| 68 | ASSERT_EQ(generated_seq_nos[6], tracker_->FirstIncomplete()); |
| 69 | |
| 70 | for (int i = MAX / 2; i <= MAX; i++) { |
| 71 | ASSERT_OK(tracker_->NewSeqNo(&seq_no)); |
| 72 | generated_seq_nos.push_back(seq_no); |
| 73 | } |
| 74 | |
| 75 | // Marking them all as completed should cause RequestTracker::FirstIncomplete() to return |
| 76 | // Status::NotFound() again. |
| 77 | for (auto seq_no : generated_seq_nos) { |
| 78 | tracker_->RpcCompleted(seq_no); |
| 79 | } |
| 80 | |
| 81 | ASSERT_EQ(tracker_->FirstIncomplete(), RequestTracker::kNoSeqNo); |
| 82 | } |
| 83 | |
| 84 | } // namespace rpc |
| 85 | } // namespace kudu |
nothing calls this directly
no test coverage detected