| 1701 | } |
| 1702 | |
| 1703 | void StreamStateTest::TestShortDebugString() { |
| 1704 | Init(BUFFER_POOL_LIMIT); |
| 1705 | |
| 1706 | int num_batches = 50; |
| 1707 | RowDescriptor* desc = int_desc_; |
| 1708 | bool gen_null = false; |
| 1709 | int64_t default_page_len = 128 * sizeof(int); |
| 1710 | int64_t max_page_len = default_page_len; |
| 1711 | int num_rows = BATCH_SIZE; |
| 1712 | |
| 1713 | BufferedTupleStream stream( |
| 1714 | runtime_state_, desc, &client_, default_page_len, max_page_len); |
| 1715 | ASSERT_OK(stream.Init("StreamStateTest::ShortDebugString", true)); |
| 1716 | bool got_write_reservation; |
| 1717 | ASSERT_OK(stream.PrepareForWrite(&got_write_reservation)); |
| 1718 | ASSERT_TRUE(got_write_reservation); |
| 1719 | |
| 1720 | // Add rows to the stream |
| 1721 | int offset = 0; |
| 1722 | for (int i = 0; i < num_batches; ++i) { |
| 1723 | RowBatch* batch = nullptr; |
| 1724 | |
| 1725 | Status status; |
| 1726 | batch = CreateBatch(desc, offset, num_rows, gen_null); |
| 1727 | for (int j = 0; j < batch->num_rows(); ++j) { |
| 1728 | bool b = stream.AddRow(batch->GetRow(j), &status); |
| 1729 | ASSERT_OK(status); |
| 1730 | ASSERT_TRUE(b); |
| 1731 | } |
| 1732 | offset += batch->num_rows(); |
| 1733 | // Reset the batch to make sure the stream handles the memory correctly. |
| 1734 | batch->Reset(); |
| 1735 | } |
| 1736 | |
| 1737 | bool got_read_reservation; |
| 1738 | ASSERT_OK(stream.PrepareForRead(false, &got_read_reservation)); |
| 1739 | ASSERT_TRUE(got_read_reservation); |
| 1740 | |
| 1741 | // Read all the rows back |
| 1742 | vector<int> results; |
| 1743 | ReadValues(&stream, desc, &results); |
| 1744 | |
| 1745 | // Verify result |
| 1746 | VerifyResults<int>(*desc, results, num_rows * num_batches, gen_null); |
| 1747 | |
| 1748 | // Verify that stream contains more than MAX_PAGE_ITER_DEBUG pages and only subset of |
| 1749 | // pages are included in DebugString(). |
| 1750 | DCHECK_GT(stream.num_pages_, BufferedTupleStream::MAX_PAGE_ITER_DEBUG); |
| 1751 | string page_count_substr = Substitute( |
| 1752 | "$0 out of $1 pages=", BufferedTupleStream::MAX_PAGE_ITER_DEBUG, stream.num_pages_); |
| 1753 | string debug_string = stream.DebugString(); |
| 1754 | ASSERT_NE(debug_string.find(page_count_substr), string::npos) |
| 1755 | << page_count_substr << " not found at BufferedTupleStream::DebugString(). " |
| 1756 | << debug_string; |
| 1757 | ASSERT_LE(debug_string.length(), ErrorMsg::MAX_ERROR_MESSAGE_LEN); |
| 1758 | |
| 1759 | stream.Close(nullptr, RowBatch::FlushMode::NO_FLUSH_RESOURCES); |
| 1760 | } |
nothing calls this directly
no test coverage detected