-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON interface for RPC Client [Issue #14] #109
Open
attaluris
wants to merge
6
commits into
ucbrise:single-machine
Choose a base branch
from
attaluris:json-parser
base: single-machine
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6343d2
JSON interface for RPC client
attaluris 6e0c2a0
fixed AppendAndGetJSONRecordTest1
attaluris 0cce8a8
implemented json_string_cursor and corresponding multilog filters
attaluris af5bdf6
AppendAndGetJSONRecordTest1 // used printed string as input
attaluris 1e9838c
json client_read and write_ops_test // used printed string as input
attaluris babd20f
JSON parser // reduced workload for json_cursor + tested spacing for …
attaluris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
#ifndef CONFLUO_TEST_ATOMIC_MULTILOG_TEST_H_ | ||
#define CONFLUO_TEST_ATOMIC_MULTILOG_TEST_H_ | ||
|
||
#include <boost/property_tree/ptree.hpp> | ||
#include <boost/property_tree/json_parser.hpp> | ||
|
||
#include "atomic_multilog.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
@@ -76,6 +79,30 @@ class AtomicMultilogTest : public testing::Test { | |
return reinterpret_cast<void *>(&r); | ||
} | ||
|
||
static std::string make_json_record(int64_t ts, bool a, int8_t b, int16_t c, int32_t d, int64_t e, float f, double g, const std::string &h) { | ||
namespace pt = boost::property_tree; | ||
pt::ptree root; | ||
|
||
root.put("TIMESTAMP", ts); | ||
root.put("A", a); | ||
root.put("B", b); | ||
root.put("C", c); | ||
root.put("D", d); | ||
root.put("E", e); | ||
std::stringstream f_ss; | ||
f_ss << std::fixed << std::setprecision(6) << f; | ||
root.put("F", f_ss.str()); | ||
std::stringstream g_ss; | ||
g_ss << std::fixed << std::setprecision(6) << g; | ||
root.put("G", g_ss.str()); | ||
root.put("H", h); | ||
|
||
std::stringstream ss; | ||
pt::write_json(ss, root); | ||
std::string ret = ss.str(); | ||
return ret; | ||
} | ||
|
||
static std::vector<column_t> schema() { | ||
schema_builder builder; | ||
builder.add_column(primitive_types::BOOL_TYPE(), "a"); | ||
|
@@ -158,14 +185,16 @@ TEST_F(AtomicMultilogTest, AppendAndGetDurableRelaxedTest) { | |
TEST_F(AtomicMultilogTest, AppendAndGetJSONRecordTest1) { | ||
atomic_multilog mlog("my_table", s, "/tmp", storage::IN_MEMORY, archival_mode::OFF, MGMT_POOL); | ||
|
||
std::string rec1 = "{'a':'false', 'b':'0', 'c':'0', 'd':'0', 'e':'0', 'f':'0.000000', 'g':'0.010000', 'h':'abc'}"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also test if this syntax works -- this would be the main use-case, I don't expect users to convert it to JSON and then back to string as the test now does. |
||
std::string rec2 = "{'a':'true', 'b':'1', 'c':'10', 'd':'2', 'e':'10', 'f':'0.100000', 'g':'0.020000', 'h':'defg'}"; | ||
std::string rec3 = "{'a':'false', 'b':'2', 'c':'20', 'd':'4', 'e':'100', 'f':'0.200000', 'g':'0.030000', 'h':'hijkl'}"; | ||
std::string rec4 = "{'a':'true', 'b':'3', 'c':'30', 'd':'6', 'e':'1000', 'f':'0.300000', 'g':'0.040000', 'h':'mnopqr'}"; | ||
std::string rec5 = "{'a':'false', 'b':'4', 'c':'40', 'd':'8', 'e':'10000', 'f':'0.400000', 'g':'0.050000', 'h':'stuvwx'}"; | ||
std::string rec6 = "{'a':'true', 'b':'5', 'c':'50', 'd':'10', 'e':'100000', 'f':'0.500000', 'g':'0.060000', 'h':'yyy'}"; | ||
std::string rec7 = "{'a':'false', 'b':'6', 'c':'60', 'd':'12', 'e':'1000000', 'f':'0.600000', 'g':'0.070000', 'h':'zzz'}"; | ||
std::string rec8 = "{'a':'true', 'b':'7', 'c':'70', 'd':'14', 'e':'10000000', 'f':'0.700000', 'g':'0.080000', 'h':'zzz'}"; | ||
int64_t ts = utils::time_utils::cur_ns(); | ||
|
||
std::string rec1 = make_json_record(ts, false, 0, 0, 0, 0, 0.000000, 0.010000, "abc"); | ||
std::string rec2 = make_json_record(ts, true, 1, 10, 2, 10, 0.100000, 0.020000, "defg"); | ||
std::string rec3 = make_json_record(ts, false, 2, 20, 4, 100, 0.200000, 0.030000, "hijkl"); | ||
std::string rec4 = make_json_record(ts, true, 3, 30, 6, 1000, 0.300000, 0.040000, "mnopqr"); | ||
std::string rec5 = make_json_record(ts, false, 4, 40, 8, 10000, 0.400000, 0.050000, "stuvwx"); | ||
std::string rec6 = make_json_record(ts, true, 5, 50, 10, 100000, 0.500000, 0.060000, "yyy"); | ||
std::string rec7 = make_json_record(ts, false, 6, 60, 12, 1000000, 0.600000, 0.070000, "zzz"); | ||
std::string rec8 = make_json_record(ts, true, 7, 70, 14, 10000000, 0.700000, 0.080000, "zzz"); | ||
|
||
ASSERT_EQ(mlog.record_size() * 0, mlog.append_json(rec1)); | ||
ASSERT_EQ(mlog.record_size() * 1, mlog.append_json(rec2)); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe try printing this out and use the printed string as your test input? Tests are also useful as sample usage for users.