Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
8a26592b
Commit
8a26592b
authored
8 years ago
by
Yuchen Zeng
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #7899 from y-zeng/cli_type
gRPC CLI type command
parents
bbf5dc84
734fd71e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/cpp/util/grpc_tool.cc
+32
-4
32 additions, 4 deletions
test/cpp/util/grpc_tool.cc
test/cpp/util/grpc_tool_test.cc
+46
-1
46 additions, 1 deletion
test/cpp/util/grpc_tool_test.cc
with
78 additions
and
5 deletions
test/cpp/util/grpc_tool.cc
+
32
−
4
View file @
8a26592b
...
@@ -75,11 +75,11 @@ class GrpcTool {
...
@@ -75,11 +75,11 @@ class GrpcTool {
GrpcToolOutputCallback
callback
);
GrpcToolOutputCallback
callback
);
bool
CallMethod
(
int
argc
,
const
char
**
argv
,
const
CliCredentials
&
cred
,
bool
CallMethod
(
int
argc
,
const
char
**
argv
,
const
CliCredentials
&
cred
,
GrpcToolOutputCallback
callback
);
GrpcToolOutputCallback
callback
);
bool
PrintType
(
int
argc
,
const
char
**
argv
,
const
CliCredentials
&
cred
,
GrpcToolOutputCallback
callback
);
// TODO(zyc): implement the following methods
// TODO(zyc): implement the following methods
// bool ListServices(int argc, const char** argv, GrpcToolOutputCallback
// bool ListServices(int argc, const char** argv, GrpcToolOutputCallback
// callback);
// callback);
// bool PrintType(int argc, const char** argv, GrpcToolOutputCallback
// callback);
// bool PrintTypeId(int argc, const char** argv, GrpcToolOutputCallback
// bool PrintTypeId(int argc, const char** argv, GrpcToolOutputCallback
// callback);
// callback);
// bool ParseMessage(int argc, const char** argv, GrpcToolOutputCallback
// bool ParseMessage(int argc, const char** argv, GrpcToolOutputCallback
...
@@ -168,7 +168,7 @@ const Command ops[] = {
...
@@ -168,7 +168,7 @@ const Command ops[] = {
// {"ls", BindWith5Args(&GrpcTool::ListServices), 1, 3},
// {"ls", BindWith5Args(&GrpcTool::ListServices), 1, 3},
// {"list", BindWith5Args(&GrpcTool::ListServices), 1, 3},
// {"list", BindWith5Args(&GrpcTool::ListServices), 1, 3},
{
"call"
,
BindWith5Args
(
&
GrpcTool
::
CallMethod
),
2
,
3
},
{
"call"
,
BindWith5Args
(
&
GrpcTool
::
CallMethod
),
2
,
3
},
//
{"type", BindWith5Args(&GrpcTool::PrintType), 2, 2},
{
"type"
,
BindWith5Args
(
&
GrpcTool
::
PrintType
),
2
,
2
},
// {"parse", BindWith5Args(&GrpcTool::ParseMessage), 2, 3},
// {"parse", BindWith5Args(&GrpcTool::ParseMessage), 2, 3},
// {"totext", BindWith5Args(&GrpcTool::ToText), 2, 3},
// {"totext", BindWith5Args(&GrpcTool::ToText), 2, 3},
// {"tobinary", BindWith5Args(&GrpcTool::ToBinary), 2, 3},
// {"tobinary", BindWith5Args(&GrpcTool::ToBinary), 2, 3},
...
@@ -180,7 +180,7 @@ void Usage(const grpc::string& msg) {
...
@@ -180,7 +180,7 @@ void Usage(const grpc::string& msg) {
"%s
\n
"
"%s
\n
"
// " grpc_cli ls ... ; List services\n"
// " grpc_cli ls ... ; List services\n"
" grpc_cli call ... ; Call method
\n
"
" grpc_cli call ... ; Call method
\n
"
//
" grpc_cli type ... ; Print type\n"
" grpc_cli type ... ; Print type
\n
"
// " grpc_cli parse ... ; Parse message\n"
// " grpc_cli parse ... ; Parse message\n"
// " grpc_cli totext ... ; Convert binary message to text\n"
// " grpc_cli totext ... ; Convert binary message to text\n"
// " grpc_cli tobinary ... ; Convert text message to binary\n"
// " grpc_cli tobinary ... ; Convert text message to binary\n"
...
@@ -257,6 +257,34 @@ bool GrpcTool::Help(int argc, const char** argv, const CliCredentials& cred,
...
@@ -257,6 +257,34 @@ bool GrpcTool::Help(int argc, const char** argv, const CliCredentials& cred,
return
true
;
return
true
;
}
}
bool
GrpcTool
::
PrintType
(
int
argc
,
const
char
**
argv
,
const
CliCredentials
&
cred
,
GrpcToolOutputCallback
callback
)
{
CommandUsage
(
"Print type
\n
"
" grpc_cli type <address> <type>
\n
"
" <address> ; host:port
\n
"
" <type> ; Protocol buffer type name
\n
"
+
cred
.
GetCredentialUsage
());
grpc
::
string
server_address
(
argv
[
0
]);
std
::
shared_ptr
<
grpc
::
Channel
>
channel
=
grpc
::
CreateChannel
(
server_address
,
cred
.
GetCredentials
());
grpc
::
ProtoReflectionDescriptorDatabase
desc_db
(
channel
);
grpc
::
protobuf
::
DescriptorPool
desc_pool
(
&
desc_db
);
grpc
::
string
output
;
const
grpc
::
protobuf
::
Descriptor
*
descriptor
=
desc_pool
.
FindMessageTypeByName
(
argv
[
1
]);
if
(
descriptor
!=
nullptr
)
{
output
=
descriptor
->
DebugString
();
}
else
{
fprintf
(
stderr
,
"Type %s not found.
\n
"
,
argv
[
1
]);
return
false
;
}
return
callback
(
output
);
}
bool
GrpcTool
::
CallMethod
(
int
argc
,
const
char
**
argv
,
bool
GrpcTool
::
CallMethod
(
int
argc
,
const
char
**
argv
,
const
CliCredentials
&
cred
,
const
CliCredentials
&
cred
,
GrpcToolOutputCallback
callback
)
{
GrpcToolOutputCallback
callback
)
{
...
...
This diff is collapsed.
Click to expand it.
test/cpp/util/grpc_tool_test.cc
+
46
−
1
View file @
8a26592b
...
@@ -109,13 +109,21 @@ class GrpcToolTest : public ::testing::Test {
...
@@ -109,13 +109,21 @@ class GrpcToolTest : public ::testing::Test {
void
ShutdownServer
()
{
server_
->
Shutdown
();
}
void
ShutdownServer
()
{
server_
->
Shutdown
();
}
void
ExitWhenError
(
int
argc
,
const
char
**
argv
,
const
CliCredentials
&
cred
,
GrpcToolOutputCallback
callback
)
{
int
result
=
GrpcToolMainLib
(
argc
,
argv
,
cred
,
callback
);
if
(
result
)
{
exit
(
result
);
}
}
std
::
unique_ptr
<
Server
>
server_
;
std
::
unique_ptr
<
Server
>
server_
;
TestServiceImpl
service_
;
TestServiceImpl
service_
;
reflection
::
ProtoServerReflectionPlugin
plugin_
;
reflection
::
ProtoServerReflectionPlugin
plugin_
;
};
};
static
bool
PrintStream
(
std
::
stringstream
*
ss
,
const
grpc
::
string
&
output
)
{
static
bool
PrintStream
(
std
::
stringstream
*
ss
,
const
grpc
::
string
&
output
)
{
(
*
ss
)
<<
output
<<
std
::
endl
;
(
*
ss
)
<<
output
;
return
true
;
return
true
;
}
}
...
@@ -168,6 +176,43 @@ TEST_F(GrpcToolTest, HelpCommand) {
...
@@ -168,6 +176,43 @@ TEST_F(GrpcToolTest, HelpCommand) {
EXPECT_TRUE
(
0
==
output_stream
.
tellp
());
EXPECT_TRUE
(
0
==
output_stream
.
tellp
());
}
}
TEST_F
(
GrpcToolTest
,
TypeCommand
)
{
// Test input "grpc_cli type localhost:<port> grpc.testing.EchoRequest"
std
::
stringstream
output_stream
;
const
grpc
::
string
server_address
=
SetUpServer
();
const
char
*
argv
[]
=
{
"grpc_cli"
,
"type"
,
server_address
.
c_str
(),
"grpc.testing.EchoRequest"
};
EXPECT_TRUE
(
0
==
GrpcToolMainLib
(
ArraySize
(
argv
),
argv
,
TestCliCredentials
(),
std
::
bind
(
PrintStream
,
&
output_stream
,
std
::
placeholders
::
_1
)));
const
grpc
::
protobuf
::
Descriptor
*
desc
=
grpc
::
protobuf
::
DescriptorPool
::
generated_pool
()
->
FindMessageTypeByName
(
"grpc.testing.EchoRequest"
);
// Expected output: the DebugString of grpc.testing.EchoRequest
EXPECT_TRUE
(
0
==
strcmp
(
output_stream
.
str
().
c_str
(),
desc
->
DebugString
().
c_str
()));
ShutdownServer
();
}
TEST_F
(
GrpcToolTest
,
TypeNotFound
)
{
// Test input "grpc_cli type localhost:<port> grpc.testing.DummyRequest"
std
::
stringstream
output_stream
;
const
grpc
::
string
server_address
=
SetUpServer
();
const
char
*
argv
[]
=
{
"grpc_cli"
,
"type"
,
server_address
.
c_str
(),
"grpc.testing.DummyRequest"
};
EXPECT_DEATH
(
ExitWhenError
(
ArraySize
(
argv
),
argv
,
TestCliCredentials
(),
std
::
bind
(
PrintStream
,
&
output_stream
,
std
::
placeholders
::
_1
)),
".*Type grpc.testing.DummyRequest not found.*"
);
ShutdownServer
();
}
TEST_F
(
GrpcToolTest
,
CallCommand
)
{
TEST_F
(
GrpcToolTest
,
CallCommand
)
{
// Test input "grpc_cli call Echo"
// Test input "grpc_cli call Echo"
std
::
stringstream
output_stream
;
std
::
stringstream
output_stream
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment