Skip to content

Commit

Permalink
Support json result. (#57)
Browse files Browse the repository at this point in the history
* Support json result.

* Fix.

* Fix.
  • Loading branch information
Shylock-Hg authored Nov 9, 2021
1 parent 84e2e4c commit cc9788c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/client/tests/ConnectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This source code is licensed under Apache 2.0 License.
*/

#include <folly/json.h>
#include <folly/synchronization/Baton.h>
#include <glog/logging.h>
#include <gtest/gtest.h>
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions src/client/tests/SessionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This source code is licensed under Apache 2.0 License.
*/

#include <folly/json.h>
#include <folly/synchronization/Baton.h>
#include <glog/logging.h>
#include <gtest/gtest.h>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cc9788c

Please sign in to comment.