-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding end to end test case for clp-s
- Loading branch information
1 parent
d969aaf
commit 5382e80
Showing
4 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include <cstdlib> | ||
#include <filesystem> | ||
#include <string> | ||
#include <string_view> | ||
#include <vector> | ||
|
||
#include <Catch2/single_include/catch2/catch.hpp> | ||
#include <msgpack.hpp> | ||
|
||
#include "../src/clp/BufferReader.hpp" | ||
#include "../src/clp/ffi/ir_stream/decoding_methods.hpp" | ||
#include "../src/clp/ffi/ir_stream/Deserializer.hpp" | ||
#include "../src/clp/ffi/ir_stream/Serializer.hpp" | ||
#include "../src/clp/ffi/KeyValuePairLogEvent.hpp" | ||
#include "../src/clp/ir/types.hpp" | ||
#include "../src/clp/time_types.hpp" | ||
#include "../src/clp_s/JsonConstructor.hpp" | ||
#include "../src/clp_s/JsonParser.hpp" | ||
|
||
using clp::BufferReader; | ||
using clp::ffi::ir_stream::Deserializer; | ||
using clp::ffi::ir_stream::IRErrorCode; | ||
using clp::ffi::ir_stream::Serializer; | ||
using clp::ffi::KeyValuePairLogEvent; | ||
using clp::ir::eight_byte_encoded_variable_t; | ||
using clp::ir::four_byte_encoded_variable_t; | ||
using clp::size_checked_pointer_cast; | ||
using clp::UtcOffset; | ||
using std::string; | ||
using std::string_view; | ||
using std::vector; | ||
|
||
auto const cDefaultTargetEncodedSize = 8ULL * 1024 * 1024 * 1024; | ||
auto const cDefaultMaxDocumentSize = 512ULL * 1024 * 1024; | ||
auto const cDefaultMinTableSize = 1ULL * 1024 * 1024; | ||
auto const cDeaultCompressionLevel = 3; | ||
auto const cDefaultPrintArchiveStats = false; | ||
auto const cDefaultStructurizeArrays = false; | ||
|
||
namespace { | ||
auto get_test_input_path_relative_to_tests_dir() -> std::filesystem::path { | ||
return std::filesystem::path{"test_log_files"} / "test_no_floats_sorted.json"; | ||
} | ||
|
||
auto get_test_input_local_path() -> std::string { | ||
std::filesystem::path const current_file_path{__FILE__}; | ||
auto const tests_dir{current_file_path.parent_path()}; | ||
return (tests_dir / get_test_input_path_relative_to_tests_dir()).string(); | ||
} | ||
} // namespace | ||
|
||
// NOLINTNEXTLINE(readability-function-cognitive-complexity) | ||
TEMPLATE_TEST_CASE( | ||
"clp-s_compression_and_extraction_no_floats", | ||
"[clp-s][end-to-end]", | ||
four_byte_encoded_variable_t, | ||
eight_byte_encoded_variable_t | ||
) { | ||
std::filesystem::remove_all("test-end-to-end-archive"); | ||
std::filesystem::remove_all("test-end-to-end-out"); | ||
std::filesystem::remove("test-end-to-end_sorted.json"); | ||
std::filesystem::remove("diff_out.txt"); | ||
|
||
std::filesystem::create_directory("test-end-to-end-archive"); | ||
REQUIRE(std::filesystem::is_directory("test-end-to-end-archive")); | ||
|
||
clp_s::JsonParserOption parser_option{}; | ||
parser_option.file_paths.push_back(get_test_input_local_path()); | ||
parser_option.archives_dir = "test-end-to-end-archive"; | ||
parser_option.target_encoded_size = cDefaultTargetEncodedSize; | ||
parser_option.max_document_size = cDefaultMaxDocumentSize; | ||
parser_option.min_table_size = cDefaultMinTableSize; | ||
parser_option.compression_level = cDeaultCompressionLevel; | ||
parser_option.print_archive_stats = cDefaultPrintArchiveStats; | ||
parser_option.structurize_arrays = cDefaultStructurizeArrays; | ||
|
||
clp_s::JsonParser parser(parser_option); | ||
REQUIRE(parser.parse()); | ||
parser.store(); | ||
|
||
REQUIRE(false == std::filesystem::is_empty("test-end-to-end-archive")); | ||
|
||
std::filesystem::create_directory("test-end-to-end-out"); | ||
REQUIRE(std::filesystem::is_directory("test-end-to-end-out")); | ||
|
||
clp_s::JsonConstructorOption constructor_option{}; | ||
constructor_option.output_dir = "test-end-to-end-out"; | ||
constructor_option.ordered = false; | ||
constructor_option.archives_dir = parser_option.archives_dir; | ||
constructor_option.ordered_chunk_size = 0; | ||
for (auto const& entry : std::filesystem::directory_iterator(constructor_option.archives_dir)) { | ||
if (false == entry.is_directory()) { | ||
// Skip non-directories | ||
continue; | ||
} | ||
|
||
constructor_option.archive_id = entry.path().filename(); | ||
clp_s::JsonConstructor constructor(constructor_option); | ||
constructor.store(); | ||
} | ||
|
||
REQUIRE(std::filesystem::exists("test-end-to-end-out/original")); | ||
|
||
std::system("jq -S -c '.' test-end-to-end-out/original | sort > test-end-to-end_sorted.json"); | ||
|
||
REQUIRE(false == std::filesystem::is_empty("test-end-to-end_sorted.json")); | ||
|
||
std::string const command = "diff -u test-end-to-end_sorted.json " + get_test_input_local_path() | ||
+ " > diff_out.txt"; | ||
std::system(command.c_str()); | ||
REQUIRE(std::filesystem::is_empty("diff_out.txt")); | ||
} |
4 changes: 4 additions & 0 deletions
4
components/core/tests/test_log_files/test_no_floats_sorted.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"empty_object":{},"false":false,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"null":null,"string":"short_string","true":true} | ||
{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"false":false,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"nonempty_object":{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"empty_object":{},"false":false,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"null":null,"string":"short_string","true":true},"null":null,"string":"short_string","true":true} | ||
{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"false":false,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"nonempty_object":{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"false":false,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"non_empty_object2":{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"empty_object":{},"false":false,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"null":null,"string":"short_string","true":true},"null":null,"string":"short_string","true":true},"null":null,"string":"short_string","true":true} | ||
{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_object":{},"false":false,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"nonempty_array":[1,2,3,4,5],"null":null,"string":"short_string","true":true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"empty_object":{},"false":false,"float_neg":-1.01,"float_pos":1.01,"float_zero":0.0,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"null":null,"string":"short_string","true":true} | ||
{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"false":false,"float_neg":-1.01,"float_pos":1.01,"float_zero":0.0,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"nonempty_object":{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"empty_object":{},"false":false,"float_neg":-1.01,"float_pos":1.01,"float_zero":0.0,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"null":null,"string":"short_string","true":true},"null":null,"string":"short_string","true":true} | ||
{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"false":false,"float_neg":-1.01,"float_pos":1.01,"float_zero":0.0,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"nonempty_object":{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"false":false,"float_neg":-1.01,"float_pos":1.01,"float_zero":0.0,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"non_empty_object2":{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_array":[],"empty_object":{},"false":false,"float_neg":-1.01,"float_pos":1.01,"float_zero":0.0,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"null":null,"string":"short_string","true":true},"null":null,"string":"short_string","true":true},"null":null,"string":"short_string","true":true} | ||
{"clp_string":"uid=0, CPU usage:99.99%, \"user_name\"=YScope","empty_object":{},"false":false,"float_neg":-1.01,"float_pos":1.01,"float_zero":0.0,"int16_max":32767,"int16_min":-32768,"int32_max":2147483647,"int32_min":-2147483648,"int64_max":0,"int64_min":1,"int8_max":127,"int8_min":-128,"nonempty_array":[1,2,3,4,5],"null":null,"string":"short_string","true":true} |