| 31 | static scoped_ptr<Frontend> fe; |
| 32 | |
| 33 | TEST(CollectionValueBuilderTest, MaxBufferSize) { |
| 34 | TestEnv test_env; |
| 35 | ASSERT_OK(test_env.Init()); |
| 36 | TQueryOptions opts; |
| 37 | RuntimeState* runtime_state; |
| 38 | ASSERT_OK(test_env.CreateQueryState(1234, &opts, &runtime_state)); |
| 39 | ObjectPool obj_pool; |
| 40 | DescriptorTblBuilder builder(fe.get(), &obj_pool); |
| 41 | builder.DeclareTuple() << TYPE_TINYINT << TYPE_TINYINT << TYPE_TINYINT; |
| 42 | DescriptorTbl* desc_tbl = builder.Build(); |
| 43 | vector<TupleDescriptor*> descs; |
| 44 | desc_tbl->GetTupleDescs(&descs); |
| 45 | ASSERT_EQ(descs.size(), 1); |
| 46 | const TupleDescriptor& tuple_desc = *descs[0]; |
| 47 | // Tuple includes a null byte (4 = 1 + 3). |
| 48 | ASSERT_EQ(tuple_desc.byte_size(), 4); |
| 49 | |
| 50 | // Create CollectionValue with buffer size of slightly more than INT_MAX / 2 |
| 51 | CollectionValue coll_value; |
| 52 | int64_t initial_capacity = (INT_MAX / 8) + 1; |
| 53 | int64_t mem_limit = initial_capacity * 4 * 4; |
| 54 | MemTracker tracker(mem_limit); |
| 55 | MemPool pool(&tracker); |
| 56 | CollectionValueBuilder coll_value_builder( |
| 57 | &coll_value, tuple_desc, &pool, runtime_state, initial_capacity); |
| 58 | EXPECT_EQ(tracker.consumption(), initial_capacity * 4); |
| 59 | |
| 60 | // Attempt to double the buffer so it goes over 32-bit INT_MAX. |
| 61 | ASSERT_GT(tracker.consumption(), INT_MAX / 2); |
| 62 | coll_value_builder.CommitTuples(initial_capacity); |
| 63 | Tuple* tuple_mem; |
| 64 | int num_tuples; |
| 65 | EXPECT_OK(coll_value_builder.GetFreeMemory(&tuple_mem, &num_tuples)); |
| 66 | EXPECT_EQ(num_tuples, initial_capacity); |
| 67 | EXPECT_EQ(tracker.consumption(), initial_capacity * (1 + 2) * 4); |
| 68 | |
| 69 | // Attempt to double the buffer again but it will fail as it exceeds |
| 70 | // the memory limit. |
| 71 | coll_value_builder.CommitTuples(initial_capacity); |
| 72 | Status status = coll_value_builder.GetFreeMemory(&tuple_mem, &num_tuples); |
| 73 | EXPECT_FALSE(status.ok()); |
| 74 | EXPECT_EQ(num_tuples, 0); |
| 75 | EXPECT_EQ(tracker.consumption(), initial_capacity * (1 + 2) * 4); |
| 76 | |
| 77 | pool.FreeAll(); |
| 78 | } |
| 79 | |
| 80 | int main(int argc, char** argv) { |
| 81 | ::testing::InitGoogleTest(&argc, argv); |
nothing calls this directly
no test coverage detected