17
17
*
18
18
*/
19
19
20
+ #define LIBZIM_ENABLE_LOGGING
21
+
20
22
#include " concurrent_cache.h"
21
23
#include " gtest/gtest.h"
22
24
@@ -38,3 +40,31 @@ TEST(ConcurrentCacheTest, handleException) {
38
40
EXPECT_THROW (cache.getOrPut (8 , ExceptionSource ()), std::runtime_error);
39
41
EXPECT_EQ (cache.getOrPut (8 , LazyValue (888 )), 888 );
40
42
}
43
+
44
+ TEST (ConcurrentCacheXRayTest, simpleFlow) {
45
+ zim::Logging::logIntoMemory ();
46
+ zim::ConcurrentCache<int , int , zim::UnitCostEstimation> cache (10 );
47
+ EXPECT_EQ (cache.getOrPut (3 , LazyValue (2025 )), 2025 );
48
+ EXPECT_EQ (cache.getOrPut (3 , LazyValue (123 )), 2025 );
49
+ EXPECT_THROW (cache.getOrPut (2 , ExceptionSource ()), std::runtime_error);
50
+
51
+ ASSERT_EQ (zim::Logging::getInMemLogContent (),
52
+ R"( thread#0: ConcurrentCache::getOrPut(3) {
53
+ thread#0: Obtained the cache slot
54
+ thread#0: It was a cache miss. Going to obtain the value...
55
+ thread#0: Value was successfully obtained. Computing its cost...
56
+ thread#0: cost=1. Committing to cache...
57
+ thread#0: Done. Cache cost is at 1
58
+ thread#0: } (return value: 2025)
59
+ thread#0: ConcurrentCache::getOrPut(3) {
60
+ thread#0: Obtained the cache slot
61
+ thread#0: } (return value: 2025)
62
+ thread#0: ConcurrentCache::getOrPut(2) {
63
+ thread#0: Obtained the cache slot
64
+ thread#0: It was a cache miss. Going to obtain the value...
65
+ thread#0: Evaluation failed. Releasing the cache slot...
66
+ thread#0: ConcurrentCache::drop(2) {
67
+ thread#0: } (return value: )
68
+ thread#0: } (return value: )
69
+ )" );
70
+ }
0 commit comments