1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright Epic Games, Inc. All Rights Reserved.
#if ZEN_WITH_TESTS
# include "zenserver-test.h"
# include <zencore/testing.h>
# include <zencore/testutils.h>
# include <zenutil/zenserverprocess.h>
# include <zenhttp/httpclient.h>
ZEN_THIRD_PARTY_INCLUDES_START
# include <tsl/robin_set.h>
ZEN_THIRD_PARTY_INCLUDES_END
namespace zen::tests {
using namespace std::literals;
TEST_SUITE_BEGIN("server.objectstore");
TEST_CASE("objectstore.blobs")
{
std::string_view Bucket = "bkt"sv;
std::vector<IoHash> CompressedBlobsHashes;
std::vector<uint64_t> BlobsSizes;
std::vector<uint64_t> CompressedBlobsSizes;
{
ZenServerInstance Instance(TestEnv);
const uint16_t PortNumber = Instance.SpawnServerAndWaitUntilReady(fmt::format("--objectstore-enabled"));
CHECK(PortNumber != 0);
HttpClient Client(Instance.GetBaseUri() + "/obj/");
for (size_t I = 0; I < 5; I++)
{
IoBuffer Blob = CreateSemiRandomBlob(4711 + I * 7);
BlobsSizes.push_back(Blob.GetSize());
CompressedBuffer CompressedBlob = CompressedBuffer::Compress(SharedBuffer(std::move(Blob)));
CompressedBlobsHashes.push_back(CompressedBlob.DecodeRawHash());
CompressedBlobsSizes.push_back(CompressedBlob.GetCompressedSize());
IoBuffer Payload = std::move(CompressedBlob).GetCompressed().Flatten().AsIoBuffer();
Payload.SetContentType(ZenContentType::kCompressedBinary);
std::string ObjectPath = fmt::format("{}/{}.utoc",
CompressedBlobsHashes.back().ToHexString().substr(0, 2),
CompressedBlobsHashes.back().ToHexString());
HttpClient::Response Result = Client.Put(fmt::format("bucket/{}/{}.utoc", Bucket, ObjectPath), Payload);
CHECK(Result);
}
for (size_t I = 0; I < 5; I++)
{
std::string ObjectPath =
fmt::format("{}/{}.utoc", CompressedBlobsHashes[I].ToHexString().substr(0, 2), CompressedBlobsHashes[I].ToHexString());
HttpClient::Response Result = Client.Get(fmt::format("bucket/{}/{}.utoc", Bucket, ObjectPath));
CHECK(Result);
CHECK_EQ(Result.ResponsePayload.GetSize(), CompressedBlobsSizes[I]);
IoHash RawHash;
uint64_t RawSize;
CompressedBuffer Compressed =
CompressedBuffer::FromCompressed(SharedBuffer(std::move(Result.ResponsePayload)), RawHash, RawSize);
CHECK(Compressed);
CHECK_EQ(RawHash, CompressedBlobsHashes[I]);
CHECK_EQ(RawSize, BlobsSizes[I]);
}
}
}
TEST_SUITE_END();
} // namespace zen::tests
#endif
|