-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix csv writer with custom frontend options (#610)
- Loading branch information
Showing
4 changed files
with
64 additions
and
6 deletions.
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
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,54 @@ | ||
#include "doctest/doctest.h" | ||
|
||
#include "misc/TestUtilities.h" | ||
#include "quill/Backend.h" | ||
#include "quill/CsvWriter.h" | ||
#include "quill/core/FrontendOptions.h" | ||
|
||
using namespace quill; | ||
|
||
struct OrderCsvSchema | ||
{ | ||
static constexpr char const* header = "order_id,symbol,quantity,price,side"; | ||
static constexpr char const* format = "{},{},{},{:.2f},{}"; | ||
}; | ||
|
||
// Define custom Frontend Options | ||
struct CustomFrontendOptions | ||
{ | ||
static constexpr quill::QueueType queue_type = quill::QueueType::BoundedBlocking; | ||
static constexpr uint32_t initial_queue_capacity = 131'072; | ||
static constexpr uint32_t blocking_queue_retry_interval_ns = 800; | ||
static constexpr bool huge_pages_enabled = false; | ||
}; | ||
|
||
/***/ | ||
TEST_CASE("csv_writing_custom_frontend") | ||
{ | ||
static constexpr char const* filename = "orders_custom_frontend.csv"; | ||
|
||
// Start the backend thread | ||
quill::BackendOptions backend_options; | ||
quill::Backend::start(backend_options); | ||
|
||
{ | ||
quill::CsvWriter<OrderCsvSchema, CustomFrontendOptions> csv_writter{filename}; | ||
csv_writter.append_row(13212123, "AAPL", 100, 210.32321, "BUY"); | ||
csv_writter.append_row(132121123, "META", 300, 478.32321, "SELL"); | ||
csv_writter.append_row(14212123, "AAPL", 120, 210.42321, "BUY"); | ||
} | ||
|
||
// Wait until the backend thread stops for test stability | ||
Backend::stop(); | ||
|
||
// Read file and check | ||
std::vector<std::string> const file_contents = quill::testing::file_contents(filename); | ||
REQUIRE_EQ(file_contents.size(), 4); | ||
|
||
REQUIRE(quill::testing::file_contains(file_contents, "order_id,symbol,quantity,price,side")); | ||
REQUIRE(quill::testing::file_contains(file_contents, "13212123,AAPL,100,210.32,BUY")); | ||
REQUIRE(quill::testing::file_contains(file_contents, "132121123,META,300,478.32,SELL")); | ||
REQUIRE(quill::testing::file_contains(file_contents, "14212123,AAPL,120,210.42,BUY")); | ||
|
||
testing::remove_file(filename); | ||
} |