@@ -169,12 +169,13 @@ TEST(BufferPoolManagerTest, DISABLED_PagePinMediumTest) {
169
169
snprintf (page0.GetDataMut (), BUSTUB_PAGE_SIZE, " Hello" );
170
170
EXPECT_EQ (0 , strcmp (page0.GetDataMut (), " Hello" ));
171
171
172
+ page0.Drop ();
173
+
172
174
// Create a vector of unique pointers to page guards, which prevents the guards from getting destructed.
173
- std::deque<WritePageGuard> pages;
174
- pages.push_back (std::move (page0));
175
+ std::vector<WritePageGuard> pages;
175
176
176
177
// Scenario: We should be able to create new pages until we fill up the buffer pool.
177
- for (size_t i = 1 ; i < FRAMES; i++) {
178
+ for (size_t i = 0 ; i < FRAMES; i++) {
178
179
auto pid = bpm->NewPage ();
179
180
auto page = bpm->WritePage (pid);
180
181
pages.push_back (std::move (page));
@@ -187,17 +188,17 @@ TEST(BufferPoolManagerTest, DISABLED_PagePinMediumTest) {
187
188
}
188
189
189
190
// Scenario: Once the buffer pool is full, we should not be able to create any new pages.
190
- for (size_t i = 0 ; i < 10 ; i++) {
191
+ for (size_t i = 0 ; i < FRAMES ; i++) {
191
192
auto pid = bpm->NewPage ();
192
193
auto fail = bpm->CheckedWritePage (pid);
193
194
ASSERT_FALSE (fail.has_value ());
194
195
}
195
196
196
197
// Scenario: Drop the first 5 pages to unpin them.
197
- for (size_t i = 0 ; i < 5 ; i++) {
198
+ for (size_t i = 0 ; i < FRAMES / 2 ; i++) {
198
199
page_id_t pid = pages[0 ].GetPageId ();
199
200
EXPECT_EQ (1 , bpm->GetPinCount (pid));
200
- pages.pop_front ( );
201
+ pages.erase (pages. begin () );
201
202
EXPECT_EQ (0 , bpm->GetPinCount (pid));
202
203
}
203
204
@@ -207,9 +208,9 @@ TEST(BufferPoolManagerTest, DISABLED_PagePinMediumTest) {
207
208
EXPECT_EQ (1 , bpm->GetPinCount (pid));
208
209
}
209
210
210
- // Scenario: After unpinning pages {0, 1, 2, 3, 4}, we should be able to create 4 new pages and bring them into
211
- // memory. Bringing those 4 pages into memory should evict the first 4 pages {0, 1, 2, 3} because of LRU.
212
- for (size_t i = 0 ; i < 4 ; i++) {
211
+ // Scenario: After unpinning pages {1, 2, 3, 4, 5 }, we should be able to create 4 new pages and bring them into
212
+ // memory. Bringing those 4 pages into memory should evict the first 4 pages {1, 2, 3, 4 } because of LRU.
213
+ for (size_t i = 0 ; i < ((FRAMES / 2 ) - 1 ) ; i++) {
213
214
auto pid = bpm->NewPage ();
214
215
auto page = bpm->WritePage (pid);
215
216
pages.push_back (std::move (page));
0 commit comments