Skip to content

Commit b1088b4

Browse files
Performance testing on android.
Added data validation. Fixed Android proxy. Fixed network initialization.
1 parent d5630ed commit b1088b4

File tree

8 files changed

+113
-78
lines changed

8 files changed

+113
-78
lines changed

external/boost/CMakeLists.txt.boost.in

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ include(ExternalProject)
2424
ExternalProject_Add(boost-download
2525
GIT_REPOSITORY @OLP_SDK_CPP_BOOST_URL@
2626
GIT_TAG @OLP_SDK_CPP_BOOST_TAG@
27-
GIT_SUBMODULES libs/any
27+
GIT_SUBMODULES libs/algorithm
28+
libs/any
2829
libs/assert
2930
libs/config
3031
libs/container_hash
3132
libs/core
3233
libs/detail
34+
libs/exception
3335
libs/format
3436
libs/function_types
3537
libs/headers
@@ -43,6 +45,7 @@ ExternalProject_Add(boost-download
4345
libs/predef
4446
libs/preprocessor
4547
libs/random
48+
libs/range
4649
libs/serialization
4750
libs/smart_ptr
4851
libs/static_assert

olp-cpp-sdk-core/src/http/android/HttpClient.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ public Request(
113113
this.proxyPort = proxyPort;
114114

115115
switch (proxyType) {
116-
case 0:
116+
case 1:
117117
this.proxyType = Proxy.Type.HTTP;
118118
break;
119-
case 4:
119+
case 2:
120120
this.proxyType = Proxy.Type.SOCKS;
121121
break;
122+
case 3:
123+
case 4:
122124
case 5:
123-
case 6:
124-
case 7:
125125
this.proxyType = Proxy.Type.SOCKS;
126126
Log.w(
127127
LOGTAG,
@@ -318,7 +318,7 @@ protected Void doInBackground(Request... requests) {
318318
conn.setRequestProperty("Connection", "Close");
319319
}
320320

321-
Log.d(LOGTAG, "Printing Request Headers...\n");
321+
//Log.d(LOGTAG, "Printing Request Headers...\n");
322322
uploadedContentSize += calculateHeadersSize(conn.getRequestProperties());
323323

324324
conn.setDoInput(true);
@@ -327,7 +327,7 @@ protected Void doInBackground(Request... requests) {
327327
if (request.postData() != null) {
328328
conn.setDoOutput(true);
329329
conn.getOutputStream().write(request.postData());
330-
Log.d(LOGTAG, "Uploaded data length:" + request.postData().length);
330+
//Log.d(LOGTAG, "Uploaded data length:" + request.postData().length);
331331
uploadedContentSize += request.postData().length;
332332
} else {
333333
conn.setDoOutput(false);
@@ -385,7 +385,7 @@ protected Void doInBackground(Request... requests) {
385385
}
386386
}
387387

388-
Log.d(LOGTAG, "Printing Response Headers...\n");
388+
//Log.d(LOGTAG, "Printing Response Headers...\n");
389389
downloadContentSize += calculateHeadersSize(conn.getHeaderFields());
390390

391391
int contentSize = conn.getContentLength();
@@ -560,7 +560,7 @@ private final int calculateHeadersSize(Map<String, List<String>> headers) throws
560560
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
561561
String header = entry.getKey();
562562
List<String> values = entry.getValue();
563-
Log.d(LOGTAG, header + ":" + values);
563+
//Log.d(LOGTAG, header + ":" + values);
564564
if(header != null) {
565565
size += header.length();
566566
}

olp-cpp-sdk-core/src/http/android/NetworkAndroid.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,15 @@ bool NetworkAndroid::Initialize() {
408408
}
409409

410410
run_thread_ = std::make_unique<std::thread>(NetworkAndroid::Run, this);
411+
412+
initialized_ = true;
413+
411414
{
412415
if (!started_) {
413416
run_thread_ready_cv_.wait(lock);
414417
}
415418
}
416419

417-
initialized_ = true;
418420
return true;
419421
}
420422

@@ -1048,18 +1050,20 @@ RequestId NetworkAndroid::GenerateNextRequestId() {
10481050
NetworkAndroid::RequestData::RequestData(
10491051
Network::Callback callback, Network::HeaderCallback header_callback,
10501052
Network::DataCallback data_callback, const std::string& url,
1051-
const std::shared_ptr<std::ostream>& payload)
1053+
Network::Payload payload)
10521054
: callback(callback),
10531055
header_callback(header_callback),
10541056
data_callback(data_callback),
10551057
url(url),
10561058
payload(payload),
1057-
obj(nullptr) {}
1059+
obj(nullptr),
1060+
count(0),
1061+
offset(0) {}
10581062

10591063
NetworkAndroid::ResponseData::ResponseData(
10601064
RequestId id, Network::Callback callback, int status, int uploaded_bytes,
10611065
int downloaded_bytes, const char* error, const char* content_type,
1062-
jlong count, jlong offset, std::shared_ptr<std::ostream> payload)
1066+
jlong count, jlong offset, Network::Payload payload)
10631067
: id(id),
10641068
callback(callback),
10651069
payload(payload),

olp-cpp-sdk-core/src/http/android/NetworkAndroid.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class NetworkAndroid : public Network {
131131
RequestData(Network::Callback callback,
132132
Network::HeaderCallback header_callback,
133133
Network::DataCallback data_callback, const std::string& url,
134-
const std::shared_ptr<std::ostream>& payload);
134+
Network::Payload payload);
135135

136136
void Reinitialize() {
137137
obj = nullptr;
@@ -142,7 +142,7 @@ class NetworkAndroid : public Network {
142142
Network::HeaderCallback header_callback;
143143
Network::DataCallback data_callback;
144144
std::string url;
145-
std::shared_ptr<std::ostream> payload;
145+
Network::Payload payload;
146146
jobject obj;
147147
jlong count;
148148
jlong offset;
@@ -155,12 +155,12 @@ class NetworkAndroid : public Network {
155155
ResponseData(RequestId id, Network::Callback callback, int status,
156156
int uploaded_bytes, int downloaded_bytes, const char* error,
157157
const char* content_type, jlong count, jlong offset,
158-
std::shared_ptr<std::ostream> payload);
158+
Network::Payload payload);
159159
bool IsValid() const { return (callback != nullptr); }
160160

161161
RequestId id = static_cast<RequestId>(RequestIdConstants::RequestIdInvalid);
162162
Network::Callback callback;
163-
std::shared_ptr<std::ostream> payload;
163+
Network::Payload payload;
164164
std::string error;
165165
std::string content_type;
166166
int status = 0;

tests/performance/CMakeLists.txt

+34-13
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
# SPDX-License-Identifier: Apache-2.0
1616
# License-Filename: LICENSE
1717

18-
if (ANDROID OR IOS)
19-
message(STATUS "Currently the performance test runner for mobile platforms is not supported")
20-
return()
21-
endif()
22-
2318
set(OLP_SDK_PERFORMANCE_TESTS_SOURCES
2419
./MemoryTest.cpp
2520
./MemoryTestBase.h
@@ -28,11 +23,37 @@ set(OLP_SDK_PERFORMANCE_TESTS_SOURCES
2823
./PrefetchTest.cpp
2924
)
3025

31-
add_executable(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_SOURCES})
32-
target_link_libraries(olp-cpp-sdk-performance-tests
33-
PRIVATE
34-
custom-params
35-
gtest_main
36-
olp-cpp-sdk-authentication
37-
olp-cpp-sdk-dataservice-read
38-
)
26+
if (ANDROID OR IOS)
27+
set(OLP_SDK_PERFORMANCE_TESTS_LIB olp-cpp-sdk-performance-tests-lib)
28+
29+
add_library(${OLP_SDK_PERFORMANCE_TESTS_LIB} ${OLP_SDK_PERFORMANCE_TESTS_SOURCES})
30+
target_link_libraries(${OLP_SDK_PERFORMANCE_TESTS_LIB}
31+
PRIVATE
32+
custom-params
33+
gtest
34+
olp-cpp-sdk-authentication
35+
olp-cpp-sdk-dataservice-read
36+
)
37+
38+
if (ANDROID)
39+
include(${CMAKE_SOURCE_DIR}/cmake/android/gen_android_test.cmake)
40+
gen_android_test_runner(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_LIB})
41+
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/android ${CMAKE_CURRENT_BINARY_DIR}/android)
42+
else()
43+
include(${CMAKE_SOURCE_DIR}/cmake/ios/gen_ios_test.cmake)
44+
gen_ios_test_runner(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_LIB})
45+
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/ios ${CMAKE_CURRENT_BINARY_DIR}/ios)
46+
endif()
47+
48+
else()
49+
50+
add_executable(olp-cpp-sdk-performance-tests ${OLP_SDK_PERFORMANCE_TESTS_SOURCES})
51+
target_link_libraries(olp-cpp-sdk-performance-tests
52+
PRIVATE
53+
custom-params
54+
gtest_main
55+
olp-cpp-sdk-authentication
56+
olp-cpp-sdk-dataservice-read
57+
)
58+
59+
endif()

tests/performance/MemoryTest.cpp

+42-47
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,52 @@
2020
#include <chrono>
2121
#include <memory>
2222

23+
#include <boost/uuid/detail/sha1.hpp>
24+
#include <boost/algorithm/hex.hpp>
25+
2326
#include <gtest/gtest.h>
2427
#include <olp/core/client/HRN.h>
2528
#include <olp/core/logging/Log.h>
2629
#include <olp/dataservice/read/VersionedLayerClient.h>
2730

2831
#include "MemoryTestBase.h"
2932

33+
std::string ComputeSha1(const char* buffer, size_t length) {
34+
using boost::uuids::detail::sha1;
35+
sha1 hash;
36+
sha1::digest_type digest;
37+
sha1::digest_type digest_rotated;
38+
39+
hash.process_bytes(buffer, length);
40+
hash.get_digest(digest);
41+
42+
// rotate bytes
43+
for (int i = 0; i < 5; ++i)
44+
{
45+
const char* tmp = reinterpret_cast<char*>(&digest);
46+
char* res = reinterpret_cast<char*>(&digest_rotated);
47+
res[i*4] = tmp[i*4+3];
48+
res[i*4+1] = tmp[i*4+2];
49+
res[i*4+2] = tmp[i*4+1];
50+
res[i*4+3] = tmp[i*4];
51+
}
52+
53+
const auto charDigest = reinterpret_cast<const char*>(&digest_rotated);
54+
std::string result;
55+
boost::algorithm::hex(charDigest, charDigest + sizeof(sha1::digest_type),
56+
std::back_inserter(result));
57+
return result;
58+
}
59+
60+
bool Validate(const std::vector<unsigned char>& buffer) {
61+
// 40 first bytes is a string representation of hash
62+
const char* bytes = reinterpret_cast<const char*>( buffer.data() );
63+
std::string hash(bytes, bytes + 40);
64+
std::string computed_hash = ComputeSha1(bytes + 40, buffer.size() - 40);
65+
OLP_SDK_LOG_CRITICAL_INFO_F("HASH", "HASHES: %s %s", hash.c_str(), computed_hash.c_str());
66+
return hash == computed_hash;
67+
}
68+
3069
namespace {
3170
using TestFunction = std::function<void(uint8_t thread_id)>;
3271

@@ -183,53 +222,9 @@ TEST_P(MemoryTest, ReadNPartitionsFromVersionedLayer) {
183222
request, [&](olp::dataservice::read::DataResponse response) {
184223
if (response.IsSuccessful()) {
185224
success_responses_.fetch_add(1);
186-
} else {
187-
failed_responses_.fetch_add(1);
188-
ReportError(response.GetError());
189-
}
190-
});
191-
192-
RandomlyCancel(std::move(token));
193-
194-
std::this_thread::sleep_for(
195-
GetSleepPeriod(parameter.requests_per_second));
196-
}
197-
});
198-
}
199-
200-
TEST_P(MemoryTest, PrefetchPartitionsFromVersionedLayer) {
201-
// Enable only errors to have a short output.
202-
olp::logging::Log::setLevel(olp::logging::Level::Warning);
203-
204-
const auto& parameter = GetParam();
205-
206-
auto settings = CreateCatalogClientSettings();
207-
208-
StartThreads([=](uint8_t /*thread_id*/) {
209-
olp::dataservice::read::VersionedLayerClient service_client(
210-
kCatalog, kVersionedLayerId, boost::none, settings);
211-
212-
const auto end_timestamp =
213-
std::chrono::steady_clock::now() + parameter.runtime;
214-
215-
while (end_timestamp > std::chrono::steady_clock::now()) {
216-
const auto level = 10;
217-
const auto tile_count = 1 << level;
218-
219-
std::vector<olp::geo::TileKey> tile_keys = {
220-
olp::geo::TileKey::FromRowColumnLevel(rand() % tile_count,
221-
rand() % tile_count, level)};
222-
223-
auto request = olp::dataservice::read::PrefetchTilesRequest()
224-
.WithMaxLevel(level + 2)
225-
.WithMinLevel(level)
226-
.WithTileKeys(tile_keys);
227-
total_requests_.fetch_add(1);
228-
auto token = service_client.PrefetchTiles(
229-
std::move(request),
230-
[&](olp::dataservice::read::PrefetchTilesResponse response) {
231-
if (response.IsSuccessful()) {
232-
success_responses_.fetch_add(1);
225+
if (!Validate(*response.GetResult())) {
226+
abort();
227+
}
233228
} else {
234229
failed_responses_.fetch_add(1);
235230
ReportError(response.GetError());

tests/performance/MemoryTestBase.h

+5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ class MemoryTestBase : public ::testing::TestWithParam<Param> {
4646
protected:
4747
olp::http::NetworkProxySettings GetLocalhostProxySettings() {
4848
return olp::http::NetworkProxySettings()
49+
#if ANDROID
50+
.WithHostname("10.0.2.2")
51+
#else
4952
.WithHostname("localhost")
53+
#endif
5054
.WithPort(3000)
5155
.WithUsername("test_user")
5256
.WithPassword("test_password")
@@ -78,6 +82,7 @@ class MemoryTestBase : public ::testing::TestWithParam<Param> {
7882
client_settings.cache =
7983
parameter.cache_factory ? parameter.cache_factory() : nullptr;
8084
client_settings.retry_settings.timeout = 1;
85+
//client_settings.retry_settings.max_attempts = 0;
8186

8287
return client_settings;
8388
}

tests/utils/olp_server/blob_service.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20+
var crypto = require('crypto')
21+
22+
function computeHash(data) {
23+
return crypto.createHash('sha1').update(data).digest('hex').toUpperCase();
24+
}
25+
2026
function generateGetBlobApiResponse(request) {
2127
const layer = request[1]
2228
const dataHandle = request[2] // ignored
@@ -30,7 +36,8 @@ function generateGetBlobApiResponse(request) {
3036
response += characters.charAt(Math.floor(Math.random() * charactersLength));
3137
}
3238

33-
return response;
39+
//console.log(computeHash(response))
40+
return computeHash(response) + response;
3441
}
3542

3643
const methods = [

0 commit comments

Comments
 (0)