-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathclient_ut.cpp
92 lines (65 loc) · 2.49 KB
/
client_ut.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "client.h"
#include "config.h"
#include <cloud/filestore/libs/diagnostics/profile_log.h>
#include <cloud/filestore/libs/diagnostics/request_stats.h>
#include <cloud/filestore/libs/server/config.h>
#include <cloud/filestore/libs/server/server.h>
#include <cloud/filestore/libs/service/context.h>
#include <cloud/filestore/libs/service/filestore_test.h>
#include <cloud/storage/core/libs/common/error.h>
#include <cloud/storage/core/libs/diagnostics/logging.h>
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/testing/unittest/tests_data.h>
#include <util/datetime/base.h>
namespace NCloud::NFileStore::NClient {
using namespace NThreading;
using namespace NCloud::NFileStore::NServer;
namespace {
////////////////////////////////////////////////////////////////////////////////
constexpr TDuration WaitTimeout = TDuration::Seconds(5);
TPortManager PortManager;
std::pair<TClientConfigPtr, TServerConfigPtr> CreateConfigs()
{
NProto::TClientConfig client;
client.SetPort(PortManager.GetPort(9021));
NProto::TServerConfig server;
server.SetPort(client.GetPort());
return {
std::make_shared<TClientConfig>(client),
std::make_shared<TServerConfig>(server),
};
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
Y_UNIT_TEST_SUITE(TFileStoreClientTest)
{
Y_UNIT_TEST(ShouldHandleRequests)
{
auto logging = CreateLoggingService("console");
auto service = std::make_shared<TFileStoreTest>();
service->PingHandler = [] (auto, auto) {
return MakeFuture<NProto::TPingResponse>();
};
auto [clientConfig, serverConfig] = CreateConfigs();
auto registry = CreateRequestStatsRegistryStub();
auto server = CreateServer(
serverConfig,
logging,
registry->GetRequestStats(),
CreateProfileLogStub(),
service);
server->Start();
auto client = CreateFileStoreClient(clientConfig, logging);
client->Start();
auto context = MakeIntrusive<TCallContext>();
auto request = std::make_shared<NProto::TPingRequest>();
auto future = client->Ping(
std::move(context),
std::move(request));
const auto& response = future.GetValue(WaitTimeout);
UNIT_ASSERT_C(!HasError(response), FormatError(response.GetError()));
client->Stop();
server->Stop();
}
}
} // namespace NCloud::NFileStore::NClient