| 784 | } |
| 785 | |
| 786 | void SimpleTupleStreamTest::TestTransferMemory(bool pin_stream, bool read_write) { |
| 787 | // Use smaller buffers so that the explicit FLUSH_RESOURCES flag is required to |
| 788 | // make the batch at capacity. |
| 789 | int buffer_size = 4 * 1024; |
| 790 | Init(100 * buffer_size); |
| 791 | |
| 792 | BufferedTupleStream stream( |
| 793 | runtime_state_, int_desc_, &client_, buffer_size, buffer_size); |
| 794 | ASSERT_OK(stream.Init("SimpleTupleStreamTest::TestTransferMemory", pin_stream)); |
| 795 | if (read_write) { |
| 796 | bool got_reservation; |
| 797 | ASSERT_OK(stream.PrepareForReadWrite(true, &got_reservation)); |
| 798 | ASSERT_TRUE(got_reservation); |
| 799 | } else { |
| 800 | bool got_write_reservation; |
| 801 | ASSERT_OK(stream.PrepareForWrite(&got_write_reservation)); |
| 802 | ASSERT_TRUE(got_write_reservation); |
| 803 | } |
| 804 | RowBatch* batch = CreateIntBatch(0, 1024, false); |
| 805 | |
| 806 | // Construct a stream with 4 pages. |
| 807 | const int total_num_pages = 4; |
| 808 | while (stream.byte_size() < total_num_pages * buffer_size) { |
| 809 | Status status; |
| 810 | for (int i = 0; i < batch->num_rows(); ++i) { |
| 811 | bool ret = stream.AddRow(batch->GetRow(i), &status); |
| 812 | EXPECT_TRUE(ret); |
| 813 | ASSERT_OK(status); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | batch->Reset(); |
| 818 | |
| 819 | if (read_write) { |
| 820 | // Read back batch so that we have a read buffer in memory. |
| 821 | bool eos; |
| 822 | ASSERT_OK(stream.GetNext(batch, &eos)); |
| 823 | EXPECT_FALSE(eos); |
| 824 | } |
| 825 | stream.Close(batch, RowBatch::FlushMode::FLUSH_RESOURCES); |
| 826 | if (pin_stream) { |
| 827 | EXPECT_EQ(total_num_pages, batch->num_buffers()); |
| 828 | } else if (read_write) { |
| 829 | // Read and write buffer should be attached. |
| 830 | EXPECT_EQ(2, batch->num_buffers()); |
| 831 | } else { |
| 832 | // Read buffer should be attached. |
| 833 | EXPECT_EQ(1, batch->num_buffers()); |
| 834 | } |
| 835 | EXPECT_TRUE(batch->AtCapacity()); // Flush resources flag should have been set. |
| 836 | batch->Reset(); |
| 837 | EXPECT_EQ(0, batch->num_buffers()); |
| 838 | } |
| 839 | |
| 840 | /// Test attaching memory to a row batch from a pinned stream. |
| 841 | TEST_F(SimpleTupleStreamTest, TransferMemoryFromPinnedStreamReadWrite) { |
nothing calls this directly
no test coverage detected