Skip to content

Commit

Permalink
PathVisitor: add hybrid test for access/set/get for thrift container …
Browse files Browse the repository at this point in the history
…key under hybrid node

Summary:
# Overview
Using new defined test struct, adding test case for accessing with path visitor with the case of thrift path terminating at hybrid node
Of the overall test cases listed below, this covers the combo of 2c x 3c,3d,3e
D66525279 Update test struct definitions for comprehensive coverage of hybrid node access patterns for all visitors:
a. Thrift path terminating at HybridNode (annotated member hybridMapOfI32ToStruct)
b. Thrift path terminating at Thrift container (list, map, set, struct field in ChildStruct) under HybridNode
c. Thrift path terminating at leaf primitive under HybridNode (primitive leaves under ChildStruct: leafEnum, optionalI32, childMap/<key>, structMap/<key>/<field>, listOfStruct<key>/<field>)
d. [Existing UTs already cover] paths that terminate in COW leaf, COW nodes of various TCs
Path Visitor UTs to cover following operations on access patterns in #2 above:
a. modifyPath
b. removePath
c. Set
d. Get
e. Access (folly::dynamic)
ref: https://fburl.com/gdoc/46krq4xp

Differential Revision: D67049121

fbshipit-source-id: 3fa5d99845426f689853f5f915e55bac20b2bb9c
  • Loading branch information
Wei-Cheng Lin authored and facebook-github-bot committed Dec 12, 2024
1 parent 3d0eccc commit 6bcd941
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions fboss/thrift_cow/visitors/tests/PathVisitorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,69 @@ TYPED_TEST(PathVisitorTests, AccessAtHybridThriftContainerTest) {
EXPECT_EQ(getOp.val, newVal);
}

TYPED_TEST(PathVisitorTests, AccessAtHybridThriftContainerKeyTest) {
RootTestStruct root;
ParentTestStruct parent;
auto testStruct = createSimpleTestStruct();
parent.mapOfI32ToMapOfStruct() = {{3, {{"4", std::move(testStruct)}}}};
root.mapOfI32ToMapOfStruct() = {{1, {{"2", std::move(parent)}}}};

auto nodeA = this->initNode(root);
folly::dynamic dyn;
auto processPath = pvlambda([&dyn](auto& node, auto begin, auto end) {
EXPECT_EQ(begin, end);
if constexpr (std::is_base_of_v<
Serializable,
std::remove_cvref_t<decltype(node)>>) {
dyn = node.toFollyDynamic();
} else {
facebook::thrift::to_dynamic(
dyn, node, facebook::thrift::dynamic_format::JSON_1);
}
});

// Thrift path at thrift container key under HybridNode - Access
std::vector<std::string> path{
"mapOfI32ToMapOfStruct",
"1",
"2",
"mapOfI32ToMapOfStruct",
"3",
"4",
"hybridMapOfI32ToStruct",
"20",
"structMap",
"30"};
auto result = RootPathVisitor::visit(
*nodeA, path.begin(), path.end(), PathVisitMode::LEAF, processPath);
EXPECT_EQ(result, ThriftTraverseResult::OK);
cfg::L4PortRange got = facebook::thrift::from_dynamic<cfg::L4PortRange>(
dyn, facebook::thrift::dynamic_format::JSON_1);
EXPECT_EQ(*got.min(), 100);
EXPECT_EQ(*got.max(), 200);

// Thrift path at thrift container key under HybridNode - Set
using TC = apache::thrift::type_class::structure;

cfg::L4PortRange newRange;
newRange.min() = 3000;
newRange.max() = 4000;
folly::fbstring newVal =
serialize<TC>(fsdb::OperProtocol::SIMPLE_JSON, newRange);
SetEncodedPathVisitorOperator setOp(fsdb::OperProtocol::SIMPLE_JSON, newVal);

result = RootPathVisitor::visit(
*nodeA, path.begin(), path.end(), PathVisitMode::LEAF, setOp);
EXPECT_EQ(result, ThriftTraverseResult::OK);

// Thrift path at thrift container key under HybridNode - Get
GetEncodedPathVisitorOperator getOp(fsdb::OperProtocol::SIMPLE_JSON);
result = RootPathVisitor::visit(
*nodeA, path.begin(), path.end(), PathVisitMode::LEAF, getOp);
EXPECT_EQ(result, ThriftTraverseResult::OK);
EXPECT_EQ(getOp.val, newVal);
}

TYPED_TEST(PathVisitorTests, AccessFieldInContainer) {
auto structA = createSimpleTestStruct();
auto nodeA = std::make_shared<ThriftStructNode<
Expand Down

0 comments on commit 6bcd941

Please sign in to comment.