2121#include < memory>
2222
2323#include < gtest/gtest.h>
24-
2524#include < olp/core/cache/CacheSettings.h>
2625#include < olp/core/cache/KeyValueCache.h>
2726#include < olp/core/client/HRN.h>
3029#include < olp/core/logging/Log.h>
3130#include < olp/core/porting/make_unique.h>
3231#include < olp/core/utils/Dir.h>
32+ #include < olp/dataservice/read/CatalogClient.h>
3333#include < olp/dataservice/read/VersionedLayerClient.h>
3434#include < testutils/CustomParameters.hpp>
35-
3635#include " NetworkWrapper.h"
3736#include " NullCache.h"
3837
3938namespace {
40-
41- using CacheFactory =
42- std::function<std::shared_ptr<olp::cache::KeyValueCache>( )>;
39+ using KeyValueCachePtr = std::shared_ptr<olp::cache::KeyValueCache>;
40+ using CacheFactory = std::function<KeyValueCachePtr()>;
41+ using TestFunction = std::function<void ( uint8_t thread_id )>;
4342
4443struct TestConfiguration {
4544 std::string configuration_name;
@@ -59,6 +58,11 @@ std::ostream& operator<<(std::ostream& os, const TestConfiguration& config) {
5958 << " , .runtime=" << config.runtime .count () << " )" ;
6059}
6160
61+ constexpr std::chrono::milliseconds GetSleepPeriod (uint32_t requests) {
62+ return std::chrono::milliseconds (1000 / requests);
63+ }
64+
65+ constexpr auto kLogTag = " MemoryTest" ;
6266const olp::client::HRN kCatalog (" hrn:here:data::olp-here-test:testhrn" );
6367const std::string kVersionedLayerId (" versioned_test_layer" );
6468
@@ -68,17 +72,12 @@ class MemoryTest : public ::testing::TestWithParam<TestConfiguration> {
6872 static void TearDownTestSuite ();
6973
7074 olp::http::NetworkProxySettings GetLocalhostProxySettings ();
71-
7275 olp::client::OlpClientSettings CreateCatalogClientSettings ();
7376
7477 void SetUp () override ;
75-
7678 void TearDown () override ;
7779
78- using TestFunction = std::function<void (const std::uint8_t thread_id)>;
79-
8080 void StartThreads (TestFunction test_body);
81-
8281 void ReportError (const olp::client::ApiError& error);
8382
8483 protected:
@@ -98,9 +97,9 @@ class MemoryTest : public ::testing::TestWithParam<TestConfiguration> {
9897std::shared_ptr<olp::http::Network> MemoryTest::s_network;
9998
10099void MemoryTest::SetUpTestSuite () {
101- auto network = std::make_shared<olp::tests::http:: Http2HttpNetworkWrapper>();
102- network->EnableErrors ( true );
103- network->EnableTimeouts ( true );
100+ auto network = std::make_shared<Http2HttpNetworkWrapper>();
101+ network->WithErrors ( false );
102+ network->WithTimeouts ( false );
104103 s_network = std::move (network);
105104}
106105
@@ -156,27 +155,30 @@ void MemoryTest::TearDown() {
156155 }
157156 client_threads_.clear ();
158157
159- OLP_SDK_LOG_CRITICAL_INFO_F (" MemoryTest " ,
160- " Test finished. Total requests %zu, succeed "
158+ OLP_SDK_LOG_CRITICAL_INFO_F (kLogTag ,
159+ " Test finished, total requests %zu, succeed "
161160 " responses %zu, failed responses %zu" ,
162161 total_requests_.load (), success_responses_.load (),
163162 failed_responses_.load ());
164163
165164 for (const auto & error : errors_) {
166- OLP_SDK_LOG_CRITICAL_INFO_F (" MemoryTest " , " error %d - count %d" ,
167- error.first , error. second );
165+ OLP_SDK_LOG_CRITICAL_INFO_F (kLogTag , " error %d - count %d" , error. first ,
166+ error.second );
168167 }
169168
170169 size_t total_requests = success_responses_.load () + failed_responses_.load ();
171170 EXPECT_EQ (total_requests_.load (), total_requests);
171+
172+ // Reset network flags
173+ auto & network = dynamic_cast <Http2HttpNetworkWrapper&>(*s_network);
174+ network.WithErrors (false );
175+ network.WithTimeouts (false );
172176}
173177
174178void MemoryTest::StartThreads (TestFunction test_body) {
175- using namespace olp ;
176-
177179 const auto & parameter = GetParam ();
178180
179- for (std:: uint8_t i = 0 ; i < parameter.calling_thread_count ; ++i) {
181+ for (uint8_t i = 0 ; i < parameter.calling_thread_count ; ++i) {
180182 client_threads_.emplace_back (std::thread (test_body, i));
181183 }
182184}
@@ -193,9 +195,80 @@ void MemoryTest::ReportError(const olp::client::ApiError& error) {
193195 }
194196}
195197
198+ // /
199+ // / CatalogClient
200+ // /
201+
202+ TEST_P (MemoryTest, ReadLatestVersionCatalogClient) {
203+ const auto & parameter = GetParam ();
204+ auto settings = CreateCatalogClientSettings ();
205+
206+ StartThreads ([=](uint8_t thread_id) {
207+ olp::dataservice::read::CatalogClient service_client (kCatalog , settings);
208+
209+ const auto end_timestamp =
210+ std::chrono::steady_clock::now () + parameter.runtime ;
211+
212+ while (end_timestamp > std::chrono::steady_clock::now ()) {
213+ int64_t start_version = rand () % (100 + 1 );
214+
215+ auto request =
216+ olp::dataservice::read::CatalogVersionRequest ().WithStartVersion (
217+ start_version);
218+ total_requests_.fetch_add (1 );
219+ service_client.GetLatestVersion (
220+ request,
221+ [&](olp::dataservice::read::CatalogVersionResponse response) {
222+ if (response.IsSuccessful ()) {
223+ success_responses_.fetch_add (1 );
224+ } else {
225+ failed_responses_.fetch_add (1 );
226+ ReportError (response.GetError ());
227+ }
228+ });
229+
230+ std::this_thread::sleep_for (
231+ GetSleepPeriod (parameter.requests_per_second ));
232+ }
233+ });
234+ }
235+
236+ TEST_P (MemoryTest, ReadMetadataCatalogClient) {
237+ const auto & parameter = GetParam ();
238+ auto settings = CreateCatalogClientSettings ();
239+
240+ StartThreads ([=](uint8_t thread_id) {
241+ olp::dataservice::read::CatalogClient service_client (kCatalog , settings);
242+
243+ const auto end_timestamp =
244+ std::chrono::steady_clock::now () + parameter.runtime ;
245+
246+ while (end_timestamp > std::chrono::steady_clock::now ()) {
247+ auto request = olp::dataservice::read::CatalogRequest ();
248+ total_requests_.fetch_add (1 );
249+ service_client.GetCatalog (
250+ request, [&](olp::dataservice::read::CatalogResponse response) {
251+ if (response.IsSuccessful ()) {
252+ success_responses_.fetch_add (1 );
253+ } else {
254+ failed_responses_.fetch_add (1 );
255+ ReportError (response.GetError ());
256+ }
257+ });
258+
259+ std::this_thread::sleep_for (
260+ GetSleepPeriod (parameter.requests_per_second ));
261+ }
262+ });
263+ }
264+
265+ // /
266+ // / VersionedLayerClient
267+ // /
268+
196269/*
197- * Test performs N requests per second for M duration. All requests are unique.
198- * Total requests number calculated as:
270+ * Test performs N requests per second for M duration. All requests are
271+ * unique. Total requests number calculated as:
199272 *
200273 * total_count = requests_per_second * calling_thread_count
201274 *
@@ -206,12 +279,9 @@ void MemoryTest::ReportError(const olp::client::ApiError& error) {
206279TEST_P (MemoryTest, ReadNPartitionsFromVersionedLayer) {
207280 const auto & parameter = GetParam ();
208281
209- const auto sleep_interval =
210- std::chrono::milliseconds (1000 / parameter.requests_per_second );
211-
212282 auto settings = CreateCatalogClientSettings ();
213283
214- StartThreads ([=](const std:: uint8_t thread_id) {
284+ StartThreads ([=](uint8_t thread_id) {
215285 olp::dataservice::read::VersionedLayerClient service_client (
216286 kCatalog , kVersionedLayerId , settings);
217287
@@ -234,20 +304,18 @@ TEST_P(MemoryTest, ReadNPartitionsFromVersionedLayer) {
234304 }
235305 });
236306
237- std::this_thread::sleep_for (sleep_interval);
307+ std::this_thread::sleep_for (
308+ GetSleepPeriod (parameter.requests_per_second ));
238309 }
239310 });
240311}
241312
242313TEST_P (MemoryTest, PrefetchPartitionsFromVersionedLayer) {
243314 const auto & parameter = GetParam ();
244315
245- const auto sleep_interval =
246- std::chrono::milliseconds (1000 / parameter.requests_per_second );
247-
248316 auto settings = CreateCatalogClientSettings ();
249317
250- StartThreads ([=](const std:: uint8_t thread_id) {
318+ StartThreads ([=](uint8_t thread_id) {
251319 olp::dataservice::read::VersionedLayerClient service_client (
252320 kCatalog , kVersionedLayerId , settings);
253321
@@ -281,7 +349,8 @@ TEST_P(MemoryTest, PrefetchPartitionsFromVersionedLayer) {
281349 }
282350 });
283351
284- std::this_thread::sleep_for (sleep_interval);
352+ std::this_thread::sleep_for (
353+ GetSleepPeriod (parameter.requests_per_second ));
285354 }
286355 });
287356}
@@ -319,8 +388,8 @@ TestConfiguration ShortRunningTestWithMemoryCache() {
319388}
320389
321390/*
322- * Short 5 minutes test to collect SDK allocations with both in memory cache and
323- * disk cache.
391+ * Short 5 minutes test to collect SDK allocations with both in memory cache
392+ * and disk cache.
324393 */
325394TestConfiguration ShortRunningTestWithDiskCache () {
326395 using namespace olp ;
0 commit comments