@@ -990,6 +990,79 @@ TEST_F(DefaultCacheImplTest, LruCacheEvictionWithProtected) {
990990 }
991991}
992992
993+ // SCOPED_TRACE("Expiry protected cache");
994+ // const std::string key1{"somekey1"};
995+ // const std::string key2{"somekey2"};
996+ // const std::string data_string{"this is key's data"};
997+ // constexpr auto expiry = 2;
998+ // std::vector<unsigned char> binary_data = {1, 2, 3};
999+ // const auto data_ptr =
1000+ // std::make_shared<std::vector<unsigned char>>(binary_data);
1001+ //
1002+ // cache::CacheSettings settings1;
1003+ // settings1.disk_path_mutable = cache_path_;
1004+ // DefaultCacheImplHelper cache1(settings1);
1005+ // cache1.Open();
1006+ // cache1.Clear();
1007+ //
1008+ // cache1.Put(key1, data_ptr, expiry);
1009+ // cache1.Put(key2, data_string, [=]() { return data_string; }, expiry);
1010+ // cache1.Close();
1011+ //
1012+ // cache::CacheSettings settings2;
1013+ // settings2.disk_path_protected = cache_path_;
1014+ // DefaultCacheImplHelper cache2(settings2);
1015+ // cache2.Open();
1016+ //
1017+ // const auto value = cache2.Get(key1);
1018+ // const auto value2 =
1019+ // cache2.Get(key2, [](const std::string& value) { return value; });
1020+ //
1021+ // EXPECT_FALSE(value.get() == nullptr);
1022+ // EXPECT_EQ(value2.type(), typeid(std::string));
1023+ // auto str = boost::any_cast<std::string>(value2);
1024+ // EXPECT_EQ(str, data_string);
1025+ //
1026+ // std::this_thread::sleep_for(std::chrono::seconds(3));
1027+ //
1028+ // EXPECT_TRUE(cache2.Get(key1).get() == nullptr);
1029+ // EXPECT_TRUE(
1030+ // cache2.Get(key2, [](const std::string& value) { return value;
1031+ // }).empty());
1032+ // cache2.Close();
1033+
1034+ TEST_F (DefaultCacheImplTest, InternalKeysBypassLru) {
1035+ {
1036+ SCOPED_TRACE (" Protect and release keys, which suppose to be evicted" );
1037+
1038+ const auto internal_key{" internal::protected::protected_data" };
1039+ cache::CacheSettings settings;
1040+ settings.disk_path_mutable = cache_path_;
1041+ settings.max_disk_storage = 2u * 1024u * 1024u ;
1042+ {
1043+ DefaultCacheImplHelper cache (settings);
1044+ ASSERT_EQ (olp::cache::DefaultCache::Success, cache.Open ());
1045+ cache.Clear ();
1046+ const std::string key{" somekey" };
1047+ std::string data_string{" this is key's data" };
1048+
1049+ constexpr auto expiry = 2 ;
1050+ EXPECT_TRUE (cache.Put (key, data_string,
1051+ [data_string]() { return data_string; }, expiry));
1052+ ASSERT_TRUE (cache.Protect ({key}));
1053+ }
1054+
1055+ settings.disk_path_mutable = cache_path_;
1056+ settings.disk_path_protected .reset ();
1057+
1058+ DefaultCacheImplHelper cache (settings);
1059+ ASSERT_TRUE (cache.Open ());
1060+ // no keys was evicted
1061+ EXPECT_TRUE (cache.Get (internal_key));
1062+ cache.Clear ();
1063+ }
1064+ }
1065+
9931066TEST_F (DefaultCacheImplTest, ReadOnlyPartitionForProtectedCache) {
9941067 SCOPED_TRACE (" Read only partition protected cache" );
9951068 const std::string key{" somekey" };
0 commit comments