Skip to content
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

Nebula cpp3 #80

Merged
merged 21 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 133 additions & 18 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
lint:
name: lint
if: ${{ contains(github.event.pull_request.labels.*.name, 'ready-for-testing') }}
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -33,13 +33,13 @@ jobs:
build:
name: build
needs: lint
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
os:
- centos7
- ubuntu1804
- ubuntu2004
compiler:
- gcc-9.2
- clang-9
Expand All @@ -61,19 +61,19 @@ jobs:
centos7)
# build with Release type
cmake \
-DCMAKE_CXX_COMPILER=$TOOLSET_CLANG_DIR/bin/g++ \
-DCMAKE_C_COMPILER=$TOOLSET_CLANG_DIR/bin/gcc \
-DCMAKE_CXX_COMPILER=$TOOLSET_GCC_DIR/bin/g++ \
-DCMAKE_C_COMPILER=$TOOLSET_GCC_DIR/bin/gcc \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_TESTING=on \
-DCMAKE_INSTALL_PREFIX=/usr/local/nebula \
-DDISABLE_CXX11_ABI=ON \
-B build
;;
ubuntu1804)
ubuntu2004)
# build with Debug type
cmake \
-DCMAKE_CXX_COMPILER=$TOOLSET_CLANG_DIR/bin/g++ \
-DCMAKE_C_COMPILER=$TOOLSET_CLANG_DIR/bin/gcc \
-DCMAKE_CXX_COMPILER=$TOOLSET_GCC_DIR/bin/g++ \
-DCMAKE_C_COMPILER=$TOOLSET_GCC_DIR/bin/gcc \
-DCMAKE_BUILD_TYPE=Debug \
-DENABLE_TESTING=on \
-DCMAKE_INSTALL_PREFIX=/usr/local/nebula \
Expand Down Expand Up @@ -109,24 +109,18 @@ jobs:
done
set -e
;;
ubuntu1804)
ubuntu2004)
set +e
for i in {0..10}; do
wget https://oss-cdn.nebula-graph.com.cn/package/nightly/$(./date.py --day_diff=$i)/nebula-graph-$(./date.py --day_diff=$i)-nightly.ubuntu1804.amd64.deb
dpkg -i nebula-graph-$(./date.py --day_diff=$i)-nightly.ubuntu1804.amd64.deb
wget https://oss-cdn.nebula-graph.com.cn/package/nightly/$(./date.py --day_diff=$i)/nebula-graph-$(./date.py --day_diff=$i)-nightly.ubuntu2004.amd64.deb
dpkg -i nebula-graph-$(./date.py --day_diff=$i)-nightly.ubuntu2004.amd64.deb
if [ $? -eq 0 ]; then
break;
fi
done
set -e
;;
esac
chmod u+w /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
echo '--cert_path=share/resources/test.ca.pem' | tee -a /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
echo '--key_path=share/resources/test.ca.key' | tee -a /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
echo '--password_path=share/resources/test.ca.password' | tee -a /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
echo '--enable_ssl=true' | tee -a /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
cp certs/* /usr/local/nebula/share/resources
/usr/local/nebula/scripts/nebula.service start all
/usr/local/nebula/scripts/nebula.service status all
echo '127.0.0.1 graphd' >> /etc/hosts
Expand All @@ -139,7 +133,9 @@ jobs:
ASAN_OPTIONS: fast_unwind_on_malloc=1
run: |
pushd build
ctest -j $(nproc) --timeout 10000 --output-on-failure
# register storage to meta
./bin/regist_host --host=127.0.0.1:9779
ctest -j $(nproc) -E '\w*_ssl_test' --timeout 10000 --output-on-failure
make install
popd
timeout-minutes: 10
Expand Down Expand Up @@ -175,3 +171,122 @@ jobs:
- name: Cleanup
if: ${{ always() }}
run: rm -rf build modules

build_ssl:
name: build ssl
needs: lint
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
os:
- centos7
- ubuntu2004
compiler:
- gcc-9.2
- clang-9
exclude:
- os: centos7
compiler: clang-9
container:
image: vesoft/nebula-dev:${{ matrix.os }}
volumes:
- /tmp/nebula-graph-client/${{ matrix.os }}-${{ matrix.compiler }}:/tmp/nebula-graph-client/nebula-graph/${{ matrix.os }}-${{ matrix.compiler }}
options: --mount type=tmpfs,destination=/tmp/ccache/nebula-graph,tmpfs-size=1073741824 --cap-add=SYS_PTRACE
steps:
- uses: actions/checkout@v2
- name: CMake
run: |
case ${{ matrix.compiler }} in
gcc-*)
case ${{ matrix.os }} in
centos7)
# build with Release type
cmake \
-DCMAKE_CXX_COMPILER=$TOOLSET_GCC_DIR/bin/g++ \
-DCMAKE_C_COMPILER=$TOOLSET_GCC_DIR/bin/gcc \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_TESTING=on \
-DCMAKE_INSTALL_PREFIX=/usr/local/nebula \
-DDISABLE_CXX11_ABI=ON \
-B build
;;
ubuntu2004)
# build with Debug type
cmake \
-DCMAKE_CXX_COMPILER=$TOOLSET_GCC_DIR/bin/g++ \
-DCMAKE_C_COMPILER=$TOOLSET_GCC_DIR/bin/gcc \
-DCMAKE_BUILD_TYPE=Debug \
-DENABLE_TESTING=on \
-DCMAKE_INSTALL_PREFIX=/usr/local/nebula \
-B build
;;
esac
;;
clang-*)
# build with Sanitizer
cmake \
-DCMAKE_CXX_COMPILER=$TOOLSET_CLANG_DIR/bin/clang++ \
-DCMAKE_C_COMPILER=$TOOLSET_CLANG_DIR/bin/clang \
-DCMAKE_BUILD_TYPE=Debug \
-DENABLE_ASAN=on \
-DENABLE_TESTING=on \
-DCMAKE_INSTALL_PREFIX=/usr/local/nebula \
-B build
;;
esac
- name: Make
run: cmake --build build/ -j $(nproc)
- name: Nebula Server
run: |
case ${{ matrix.os }} in
centos7)
set +e
for i in {0..10}; do
wget https://oss-cdn.nebula-graph.com.cn/package/nightly/$(./date.py --day_diff=$i)/nebula-graph-$(./date.py --day_diff=$i)-nightly.el7.x86_64.rpm
rpm -ivh nebula-graph-$(./date.py --day_diff=$i)-nightly.el7.x86_64.rpm
if [ $? -eq 0 ]; then
break;
fi
done
set -e
;;
ubuntu2004)
set +e
for i in {0..10}; do
wget https://oss-cdn.nebula-graph.com.cn/package/nightly/$(./date.py --day_diff=$i)/nebula-graph-$(./date.py --day_diff=$i)-nightly.ubuntu2004.amd64.deb
dpkg -i nebula-graph-$(./date.py --day_diff=$i)-nightly.ubuntu2004.amd64.deb
if [ $? -eq 0 ]; then
break;
fi
done
set -e
;;
esac
chmod u+w /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
echo '--cert_path=share/resources/test.derive.crt' | tee -a /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
echo '--key_path=share/resources/test.derive.key' | tee -a /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
echo '--ca_path=share/resources/test.ca.pem' | tee -a /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
echo '--enable_ssl=true' | tee -a /usr/local/nebula/etc/nebula-graphd.conf /usr/local/nebula/etc/nebula-storaged.conf /usr/local/nebula/etc/nebula-metad.conf
cp certs/* /usr/local/nebula/share/resources
/usr/local/nebula/scripts/nebula.service start all
/usr/local/nebula/scripts/nebula.service status all
echo '127.0.0.1 graphd' >> /etc/hosts
echo '127.0.0.1 graphd1' >> /etc/hosts
echo '127.0.0.1 graphd2' >> /etc/hosts
# The connection maybe unstable, so we wait a while
sleep 10
- name: CTest SSL
env:
ASAN_OPTIONS: fast_unwind_on_malloc=1
run: |
pushd build
# register storage to meta
./bin/regist_host --enable_ssl=true --host=127.0.0.1:9779
ctest -j $(nproc) -R '\w*_ssl_test' --timeout 10000 --output-on-failure
make install
popd
timeout-minutes: 10
- name: Cleanup
if: ${{ always() }}
run: rm -rf build modules
41 changes: 41 additions & 0 deletions src/client/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ nebula_add_test(
${NEBULA_THIRD_PARTY_LIBRARIES}
)

nebula_add_test(
NAME
connection_ssl_test
SOURCES
ConnectionSSLTest.cpp
OBJECTS
${NEBULA_CLIENT_OBJS}
$<TARGET_OBJECTS:nebula_common_obj>
$<TARGET_OBJECTS:nebula_graph_client_obj>
LIBRARIES
gtest
${NEBULA_THIRD_PARTY_LIBRARIES}
)

nebula_add_test(
NAME
session_test
Expand All @@ -30,6 +44,33 @@ nebula_add_test(
${NEBULA_THIRD_PARTY_LIBRARIES}
)

nebula_add_executable(
NAME
regist_host
SOURCES
RegistHost.cpp
OBJECTS
${NEBULA_CLIENT_OBJS}
$<TARGET_OBJECTS:nebula_common_obj>
$<TARGET_OBJECTS:nebula_graph_client_obj>
LIBRARIES
${NEBULA_THIRD_PARTY_LIBRARIES}
)

nebula_add_test(
NAME
session_ssl_test
SOURCES
SessionSSLTest.cpp
OBJECTS
${NEBULA_CLIENT_OBJS}
$<TARGET_OBJECTS:nebula_common_obj>
$<TARGET_OBJECTS:nebula_graph_client_obj>
LIBRARIES
gtest
${NEBULA_THIRD_PARTY_LIBRARIES}
)

nebula_add_test(
NAME
address_test
Expand Down
44 changes: 44 additions & 0 deletions src/client/tests/ConnectionSSLTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#include <common/Init.h>
#include <folly/json.h>
#include <folly/synchronization/Baton.h>
#include <glog/logging.h>
#include <gtest/gtest.h>
#include <nebula/client/Connection.h>

#include "./ClientTest.h"

// Require a nebula server could access

static constexpr char kServerHost[] = "graphd";

class ConnectionTest : public ClientTest {};

TEST_F(ConnectionTest, SSL) {
nebula::Connection c;

ASSERT_TRUE(c.open(kServerHost, 9669, 10, true, ""));

// auth
auto authResp = c.authenticate("root", "nebula");
ASSERT_EQ(authResp.errorCode, nebula::ErrorCode::SUCCEEDED) << *authResp.errorMsg;

// execute
auto resp = c.execute(*authResp.sessionId, "YIELD 1");
ASSERT_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED);
nebula::DataSet expected({"1"});
expected.emplace_back(nebula::List({1}));
EXPECT_TRUE(verifyResultWithoutOrder(*resp.data, expected));
}

int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
nebula::init(&argc, &argv);
google::SetStderrLogging(google::INFO);

return RUN_ALL_TESTS();
}
17 changes: 0 additions & 17 deletions src/client/tests/ConnectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,6 @@ TEST_F(ConnectionTest, Timeout) {
ASSERT_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED);
}

TEST_F(ConnectionTest, SSL) {
nebula::Connection c;

ASSERT_TRUE(c.open(kServerHost, 9669, 10, true, ""));

// auth
auto authResp = c.authenticate("root", "nebula");
ASSERT_EQ(authResp.errorCode, nebula::ErrorCode::SUCCEEDED) << *authResp.errorMsg;

// execute
auto resp = c.execute(*authResp.sessionId, "YIELD 1");
ASSERT_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED);
nebula::DataSet expected({"1"});
expected.emplace_back(nebula::List({1}));
EXPECT_TRUE(verifyResultWithoutOrder(*resp.data, expected));
}

TEST_F(ConnectionTest, JsonResult) {
nebula::Connection c;

Expand Down
37 changes: 37 additions & 0 deletions src/client/tests/RegistHost.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#include <common/Init.h>
#include <folly/Format.h>
#include <glog/logging.h>
#include <nebula/client/Config.h>
#include <nebula/client/ConnectionPool.h>
#include <nebula/client/Session.h>

#include <atomic>
#include <chrono>
#include <thread>

// Require a nebula server could access

DEFINE_string(host, "", "Register host address.");
DEFINE_string(server, "127.0.0.1:9669", "Nebula server address.");
DEFINE_bool(enable_ssl, false, "Enable SSL.");

int main(int argc, char** argv) {
nebula::init(&argc, &argv);
google::SetStderrLogging(google::INFO);

nebula::ConnectionPool pool;
nebula::Config c{10, 0, 300, 0, "", FLAGS_enable_ssl};
pool.init({FLAGS_server}, c);
auto session = pool.getSession("root", "nebula");
CHECK(session.valid());

auto resp =
session.execute(folly::format("ADD HOSTS {} INTO NEW ZONE 'default_zone'", FLAGS_host).str());
CHECK_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED) << *resp.errorMsg;
return 0;
}
Loading