Skip to content

Commit 1e64a08

Browse files
committed
- Added Snappy compression/decompression test case to the remote test app
1 parent e0cd859 commit 1e64a08

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ FetchContent_Declare(
8686
FetchContent_Declare(
8787
snappy
8888
GIT_REPOSITORY https://github.com/google/snappy.git
89-
GIT_TAG 1.1.10
89+
GIT_TAG 1.2.2
9090
)
9191

9292
# Fetch dependencies
@@ -222,9 +222,12 @@ target_link_libraries(dbpa_remote_testapp
222222
dbps_remote_lib
223223
dbps_client_lib
224224
dbps_common_lib
225+
dbps_server_lib
225226
)
226227
target_include_directories(dbpa_remote_testapp PRIVATE
227228
${CMAKE_BINARY_DIR}/_deps/cxxopts-src/include
229+
src/server
230+
${CMAKE_BINARY_DIR}/_deps/snappy-src
228231
)
229232

230233
# =============================================================================

src/scripts/dbpa_remote_testapp.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "../common/dbpa_remote.h"
2929
#include "../client/httplib_client.h"
3030
#include "../common/enums.h"
31+
#include "../server/compression_utils.h"
3132
#include "tcb/span.hpp"
3233

3334
using namespace dbps::external;
@@ -143,7 +144,7 @@ class DBPARemoteTestApp {
143144
"demo_fixed_len_key_001", // column_key_id
144145
Type::FIXED_LEN_BYTE_ARRAY, // datatype
145146
8, // datatype_length (8 bytes per element)
146-
CompressionCodec::UNCOMPRESSED, // compression_type
147+
CompressionCodec::SNAPPY, // compression_type (input will be Snappy-compressed)
147148
VALID_ENCRYPTION_METADATA // column_encryption_metadata
148149
);
149150

@@ -464,11 +465,16 @@ class DBPARemoteTestApp {
464465
}
465466

466467
std::cout << "Test data: 3 fixed-length strings (8 bytes each)" << std::endl;
467-
std::cout << "Total size: " << fixed_length_data.size() << " bytes" << std::endl;
468+
std::cout << "Original size: " << fixed_length_data.size() << " bytes" << std::endl;
468469

470+
// Compress the test data using Snappy before sending to server
471+
std::vector<uint8_t> fixed_length_data_compressed = Compress(fixed_length_data, CompressionCodec::SNAPPY);
472+
std::cout << "Compressed size: " << fixed_length_data_compressed.size() << " bytes" << std::endl;
473+
469474
// Test encryption with FIXED_LEN_BYTE_ARRAY and datatype_length
475+
// The server will decompress the fixed_length_data_compressed, encrypt it, and compress the encrypted result
470476
std::map<std::string, std::string> fixed_len_encoding_attributes = {{"page_encoding", "PLAIN"}, {"page_type", "DICTIONARY_PAGE"}};
471-
auto encrypt_result = fixed_len_agent_->Encrypt(span<const uint8_t>(fixed_length_data), fixed_len_encoding_attributes);
477+
auto encrypt_result = fixed_len_agent_->Encrypt(span<const uint8_t>(fixed_length_data_compressed), fixed_len_encoding_attributes);
472478

473479
if (!encrypt_result || !encrypt_result->success()) {
474480
std::cout << "ERROR: FIXED_LEN_BYTE_ARRAY encryption failed" << std::endl;
@@ -493,13 +499,22 @@ class DBPARemoteTestApp {
493499

494500
std::cout << "OK: FIXED_LEN_BYTE_ARRAY decrypted successfully" << std::endl;
495501

502+
// The server returns compressed plaintext (same compression as input)
503+
// Decompress it before comparing with original data
504+
auto decrypted_compressed_span = decrypt_result->plaintext();
505+
std::vector<uint8_t> decrypted_compressed(decrypted_compressed_span.begin(), decrypted_compressed_span.end());
506+
std::vector<uint8_t> decrypted_data = Decompress(decrypted_compressed, CompressionCodec::SNAPPY);
507+
std::cout << "Decrypted compressed size: " << decrypted_compressed.size() << " bytes" << std::endl;
508+
std::cout << "Decrypted uncompressed size: " << decrypted_data.size() << " bytes" << std::endl;
509+
496510
// Verify data integrity
497-
auto decrypted_data = decrypt_result->plaintext();
498511
if (decrypted_data.size() == fixed_length_data.size() &&
499-
std::equal(decrypted_data.begin(), decrypted_data.end(), fixed_length_data.begin())) {
512+
std::equal(decrypted_data.begin(), decrypted_data.end(), fixed_length_data.begin(), fixed_length_data.end())) {
500513
std::cout << "OK: FIXED_LEN_BYTE_ARRAY data integrity verified" << std::endl;
501514
} else {
502515
std::cout << "ERROR: FIXED_LEN_BYTE_ARRAY data integrity check failed" << std::endl;
516+
std::cout << " Expected size: " << fixed_length_data.size() << " bytes" << std::endl;
517+
std::cout << " Got size: " << decrypted_data.size() << " bytes" << std::endl;
503518
return false;
504519
}
505520

0 commit comments

Comments
 (0)