Skip to content

Commit 69fb168

Browse files
authored
feat(clp-s): Add end to end search tests for clp-s. (#668)
1 parent 121b717 commit 69fb168

File tree

7 files changed

+359
-42
lines changed

7 files changed

+359
-42
lines changed

components/core/CMakeLists.txt

+54-2
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,30 @@ set(SOURCE_FILES_clp_s_unitTest
299299
src/clp_s/SchemaTree.hpp
300300
src/clp_s/SchemaWriter.cpp
301301
src/clp_s/SchemaWriter.hpp
302+
src/clp_s/search/AddTimestampConditions.cpp
303+
src/clp_s/search/AddTimestampConditions.hpp
302304
src/clp_s/search/AndExpr.cpp
303305
src/clp_s/search/AndExpr.hpp
304306
src/clp_s/search/BooleanLiteral.cpp
305307
src/clp_s/search/BooleanLiteral.hpp
308+
src/clp_s/search/clp_search/EncodedVariableInterpreter.cpp
309+
src/clp_s/search/clp_search/EncodedVariableInterpreter.hpp
310+
src/clp_s/search/clp_search/Grep.cpp
311+
src/clp_s/search/clp_search/Grep.hpp
306312
src/clp_s/search/clp_search/Query.cpp
307313
src/clp_s/search/clp_search/Query.hpp
308314
src/clp_s/search/ColumnDescriptor.cpp
309315
src/clp_s/search/ColumnDescriptor.hpp
316+
src/clp_s/search/ConstantProp.cpp
317+
src/clp_s/search/ConstantProp.hpp
318+
src/clp_s/search/ConvertToExists.cpp
319+
src/clp_s/search/ConvertToExists.hpp
310320
src/clp_s/search/DateLiteral.cpp
311321
src/clp_s/search/DateLiteral.hpp
312322
src/clp_s/search/EmptyExpr.cpp
313323
src/clp_s/search/EmptyExpr.hpp
324+
src/clp_s/search/EvaluateTimestampIndex.cpp
325+
src/clp_s/search/EvaluateTimestampIndex.hpp
314326
src/clp_s/search/Expression.cpp
315327
src/clp_s/search/Expression.hpp
316328
src/clp_s/search/FilterExpr.cpp
@@ -319,12 +331,22 @@ set(SOURCE_FILES_clp_s_unitTest
319331
src/clp_s/search/Integral.cpp
320332
src/clp_s/search/Integral.hpp
321333
src/clp_s/search/Literal.hpp
334+
src/clp_s/search/NarrowTypes.cpp
335+
src/clp_s/search/NarrowTypes.hpp
322336
src/clp_s/search/NullLiteral.cpp
323337
src/clp_s/search/NullLiteral.hpp
324338
src/clp_s/search/OrExpr.cpp
325339
src/clp_s/search/OrExpr.hpp
326340
src/clp_s/search/OrOfAndForm.cpp
327341
src/clp_s/search/OrOfAndForm.hpp
342+
src/clp_s/search/Output.cpp
343+
src/clp_s/search/Output.hpp
344+
src/clp_s/search/OutputHandler.cpp
345+
src/clp_s/search/OutputHandler.hpp
346+
src/clp_s/search/Projection.cpp
347+
src/clp_s/search/Projection.hpp
348+
src/clp_s/search/SchemaMatch.cpp
349+
src/clp_s/search/SchemaMatch.hpp
328350
src/clp_s/search/SearchUtils.cpp
329351
src/clp_s/search/SearchUtils.hpp
330352
src/clp_s/search/StringLiteral.cpp
@@ -349,7 +371,29 @@ set(SOURCE_FILES_clp_s_unitTest
349371
src/clp_s/ZstdCompressor.hpp
350372
src/clp_s/ZstdDecompressor.cpp
351373
src/clp_s/ZstdDecompressor.hpp
352-
)
374+
)
375+
376+
set(SOURCE_FILES_reducer_unitTest
377+
src/reducer/BufferedSocketWriter.cpp
378+
src/reducer/BufferedSocketWriter.hpp
379+
src/reducer/ConstRecordIterator.hpp
380+
src/reducer/CountOperator.cpp
381+
src/reducer/CountOperator.hpp
382+
src/reducer/DeserializedRecordGroup.cpp
383+
src/reducer/DeserializedRecordGroup.hpp
384+
src/reducer/GroupTags.hpp
385+
src/reducer/network_utils.cpp
386+
src/reducer/network_utils.hpp
387+
src/reducer/Operator.cpp
388+
src/reducer/Operator.hpp
389+
src/reducer/Pipeline.cpp
390+
src/reducer/Pipeline.hpp
391+
src/reducer/Record.hpp
392+
src/reducer/RecordGroup.hpp
393+
src/reducer/RecordGroupIterator.hpp
394+
src/reducer/RecordTypedKeyIterator.hpp
395+
src/reducer/types.hpp
396+
)
353397

354398
set(SOURCE_FILES_unitTest
355399
src/clp/Array.hpp
@@ -491,6 +535,8 @@ set(SOURCE_FILES_unitTest
491535
src/clp/MySQLParamBindings.hpp
492536
src/clp/MySQLPreparedStatement.cpp
493537
src/clp/MySQLPreparedStatement.hpp
538+
src/clp/networking/socket_utils.cpp
539+
src/clp/networking/socket_utils.hpp
494540
src/clp/NetworkReader.cpp
495541
src/clp/NetworkReader.hpp
496542
src/clp/PageAllocatedVector.hpp
@@ -578,10 +624,12 @@ set(SOURCE_FILES_unitTest
578624
submodules/sqlite3/sqlite3.h
579625
submodules/sqlite3/sqlite3ext.h
580626
tests/LogSuppressor.hpp
627+
tests/TestOutputCleaner.hpp
581628
tests/test-Array.cpp
582629
tests/test-BoundedReader.cpp
583630
tests/test-BufferedFileReader.cpp
584631
tests/test-clp_s-end_to_end.cpp
632+
tests/test-clp_s-search.cpp
585633
tests/test-EncodedVariableInterpreter.cpp
586634
tests/test-encoding_methods.cpp
587635
tests/test-error_handling.cpp
@@ -612,7 +660,11 @@ set(SOURCE_FILES_unitTest
612660
tests/test-utf8_utils.cpp
613661
tests/test-Utils.cpp
614662
)
615-
add_executable(unitTest ${SOURCE_FILES_unitTest} ${SOURCE_FILES_clp_s_unitTest})
663+
add_executable(unitTest
664+
${SOURCE_FILES_unitTest}
665+
${SOURCE_FILES_clp_s_unitTest}
666+
${SOURCE_FILES_reducer_unitTest}
667+
)
616668
target_include_directories(unitTest
617669
PRIVATE
618670
${CMAKE_SOURCE_DIR}/submodules

components/core/src/clp_s/search/OutputHandler.hpp

+49
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <queue>
1010
#include <string>
1111
#include <string_view>
12+
#include <vector>
1213

1314
#include <mongocxx/client.hpp>
1415
#include <mongocxx/collection.hpp>
@@ -294,6 +295,54 @@ class CountByTimeOutputHandler : public OutputHandler {
294295
std::map<int64_t, int64_t> m_bucket_counts;
295296
int64_t m_count_by_time_bucket_size;
296297
};
298+
299+
/**
300+
* Output handler that records all results in a provided vector.
301+
*/
302+
class VectorOutputHandler : public OutputHandler {
303+
public:
304+
// Types
305+
struct QueryResult {
306+
// Constructors
307+
QueryResult(
308+
std::string_view message,
309+
epochtime_t timestamp,
310+
std::string_view archive_id,
311+
int64_t log_event_idx
312+
)
313+
: message{message},
314+
timestamp{timestamp},
315+
archive_id{archive_id},
316+
log_event_idx{log_event_idx} {}
317+
318+
std::string message;
319+
epochtime_t timestamp;
320+
std::string archive_id;
321+
int64_t log_event_idx;
322+
};
323+
324+
// Constructors
325+
VectorOutputHandler(std::vector<QueryResult>& output)
326+
: OutputHandler{true, true},
327+
m_output(output) {}
328+
329+
// Methods inherited from OutputHandler
330+
void write(
331+
std::string_view message,
332+
epochtime_t timestamp,
333+
std::string_view archive_id,
334+
int64_t log_event_idx
335+
) override {
336+
m_output.emplace_back(message, timestamp, archive_id, log_event_idx);
337+
}
338+
339+
void write(std::string_view message) override {
340+
m_output.emplace_back(message, epochtime_t{}, std::string_view{}, int64_t{});
341+
}
342+
343+
private:
344+
std::vector<QueryResult>& m_output;
345+
};
297346
} // namespace clp_s::search
298347

299348
#endif // CLP_S_SEARCH_OUTPUTHANDLER_HPP

components/core/tests/LogSuppressor.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ class LogSuppressor {
1313
spdlog::default_logger()->set_level(spdlog::level::off);
1414
}
1515

16-
LogSuppressor(LogSuppressor const& other) = default;
17-
LogSuppressor(LogSuppressor&& other) noexcept = default;
18-
19-
LogSuppressor& operator=(LogSuppressor const& other) = default;
20-
LogSuppressor& operator=(LogSuppressor&& other) noexcept = default;
21-
2216
~LogSuppressor() { spdlog::default_logger()->set_level(m_previous_logging_level); }
2317

18+
// Delete copy & move constructors and assignment operators
19+
LogSuppressor(LogSuppressor const& other) = delete;
20+
LogSuppressor(LogSuppressor&& other) = delete;
21+
auto operator=(LogSuppressor const& other) -> LogSuppressor& = delete;
22+
auto operator=(LogSuppressor&& other) -> LogSuppressor& = delete;
23+
2424
private:
2525
spdlog::level::level_enum m_previous_logging_level;
2626
};
2727

2828
#endif // TESTS_LOGSUPPRESSOR_HPP
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef TESTS_TESTOUTPUTCLEANER_HPP
2+
#define TESTS_TESTOUTPUTCLEANER_HPP
3+
4+
#include <filesystem>
5+
#include <string>
6+
#include <vector>
7+
8+
/**
9+
* A class that deletes the directories and files created by test cases, both before and after each
10+
* test case where the class is instantiated.
11+
*/
12+
class TestOutputCleaner {
13+
public:
14+
explicit TestOutputCleaner(std::vector<std::string> const& paths) : m_paths(paths) {
15+
delete_paths();
16+
}
17+
18+
~TestOutputCleaner() { delete_paths(); }
19+
20+
// Delete copy & move constructors and assignment operators
21+
TestOutputCleaner(TestOutputCleaner const&) = delete;
22+
TestOutputCleaner(TestOutputCleaner&&) = delete;
23+
auto operator=(TestOutputCleaner const&) -> TestOutputCleaner& = delete;
24+
auto operator=(TestOutputCleaner&&) -> TestOutputCleaner& = delete;
25+
26+
private:
27+
void delete_paths() const {
28+
for (auto const& path : m_paths) {
29+
std::filesystem::remove_all(path);
30+
}
31+
}
32+
33+
std::vector<std::string> m_paths;
34+
};
35+
36+
#endif // TESTS_TESTOUTPUTCLEANER_HPP

components/core/tests/test-clp_s-end_to_end.cpp

+11-34
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#include <filesystem>
55
#include <string>
66
#include <string_view>
7-
#include <vector>
87

98
#include <Catch2/single_include/catch2/catch.hpp>
109
#include <fmt/format.h>
1110

1211
#include "../src/clp_s/InputConfig.hpp"
1312
#include "../src/clp_s/JsonConstructor.hpp"
1413
#include "../src/clp_s/JsonParser.hpp"
14+
#include "TestOutputCleaner.hpp"
1515

1616
constexpr std::string_view cTestEndToEndArchiveDirectory{"test-end-to-end-archive"};
1717
constexpr std::string_view cTestEndToEndOutputDirectory{"test-end-to-end-out"};
@@ -20,33 +20,9 @@ constexpr std::string_view cTestEndToEndInputFileDirectory{"test_log_files"};
2020
constexpr std::string_view cTestEndToEndInputFile{"test_no_floats_sorted.jsonl"};
2121

2222
namespace {
23-
/**
24-
* A class that deletes the directories and files created by test cases, both before and after each
25-
* test case where the class is instantiated.
26-
*/
27-
class TestOutputCleaner {
28-
public:
29-
TestOutputCleaner() { delete_files(); }
30-
31-
~TestOutputCleaner() { delete_files(); }
32-
33-
// Delete copy & move constructors and assignment operators
34-
TestOutputCleaner(TestOutputCleaner const&) = delete;
35-
TestOutputCleaner(TestOutputCleaner&&) = delete;
36-
auto operator=(TestOutputCleaner const&) -> TestOutputCleaner& = delete;
37-
auto operator=(TestOutputCleaner&&) -> TestOutputCleaner& = delete;
38-
39-
private:
40-
static void delete_files() {
41-
std::filesystem::remove_all(cTestEndToEndArchiveDirectory);
42-
std::filesystem::remove_all(cTestEndToEndOutputDirectory);
43-
std::filesystem::remove(cTestEndToEndOutputSortedJson);
44-
}
45-
};
46-
4723
auto get_test_input_path_relative_to_tests_dir() -> std::filesystem::path;
4824
auto get_test_input_local_path() -> std::string;
49-
void compress(bool structurize_arrays);
25+
void compress(bool structurize_arrays, bool single_file_archive);
5026
auto extract() -> std::filesystem::path;
5127
void compare(std::filesystem::path const& extracted_json_path);
5228

@@ -60,7 +36,7 @@ auto get_test_input_local_path() -> std::string {
6036
return (tests_dir / get_test_input_path_relative_to_tests_dir()).string();
6137
}
6238

63-
void compress(bool structurize_arrays) {
39+
void compress(bool structurize_arrays, bool single_file_archive) {
6440
constexpr auto cDefaultTargetEncodedSize = 8ULL * 1024 * 1024 * 1024; // 8 GiB
6541
constexpr auto cDefaultMaxDocumentSize = 512ULL * 1024 * 1024; // 512 MiB
6642
constexpr auto cDefaultMinTableSize = 1ULL * 1024 * 1024; // 1 MiB
@@ -82,6 +58,7 @@ void compress(bool structurize_arrays) {
8258
parser_option.compression_level = cDefaultCompressionLevel;
8359
parser_option.print_archive_stats = cDefaultPrintArchiveStats;
8460
parser_option.structurize_arrays = structurize_arrays;
61+
parser_option.single_file_archive = single_file_archive;
8562

8663
clp_s::JsonParser parser{parser_option};
8764
REQUIRE(parser.parse());
@@ -102,11 +79,6 @@ auto extract() -> std::filesystem::path {
10279
constructor_option.ordered = cDefaultOrdered;
10380
constructor_option.target_ordered_chunk_size = cDefaultTargetOrderedChunkSize;
10481
for (auto const& entry : std::filesystem::directory_iterator(cTestEndToEndArchiveDirectory)) {
105-
if (false == entry.is_directory()) {
106-
// Skip non-directories
107-
continue;
108-
}
109-
11082
constructor_option.archive_path = clp_s::Path{
11183
.source{clp_s::InputSource::Filesystem},
11284
.path{entry.path().string()}
@@ -153,10 +125,15 @@ void compare(std::filesystem::path const& extracted_json_path) {
153125

154126
TEST_CASE("clp-s-compress-extract-no-floats", "[clp-s][end-to-end]") {
155127
auto structurize_arrays = GENERATE(true, false);
128+
auto single_file_archive = GENERATE(true, false);
156129

157-
TestOutputCleaner const test_cleanup;
130+
TestOutputCleaner const test_cleanup{
131+
{std::string{cTestEndToEndArchiveDirectory},
132+
std::string{cTestEndToEndOutputDirectory},
133+
std::string{cTestEndToEndOutputSortedJson}}
134+
};
158135

159-
compress(structurize_arrays);
136+
compress(structurize_arrays, single_file_archive);
160137

161138
auto extracted_json_path = extract();
162139

0 commit comments

Comments
 (0)