Commit ec5c3681 authored by zhujiashun's avatar zhujiashun

Add a case in ErrorCodeToGrpcStatus

parent 2e471c02
...@@ -26,6 +26,8 @@ namespace brpc { ...@@ -26,6 +26,8 @@ namespace brpc {
GrpcStatus ErrorCodeToGrpcStatus(int error_code) { GrpcStatus ErrorCodeToGrpcStatus(int error_code) {
switch (error_code) { switch (error_code) {
case 0:
return GRPC_OK;
case ENOSERVICE: case ENOSERVICE:
case ENOMETHOD: case ENOMETHOD:
return GRPC_UNIMPLEMENTED; return GRPC_UNIMPLEMENTED;
...@@ -43,7 +45,7 @@ GrpcStatus ErrorCodeToGrpcStatus(int error_code) { ...@@ -43,7 +45,7 @@ GrpcStatus ErrorCodeToGrpcStatus(int error_code) {
case ETIMEDOUT: case ETIMEDOUT:
return GRPC_INTERNAL; return GRPC_INTERNAL;
default: default:
return GRPC_OK; return GRPC_INTERNAL;
} }
} }
......
...@@ -63,6 +63,7 @@ public: ...@@ -63,6 +63,7 @@ public:
if (req->has_error_code()) { if (req->has_error_code()) {
const std::string err_msg = const std::string err_msg =
butil::string_printf("%s%d", g_prefix.c_str(), req->error_code()); butil::string_printf("%s%d", g_prefix.c_str(), req->error_code());
// TODO(zhujiashun): set and check error_code when GrpcStatusToErrorCode is done
cntl->SetFailed(err_msg.c_str()); cntl->SetFailed(err_msg.c_str());
return; return;
} }
...@@ -109,7 +110,6 @@ protected: ...@@ -109,7 +110,6 @@ protected:
stub.Method(&cntl, &req, &res, NULL); stub.Method(&cntl, &req, &res, NULL);
EXPECT_FALSE(cntl.Failed()) << cntl.ErrorCode() << ": " << cntl.ErrorText(); EXPECT_FALSE(cntl.Failed()) << cntl.ErrorCode() << ": " << cntl.ErrorText();
EXPECT_EQ(res.message(), g_prefix + g_req); EXPECT_EQ(res.message(), g_prefix + g_req);
//EXPECT_EQ(brpc::GRPC_OK, cntl.grpc_status());
} }
brpc::Server _server; brpc::Server _server;
...@@ -164,9 +164,9 @@ TEST_F(GrpcTest, return_error) { ...@@ -164,9 +164,9 @@ TEST_F(GrpcTest, return_error) {
test::GrpcService_Stub stub(&_channel); test::GrpcService_Stub stub(&_channel);
stub.Method(&cntl, &req, &res, NULL); stub.Method(&cntl, &req, &res, NULL);
EXPECT_TRUE(cntl.Failed()); EXPECT_TRUE(cntl.Failed());
// FIXME(zhujiashun): message body is empty so the Errorcode may be ERESPONSE // TODO(zhujiashun): set and check error_code when GrpcStatusToErrorCode is done
// EXPECT_EQ(cntl.ErrorCode(), brpc::EINTERNAL); EXPECT_EQ(cntl.ErrorCode(), brpc::EINTERNAL);
// EXPECT_EQ(cntl.ErrorText(), butil::string_printf("%s%d", g_prefix.c_str(), i)); EXPECT_TRUE(butil::StringPiece(cntl.ErrorText()).ends_with(butil::string_printf("%s%d", g_prefix.c_str(), i)));
} }
} }
...@@ -195,9 +195,9 @@ TEST_F(GrpcTest, MethodNotExist) { ...@@ -195,9 +195,9 @@ TEST_F(GrpcTest, MethodNotExist) {
test::GrpcService_Stub stub(&_channel); test::GrpcService_Stub stub(&_channel);
stub.MethodNotExist(&cntl, &req, &res, NULL); stub.MethodNotExist(&cntl, &req, &res, NULL);
EXPECT_TRUE(cntl.Failed()); EXPECT_TRUE(cntl.Failed());
// FIXME(zhujiashun): message body is empty so the Errorcode may be ERESPONSE // TODO(zhujiashun): set and check error_code when GrpcStatusToErrorCode is done
//EXPECT_EQ(cntl.ErrorCode(), brpc::EINTERNAL); EXPECT_EQ(cntl.ErrorCode(), brpc::EINTERNAL);
//ASSERT_TRUE(butil::StringPiece(cntl.ErrorText()).ends_with("Method MethodNotExist() not implemented.")); ASSERT_TRUE(butil::StringPiece(cntl.ErrorText()).ends_with("Method MethodNotExist() not implemented."));
} }
} // namespace } // namespace
Markdown is supported
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