Skip to content

Commit

Permalink
chore: update jsoncons dependency (#1066)
Browse files Browse the repository at this point in the history
* chore: update jsoncons dependency

* fix: remove unused test case

Signed-off-by: iko1 <[email protected]>

* initial attempt to create custom memory allocator test

Signed-off-by: iko1 <[email protected]>

* chore: update jsoncons dependency

Signed-off-by: iko1 <[email protected]>

* chore: update jsoncons dependency

Signed-off-by: iko1 <[email protected]>

---------

Signed-off-by: iko1 <[email protected]>
  • Loading branch information
iko1 authored Jul 11, 2023
1 parent c27fa8d commit 37eedd4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ set(REFLEX "${THIRD_PARTY_LIB_DIR}/reflex/bin/reflex")

add_third_party(
jsoncons
URL https://github.com/danielaparker/jsoncons/archive/refs/tags/v0.168.7.tar.gz
CMAKE_PASS_FLAGS "-DJSONCONS_BUILD_TESTS=OFF"
URL https://github.com/danielaparker/jsoncons/archive/refs/tags/v0.171.0.tar.gz
CMAKE_PASS_FLAGS "-DJSONCONS_BUILD_TESTS=OFF -DJSONCONS_HAS_POLYMORPHIC_ALLOCATOR=ON"
LIB "none"
)

Expand Down
49 changes: 33 additions & 16 deletions src/core/json_test.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright 2022, DragonflyDB authors. All rights reserved.
// Copyright 2023, DragonflyDB authors. All rights reserved.
// See LICENSE for licensing terms.
//

#include <jsoncons/json.hpp>
#include <jsoncons_ext/jsonpath/jsonpath.hpp>
#include <memory_resource>

#include "base/gtest.h"
#include "base/logging.h"

namespace dfly {
using namespace std;
using namespace jsoncons;
using namespace jsoncons::literals;

Expand All @@ -20,7 +20,7 @@ class JsonTest : public ::testing::Test {
};

TEST_F(JsonTest, Basic) {
string data = R"(
std::string data = R"(
{
"application": "hiking",
"reputons": [
Expand Down Expand Up @@ -69,7 +69,7 @@ TEST_F(JsonTest, Errors) {
json_decoder<json> decoder;
basic_json_parser<char> parser(basic_json_decode_options<char>{}, cb);

string_view input{"\000bla"};
std::string_view input{"\000bla"};
parser.update(input.data(), input.size());
parser.parse_some(decoder);
parser.finish_parse(decoder);
Expand Down Expand Up @@ -101,19 +101,36 @@ TEST_F(JsonTest, Delete) {
EXPECT_EQ(R"({"c":{"a":1, "b":2}, "d":{"b":2, "c":3}, "e": [1,2]})"_json, j1);
}

TEST_F(JsonTest, DeleteExt) {
jsonpath::detail::static_resources<json, const json&> resources;
jsonpath::jsonpath_expression<json>::evaluator_t eval;
jsonpath::jsonpath_expression<json>::json_selector_t sel = eval.compile(resources, "$.d.*");
json j1 = R"({"c":{"a":1, "b":2}, "d":{"a":1, "b":2, "c":3}, "e": [1,2]})"_json;

jsoncons::jsonpath::detail::dynamic_resources<json, const json&> dyn_res;
TEST_F(JsonTest, JsonWithPolymorhicAllocator) {
char buffer[1024] = {};
std::pmr::monotonic_buffer_resource pool{std::data(buffer), std::size(buffer)};
std::pmr::polymorphic_allocator<char> alloc(&pool);

std::string input = R"(
{ "store": {
"book": [
{ "category": "Roman",
"author": "Felix Lobrecht",
"title": "Sonne und Beton",
"price": 12.99
},
{ "category": "Roman",
"author": "Thomas F. Schneider",
"title": "Im Westen nichts Neues",
"price": 10.00
}
]
}
}
)";

auto f = [](const jsonpath::json_location<char>& path, const json& val) {
LOG(INFO) << path.to_string();
};
auto j1 = pmr::json::parse(combine_allocators(alloc), input, json_options{});
EXPECT_EQ("Roman", j1["store"]["book"][0]["category"].as_string());
EXPECT_EQ("Felix Lobrecht", j1["store"]["book"][0]["author"].as_string());
EXPECT_EQ(12.99, j1["store"]["book"][0]["price"].as_double());

sel.evaluate(dyn_res, j1, dyn_res.root_path_node(), j1, f, jsonpath::result_options::path);
EXPECT_EQ("Roman", j1["store"]["book"][1]["category"].as_string());
EXPECT_EQ("Im Westen nichts Neues", j1["store"]["book"][1]["title"].as_string());
EXPECT_EQ(10.00, j1["store"]["book"][1]["price"].as_double());
}

} // namespace dfly
6 changes: 3 additions & 3 deletions src/server/cluster/cluster_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ optional<vector<ClusterConfig::SlotRange>> GetClusterSlotRanges(const JsonType&

vector<ClusterConfig::SlotRange> ranges;

for (const auto& range : slots.array_value()) {
for (const auto& range : slots.array_range()) {
if (!range.is_object()) {
LOG(WARNING) << kInvalidConfigPrefix << "slot_ranges element is not an object " << range;
return nullopt;
Expand Down Expand Up @@ -212,7 +212,7 @@ optional<ClusterConfig::ClusterShards> BuildClusterConfigFromJson(const JsonType
return nullopt;
}

for (const auto& element : json.array_value()) {
for (const auto& element : json.array_range()) {
ClusterConfig::ClusterShard shard;

if (!element.is_object()) {
Expand All @@ -238,7 +238,7 @@ optional<ClusterConfig::ClusterShards> BuildClusterConfigFromJson(const JsonType
return nullopt;
}

for (const auto& replica : replicas.array_value()) {
for (const auto& replica : replicas.array_range()) {
auto node = ParseClusterNode(replica);
if (!node.has_value()) {
return nullopt;
Expand Down
4 changes: 2 additions & 2 deletions src/server/json_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ OpResult<vector<OptSizeT>> OpObjLen(const OpArgs& op_args, string_view key,
vector<OptSizeT> vec;
auto cb = [&vec](const string_view& path, const JsonType& val) {
if (val.is_object()) {
vec.emplace_back(val.object_value().size());
vec.emplace_back(val.size());
} else {
vec.emplace_back(nullopt);
}
Expand All @@ -483,7 +483,7 @@ OpResult<vector<OptSizeT>> OpArrLen(const OpArgs& op_args, string_view key,
vector<OptSizeT> vec;
auto cb = [&vec](const string_view& path, const JsonType& val) {
if (val.is_array()) {
vec.emplace_back(val.array_value().size());
vec.emplace_back(val.size());
} else {
vec.emplace_back(nullopt);
}
Expand Down

0 comments on commit 37eedd4

Please sign in to comment.