From cc9788c31fe632a9135688a88997a80f081882ab Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Tue, 9 Nov 2021 18:04:30 +0800 Subject: [PATCH] Support json result. (#57) * Support json result. * Fix. * Fix. --- src/client/tests/ConnectionTest.cpp | 21 +++++++++++++++++++++ src/client/tests/SessionTest.cpp | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/client/tests/ConnectionTest.cpp b/src/client/tests/ConnectionTest.cpp index fbeb12f2..7741739a 100644 --- a/src/client/tests/ConnectionTest.cpp +++ b/src/client/tests/ConnectionTest.cpp @@ -3,6 +3,7 @@ * This source code is licensed under Apache 2.0 License. */ +#include #include #include #include @@ -178,6 +179,26 @@ TEST_F(ConnectionTest, SSL) { EXPECT_TRUE(verifyResultWithoutOrder(*resp.data, expected)); } +TEST_F(ConnectionTest, JsonResult) { + nebula::Connection c; + + ASSERT_TRUE(c.open(kServerHost, 9669, 10)); + + // auth + auto authResp = c.authenticate("root", "nebula"); + ASSERT_EQ(authResp.errorCode, nebula::ErrorCode::SUCCEEDED); + + auto resp = c.executeJson(*authResp.sessionId, "YIELD 1"); + folly::parseJson(resp); + + folly::Baton<> b1; + c.asyncExecuteJson(*authResp.sessionId, "YIELD 1", [&b1](std::string &&asyncResp) { + folly::parseJson(asyncResp); + b1.post(); + }); + b1.wait(); +} + int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); nebula::init(&argc, &argv); diff --git a/src/client/tests/SessionTest.cpp b/src/client/tests/SessionTest.cpp index aa4b5eaf..f06fa7f0 100644 --- a/src/client/tests/SessionTest.cpp +++ b/src/client/tests/SessionTest.cpp @@ -3,6 +3,7 @@ * This source code is licensed under Apache 2.0 License. */ +#include #include #include #include @@ -190,6 +191,24 @@ TEST_F(SessionTest, SSL) { EXPECT_TRUE(verifyResultWithoutOrder(*result.data, expected)); } +TEST_F(SessionTest, JsonResult) { + nebula::ConnectionPool pool; + nebula::Config c{10, 0, 10, 0, "", false}; + pool.init({kServerHost ":9669"}, c); + auto session = pool.getSession("root", "nebula"); + ASSERT_TRUE(session.valid()); + + auto resp = session.executeJson("YIELD 1"); + folly::parseJson(resp); + + folly::Baton<> b; + session.asyncExecuteJson("YIELD 1", [&b](std::string&& asyncResp) { + folly::parseJson(asyncResp); + b.post(); + }); + b.wait(); +} + int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); nebula::init(&argc, &argv);