-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into user_meta
- Loading branch information
Showing
47 changed files
with
1,052 additions
and
884 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
add_executable( | ||
test_serverContext_test | ||
TestServerContext.cpp | ||
$<TARGET_OBJECTS:thrift_obj> | ||
$<TARGET_OBJECTS:base_obj> | ||
$<TARGET_OBJECTS:thread_obj> | ||
) | ||
nebula_link_libraries( | ||
test_serverContext_test | ||
${THRIFT_LIBRARIES} | ||
wangle | ||
gtest | ||
) | ||
nebula_add_test(test_serverContext_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* Copyright (c) 2019 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
#ifndef COMMON_TEST_SERVERCONTEXT_H_ | ||
#define COMMON_TEST_SERVERCONTEXT_H_ | ||
|
||
#include "base/Base.h" | ||
#include "thread/NamedThread.h" | ||
#include "kvstore/KVStore.h" | ||
#include "meta/client/MetaClient.h" | ||
#include <thrift/lib/cpp2/server/ThriftServer.h> | ||
|
||
namespace nebula { | ||
namespace test { | ||
|
||
struct ServerContext { | ||
~ServerContext() { | ||
if (server_ != nullptr) { | ||
server_->stop(); | ||
} | ||
if (thread_ != nullptr) { | ||
thread_->join(); | ||
} | ||
KVStore_ = nullptr; | ||
server_ = nullptr; | ||
thread_ = nullptr; | ||
VLOG(3) << "~ServerContext"; | ||
} | ||
|
||
std::unique_ptr<apache::thrift::ThriftServer> server_{nullptr}; | ||
std::unique_ptr<thread::NamedThread> thread_{nullptr}; | ||
// To keep meta and storage's KVStore | ||
std::unique_ptr<kvstore::KVStore> KVStore_{nullptr}; | ||
uint16_t port_{0}; | ||
}; | ||
|
||
static void mockCommon(test::ServerContext *sc, | ||
const std::string &name, | ||
uint16_t port, | ||
std::shared_ptr<apache::thrift::ServerInterface> handler) { | ||
if (nullptr == sc) { | ||
LOG(ERROR) << "ServerContext is nullptr"; | ||
return; | ||
} | ||
sc->server_ = std::make_unique<apache::thrift::ThriftServer>(); | ||
sc->server_->setInterface(std::move(handler)); | ||
sc->server_->setPort(port); | ||
sc->thread_ = std::make_unique<thread::NamedThread>(name, [&]() { | ||
sc->server_->serve(); | ||
LOG(INFO) << "Stop the server..."; | ||
}); | ||
while (!sc->server_->getServeEventBase() || | ||
!sc->server_->getServeEventBase()->isRunning()) { | ||
} | ||
sc->port_ = sc->server_->getAddress().getPort(); | ||
} | ||
|
||
} // namespace test | ||
} // namespace nebula | ||
#endif // COMMON_TEST_SERVERCONTEXT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Copyright (c) 2019 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#include "base/Base.h" | ||
#include <gtest/gtest.h> | ||
#include "test/ServerContext.h" | ||
|
||
|
||
namespace nebula { | ||
namespace test { | ||
|
||
class TestServer final : public apache::thrift::ServerInterface { | ||
public: | ||
TestServer() {} | ||
~TestServer() {} | ||
std::unique_ptr<apache::thrift::AsyncProcessor> getProcessor() override { | ||
return nullptr; | ||
} | ||
}; | ||
|
||
TEST(ServerContext, mockCommon) { | ||
auto sc = std::make_unique<ServerContext>(); | ||
auto handler = std::make_shared<TestServer>(); | ||
test::mockCommon(sc.get(), "test", 0, handler); | ||
} | ||
|
||
} // namespace test | ||
} // namespace nebula | ||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
folly::init(&argc, &argv, true); | ||
google::SetStderrLogging(google::INFO); | ||
|
||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.