Skip to content
Snippets Groups Projects
Commit eef0f0ed authored by CPWstatic's avatar CPWstatic Committed by dangleptr
Browse files

Finish find path when we meet the dead end. (#1124)

parent e05e3420
No related branches found
No related tags found
No related merge requests found
......@@ -171,6 +171,12 @@ void FindPathExecutor::execute() {
}
void FindPathExecutor::getNeighborsAndFindPath() {
// We meet the dead end.
if (fromVids_.empty() || toVids_.empty()) {
onFinish_();
return;
}
fPro_ = std::make_unique<folly::Promise<folly::Unit>>();
tPro_ = std::make_unique<folly::Promise<folly::Unit>>();
std::vector<folly::Future<folly::Unit>> futures;
......@@ -213,6 +219,8 @@ void FindPathExecutor::findPath() {
VLOG(2) << "Find Path.";
visitedFrom_.clear();
std::multimap<VertexID, Path> pathF;
VLOG(2) << "Get froms: " << fromFrontiers_.second.size();
VLOG(2) << "Get tos: " << toFrontiers_.second.size();
for (auto &frontier : fromFrontiers_.second) {
// Notice: we treat edges with different ranking
// between two vertices as different path
......@@ -275,7 +283,7 @@ void FindPathExecutor::findPath() {
onFinish_();
return;
} else {
LOG(INFO) << "Current step:" << currentStep_;
VLOG(2) << "Current step:" << currentStep_;
++currentStep_;
}
getNeighborsAndFindPath();
......
......@@ -437,5 +437,68 @@ TEST_F(FindPathTest, multiEdgesAll) {
ASSERT_TRUE(verifyPath(resp, expected));
}
}
TEST_F(FindPathTest, vertexNotExist) {
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND SHORTEST PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto query = folly::stringPrintf(fmt,
std::hash<std::string>()("Nobody1"), std::hash<std::string>()("Nobody2"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND SHORTEST PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, tim.vid(), std::hash<std::string>()("Nobody"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND SHORTEST PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, std::hash<std::string>()("Nobody"), tim.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND ALL PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto query = folly::stringPrintf(fmt,
std::hash<std::string>()("Nobody1"), std::hash<std::string>()("Nobody2"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND ALL PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, tim.vid(), std::hash<std::string>()("Nobody"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND ALL PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, std::hash<std::string>()("Nobody"), tim.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
}
} // namespace graph
} // namespace nebula
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment