blob: 97c3330ac9e68b53f0a61ea7a8e0c3030a227287 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/util/generationholder.h>
using vespalib::GenerationHolder;
using MyHeld = vespalib::GenerationHeldBase;
TEST(GenerationHolderTest, basic_tracking)
{
GenerationHolder gh;
gh.hold(std::make_unique<MyHeld>(sizeof(int32_t)));
gh.transferHoldLists(0);
gh.hold(std::make_unique<MyHeld>(sizeof(int32_t)));
gh.transferHoldLists(1);
gh.hold(std::make_unique<MyHeld>(sizeof(int32_t)));
gh.transferHoldLists(2);
gh.hold(std::make_unique<MyHeld>(sizeof(int32_t)));
gh.transferHoldLists(4);
EXPECT_EQ(4u * sizeof(int32_t), gh.getHeldBytes());
gh.trimHoldLists(0);
EXPECT_EQ(4u * sizeof(int32_t), gh.getHeldBytes());
gh.trimHoldLists(1);
EXPECT_EQ(3u * sizeof(int32_t), gh.getHeldBytes());
gh.trimHoldLists(2);
EXPECT_EQ(2u * sizeof(int32_t), gh.getHeldBytes());
gh.hold(std::make_unique<MyHeld>(sizeof(int32_t)));
gh.transferHoldLists(6);
EXPECT_EQ(3u * sizeof(int32_t), gh.getHeldBytes());
gh.trimHoldLists(6);
EXPECT_EQ(1u * sizeof(int32_t), gh.getHeldBytes());
gh.trimHoldLists(7);
EXPECT_EQ(0u * sizeof(int32_t), gh.getHeldBytes());
gh.trimHoldLists(7);
EXPECT_EQ(0u * sizeof(int32_t), gh.getHeldBytes());
}
GTEST_MAIN_RUN_ALL_TESTS()
|