Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
cfab9e1f
Commit
cfab9e1f
authored
Oct 09, 2018
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* improve grpc status to error code conversion
* improve grpc UT
parent
165499ef
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
18 deletions
+19
-18
grpc.cpp
src/brpc/grpc.cpp
+6
-3
brpc_grpc_protocol_unittest.cpp
test/brpc_grpc_protocol_unittest.cpp
+11
-13
grpc.proto
test/grpc.proto
+2
-2
No files found.
src/brpc/grpc.cpp
View file @
cfab9e1f
...
...
@@ -61,13 +61,17 @@ GrpcStatus ErrorCodeToGrpcStatus(int error_code) {
case
EINVAL
:
return
GRPC_INVALIDARGUMENT
;
case
ELIMIT
:
return
GRPC_RESOURCEEXHAUSTED
;
case
ELOGOFF
:
return
GRPC_UNAVAILABLE
;
case
EPERM
:
return
GRPC_PERMISSIONDENIED
;
case
ERPCTIMEDOUT
:
return
GRPC_DEADLINEEXCEEDED
;
case
ETIMEDOUT
:
return
GRPC_INTERNAL
;
case
ECANCELED
:
return
GRPC_CANCELED
;
default
:
return
GRPC_INTERNAL
;
}
...
...
@@ -80,6 +84,7 @@ int GrpcStatusToErrorCode(GrpcStatus grpc_status) {
case
GRPC_CANCELED
:
return
ECANCELED
;
case
GRPC_UNKNOWN
:
return
EINTERNAL
;
case
GRPC_INVALIDARGUMENT
:
return
EINVAL
;
case
GRPC_DEADLINEEXCEEDED
:
...
...
@@ -99,9 +104,8 @@ int GrpcStatusToErrorCode(GrpcStatus grpc_status) {
case
GRPC_UNIMPLEMENTED
:
return
ENOMETHOD
;
case
GRPC_INTERNAL
:
return
EINTERNAL
;
case
GRPC_UNAVAILABLE
:
return
E
AGAIN
;
return
E
INTERNAL
;
case
GRPC_DATALOSS
:
return
EINTERNAL
;
case
GRPC_UNAUTHENTICATED
:
...
...
@@ -109,7 +113,6 @@ int GrpcStatusToErrorCode(GrpcStatus grpc_status) {
default
:
return
EINTERNAL
;
}
}
void
PercentEncode
(
const
std
::
string
&
str
,
std
::
string
*
str_out
)
{
...
...
test/brpc_grpc_protocol_unittest.cpp
View file @
cfab9e1f
...
...
@@ -55,16 +55,13 @@ public:
brpc
::
ClosureGuard
done_guard
(
done
);
EXPECT_EQ
(
g_req
,
req
->
message
());
if
(
req
->
has_gzip
()
&&
req
->
gzip
())
{
if
(
req
->
gzip
())
{
cntl
->
set_response_compress_type
(
brpc
::
COMPRESS_TYPE_GZIP
);
}
res
->
set_message
(
g_prefix
+
req
->
message
());
if
(
req
->
has_error_code
())
{
const
std
::
string
err_msg
=
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
());
if
(
req
->
return_error
())
{
cntl
->
SetFailed
(
brpc
::
EINTERNAL
,
"%s"
,
g_prefix
.
c_str
());
return
;
}
}
...
...
@@ -105,6 +102,7 @@ protected:
}
req
.
set_message
(
g_req
);
req
.
set_gzip
(
res_gzip
);
req
.
set_return_error
(
false
);
test
::
GrpcService_Stub
stub
(
&
_channel
);
stub
.
Method
(
&
cntl
,
&
req
,
&
res
,
NULL
);
...
...
@@ -154,20 +152,17 @@ TEST_F(GrpcTest, sanity) {
}
TEST_F
(
GrpcTest
,
return_error
)
{
// GRPC_OK(0) is skipped
for
(
int
i
=
1
;
i
<
(
int
)
brpc
::
GRPC_MAX
;
++
i
)
{
test
::
GrpcRequest
req
;
test
::
GrpcResponse
res
;
brpc
::
Controller
cntl
;
req
.
set_message
(
g_req
);
req
.
set_error_code
(
i
);
req
.
set_gzip
(
false
);
req
.
set_return_error
(
true
);
test
::
GrpcService_Stub
stub
(
&
_channel
);
stub
.
Method
(
&
cntl
,
&
req
,
&
res
,
NULL
);
EXPECT_TRUE
(
cntl
.
Failed
());
// TODO(zhujiashun): set and check error_code when GrpcStatusToErrorCode is done
EXPECT_EQ
(
cntl
.
ErrorCode
(),
brpc
::
EINTERNAL
);
EXPECT_TRUE
(
butil
::
StringPiece
(
cntl
.
ErrorText
()).
ends_with
(
butil
::
string_printf
(
"%s%d"
,
g_prefix
.
c_str
(),
i
)));
}
EXPECT_TRUE
(
butil
::
StringPiece
(
cntl
.
ErrorText
()).
ends_with
(
butil
::
string_printf
(
"%s"
,
g_prefix
.
c_str
())));
}
TEST_F
(
GrpcTest
,
RpcTimedOut
)
{
...
...
@@ -181,6 +176,8 @@ TEST_F(GrpcTest, RpcTimedOut) {
test
::
GrpcResponse
res
;
brpc
::
Controller
cntl
;
req
.
set_message
(
g_req
);
req
.
set_gzip
(
false
);
req
.
set_return_error
(
false
);
test
::
GrpcService_Stub
stub
(
&
_channel
);
stub
.
MethodTimeOut
(
&
cntl
,
&
req
,
&
res
,
NULL
);
EXPECT_TRUE
(
cntl
.
Failed
());
...
...
@@ -192,10 +189,11 @@ TEST_F(GrpcTest, MethodNotExist) {
test
::
GrpcResponse
res
;
brpc
::
Controller
cntl
;
req
.
set_message
(
g_req
);
req
.
set_gzip
(
false
);
req
.
set_return_error
(
false
);
test
::
GrpcService_Stub
stub
(
&
_channel
);
stub
.
MethodNotExist
(
&
cntl
,
&
req
,
&
res
,
NULL
);
EXPECT_TRUE
(
cntl
.
Failed
());
// TODO(zhujiashun): set and check error_code when GrpcStatusToErrorCode is done
EXPECT_EQ
(
cntl
.
ErrorCode
(),
brpc
::
EINTERNAL
);
ASSERT_TRUE
(
butil
::
StringPiece
(
cntl
.
ErrorText
()).
ends_with
(
"Method MethodNotExist() not implemented."
));
}
...
...
test/grpc.proto
View file @
cfab9e1f
...
...
@@ -5,8 +5,8 @@ package test;
message
GrpcRequest
{
required
string
message
=
1
;
optional
bool
gzip
=
2
;
optional
int32
error_code
=
3
;
required
bool
gzip
=
2
;
required
bool
return_error
=
3
;
};
message
GrpcResponse
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment