File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change 2020#include " concurrent_cache.h"
2121#include " gtest/gtest.h"
2222
23+ struct LazyValue
24+ {
25+ const int value;
26+ explicit LazyValue (int v) : value(v) {}
27+ int operator ()() const { return value; }
28+ };
29+
30+ struct ExceptionSource
31+ {
32+ int operator ()() const { throw std::runtime_error (" oops" ); return 0 ; }
33+ };
34+
2335TEST (ConcurrentCacheTest, handleException) {
2436 zim::ConcurrentCache<int , int > cache (1 );
25- auto val = cache.getOrPut (7 , []() { return 777 ; });
26- EXPECT_EQ (val, 777 );
27- EXPECT_THROW (cache.getOrPut (8 , []() { throw std::runtime_error (" oups" ); return 0 ; }), std::runtime_error);
28- val = cache.getOrPut (8 , []() { return 888 ; });
29- EXPECT_EQ (val, 888 );
37+ EXPECT_EQ (cache.getOrPut (7 , LazyValue (777 )), 777 );
38+ EXPECT_THROW (cache.getOrPut (8 , ExceptionSource ()), std::runtime_error);
39+ EXPECT_EQ (cache.getOrPut (8 , LazyValue (888 )), 888 );
3040}
You can’t perform that action at this time.
0 commit comments