diff options
Diffstat (limited to 'zenserver-test/zenserver-test.cpp')
| -rw-r--r-- | zenserver-test/zenserver-test.cpp | 89 |
1 files changed, 58 insertions, 31 deletions
diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp index 85393aed2..425f43946 100644 --- a/zenserver-test/zenserver-test.cpp +++ b/zenserver-test/zenserver-test.cpp @@ -1827,7 +1827,8 @@ TEST_CASE("zcache.rpc") Data[Idx] = Idx % 255; } - zen::CbAttachment Attachment(zen::CompressedBuffer::Compress(SharedBuffer::MakeView(Data.data(), Data.size()))); + CompressedBuffer Value = zen::CompressedBuffer::Compress(SharedBuffer::MakeView(Data.data(), Data.size())); + zen::CbAttachment Attachment(Value); Writer.BeginObject(); { @@ -1838,7 +1839,17 @@ TEST_CASE("zcache.rpc") Writer << "Bucket"sv << CacheKey.Bucket << "Hash"sv << CacheKey.Hash; } Writer.EndObject(); - Writer << "Data"sv << Attachment; + Writer.BeginArray("Values"sv); + { + Writer.BeginObject(); + { + Writer.AddObjectId("Id"sv, Oid::NewOid()); + Writer.AddBinaryAttachment("RawHash"sv, IoHash::FromBLAKE3(Value.GetRawHash())); + Writer.AddInteger("RawSize"sv, Value.GetRawSize()); + } + Writer.EndObject(); + } + Writer.EndArray(); } Writer.EndObject(); Writer.SetName("Policy"sv); @@ -1862,7 +1873,7 @@ TEST_CASE("zcache.rpc") for (uint32_t Key = 1; Key <= Num; ++Key) { - zen::IoHash KeyHash; + zen::IoHash KeyHash; ((uint32_t*)(KeyHash.Hash))[0] = Key; const zen::CacheKey CacheKey = zen::CacheKey::Create(Bucket, KeyHash); CbPackage Package; @@ -1907,27 +1918,30 @@ TEST_CASE("zcache.rpc") bool Success; }; - auto GetCacheRecords = - [](std::string_view BaseUri, std::span<zen::CacheKey> Keys, const zen::CacheRecordPolicy& Policy) -> GetCacheRecordResult { + auto GetCacheRecords = [](std::string_view BaseUri, std::span<zen::CacheKey> Keys, zen::CachePolicy Policy) -> GetCacheRecordResult { using namespace zen; CbObjectWriter Request; Request << "Method"sv << "GetCacheRecords"sv; Request.BeginObject("Params"sv); - - Request.BeginArray("CacheKeys"sv); - for (const CacheKey& Key : Keys) { - Request.BeginObject(); - Request << "Bucket"sv << Key.Bucket << "Hash"sv << Key.Hash; - Request.EndObject(); + Request << "DefaultPolicy"sv << WriteToString<128>(Policy); + Request.BeginArray("Requests"sv); + for (const CacheKey& Key : Keys) + { + Request.BeginObject(); + { + Request.BeginObject("Key"sv); + { + Request << "Bucket"sv << Key.Bucket << "Hash"sv << Key.Hash; + } + Request.EndObject(); + } + Request.EndObject(); + } + Request.EndArray(); } - Request.EndArray(); - - Request.SetName("Policy"sv); - Policy.Save(Request); - Request.EndObject(); BinaryWriter Body; @@ -1978,7 +1992,7 @@ TEST_CASE("zcache.rpc") Inst.SpawnServer(PortNumber); Inst.WaitUntilReady(); - CacheRecordPolicy Policy; + CachePolicy Policy = CachePolicy::Default; std::vector<zen::CacheKey> Keys = PutCacheRecords(BaseUri, "mastodon"sv, 128); GetCacheRecordResult Result = GetCacheRecords(BaseUri, Keys, Policy); @@ -1988,11 +2002,18 @@ TEST_CASE("zcache.rpc") { const CacheKey& ExpectedKey = Keys[Index++]; - CbObjectView RecordObj = RecordView.AsObjectView(); - CbObjectView KeyObj = RecordObj["Key"sv].AsObjectView(); - const CacheKey Key = CacheKey::Create(KeyObj["Bucket"sv].AsString(), KeyObj["Hash"].AsHash()); - const IoHash AttachmentHash = RecordObj["Data"sv].AsHash(); - const CbAttachment* Attachment = Result.Response.FindAttachment(AttachmentHash); + CbObjectView RecordObj = RecordView.AsObjectView(); + CbObjectView KeyObj = RecordObj["Key"sv].AsObjectView(); + const CacheKey Key = CacheKey::Create(KeyObj["Bucket"sv].AsString(), KeyObj["Hash"].AsHash()); + IoHash AttachmentHash; + size_t NumValues = 0; + for (CbFieldView Value : RecordObj["Values"sv]) + { + AttachmentHash = Value.AsObjectView()["RawHash"sv].AsHash(); + ++NumValues; + } + CHECK(NumValues == 1); + const CbAttachment* Attachment = Result.Response.FindAttachment(AttachmentHash); CHECK(Key == ExpectedKey); CHECK(Attachment != nullptr); @@ -2010,7 +2031,7 @@ TEST_CASE("zcache.rpc") Inst.SpawnServer(PortNumber); Inst.WaitUntilReady(); - CacheRecordPolicy Policy; + CachePolicy Policy = CachePolicy::Default; std::vector<zen::CacheKey> ExistingKeys = PutCacheRecords(BaseUri, "mastodon"sv, 128); std::vector<zen::CacheKey> Keys; @@ -2035,12 +2056,18 @@ TEST_CASE("zcache.rpc") } else { - const CacheKey& ExpectedKey = ExistingKeys[KeyIndex++]; - CbObjectView RecordObj = RecordView.AsObjectView(); - zen::CacheKey Key = LoadKey(RecordObj["Key"sv]); - const IoHash AttachmentHash = RecordObj["Data"sv].AsHash(); - const CbAttachment* Attachment = Result.Response.FindAttachment(AttachmentHash); - + const CacheKey& ExpectedKey = ExistingKeys[KeyIndex++]; + CbObjectView RecordObj = RecordView.AsObjectView(); + zen::CacheKey Key = LoadKey(RecordObj["Key"sv]); + IoHash AttachmentHash; + size_t NumValues = 0; + for (CbFieldView Value : RecordObj["Values"sv]) + { + AttachmentHash = Value.AsObjectView()["RawHash"sv].AsHash(); + ++NumValues; + } + CHECK(NumValues == 1); + const CbAttachment* Attachment = Result.Response.FindAttachment(AttachmentHash); CHECK(Key == ExpectedKey); CHECK(Attachment != nullptr); } @@ -2061,7 +2088,7 @@ TEST_CASE("zcache.rpc") std::vector<zen::CacheKey> Keys = PutCacheRecords(UpstreamCfg.BaseUri, "mastodon"sv, 4); - CacheRecordPolicy Policy(CachePolicy::QueryLocal); + CachePolicy Policy = CachePolicy::QueryLocal; GetCacheRecordResult Result = GetCacheRecords(LocalCfg.BaseUri, Keys, Policy); CHECK(Result.Records.size() == Keys.size()); @@ -2086,7 +2113,7 @@ TEST_CASE("zcache.rpc") std::vector<zen::CacheKey> Keys = PutCacheRecords(UpstreamCfg.BaseUri, "mastodon"sv, 4); - CacheRecordPolicy Policy(CachePolicy::QueryLocal | CachePolicy::QueryRemote); + CachePolicy Policy = (CachePolicy::QueryLocal | CachePolicy::QueryRemote); GetCacheRecordResult Result = GetCacheRecords(LocalCfg.BaseUri, Keys, Policy); CHECK(Result.Records.size() == Keys.size()); |