@@ -43,10 +43,11 @@ TEST(ConcurrentCacheTest, handleException) {
43
43
44
44
TEST (ConcurrentCacheXRayTest, simpleFlow) {
45
45
zim::Logging::logIntoMemory ();
46
- zim::ConcurrentCache<int , int , zim::UnitCostEstimation> cache (10 );
46
+ zim::ConcurrentCache<int , int , zim::UnitCostEstimation> cache (1 );
47
47
EXPECT_EQ (cache.getOrPut (3 , LazyValue (2025 )), 2025 );
48
48
EXPECT_EQ (cache.getOrPut (3 , LazyValue (123 )), 2025 );
49
49
EXPECT_THROW (cache.getOrPut (2 , ExceptionSource ()), std::runtime_error);
50
+ EXPECT_EQ (cache.getOrPut (2 , LazyValue (123 )), 123 );
50
51
51
52
ASSERT_EQ (zim::Logging::getInMemLogContent (),
52
53
R"( thread#0: ConcurrentCache::getOrPut(3) {
@@ -60,6 +61,8 @@ thread#0: It was a cache miss. Going to obtain the value...
60
61
thread#0: Value was successfully obtained. Computing its cost...
61
62
thread#0: cost=1. Committing to cache...
62
63
thread#0: lru_cache::increaseCost(1) {
64
+ thread#0: _current_cost after increase: 1
65
+ thread#0: settled _current_cost: 1
63
66
thread#0: }
64
67
thread#0: Done. Cache cost is at 1
65
68
thread#0: } (return value: 2025)
@@ -81,9 +84,32 @@ thread#0: Evaluation failed. Releasing the cache slot...
81
84
thread#0: ConcurrentCache::drop(2) {
82
85
thread#0: lru_cache::drop(2) {
83
86
thread#0: lru_cache::decreaseCost(0) {
87
+ thread#0: _current_cost after decrease: 1
84
88
thread#0: }
85
89
thread#0: }
86
90
thread#0: }
87
91
thread#0: }
92
+ thread#0: ConcurrentCache::getOrPut(2) {
93
+ thread#0: lru_cache::getOrPut(2) {
94
+ thread#0: not in cache, adding...
95
+ thread#0: lru_cache::increaseCost(0) {
96
+ thread#0: }
97
+ thread#0: }
98
+ thread#0: Obtained the cache slot
99
+ thread#0: It was a cache miss. Going to obtain the value...
100
+ thread#0: Value was successfully obtained. Computing its cost...
101
+ thread#0: cost=1. Committing to cache...
102
+ thread#0: lru_cache::increaseCost(1) {
103
+ thread#0: _current_cost after increase: 2
104
+ thread#0: lru_cache::dropLast() {
105
+ thread#0: evicting entry with key: 3
106
+ thread#0: lru_cache::decreaseCost(1) {
107
+ thread#0: _current_cost after decrease: 1
108
+ thread#0: }
109
+ thread#0: }
110
+ thread#0: settled _current_cost: 1
111
+ thread#0: }
112
+ thread#0: Done. Cache cost is at 1
113
+ thread#0: } (return value: 123)
88
114
)" );
89
115
}
0 commit comments