Skip to content

Commit 00f3c03

Browse files
committed
Mention gRPCurl on the server testing page (Fixes #428)
1 parent 63d5d9e commit 00f3c03

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

docs/en/server/getting-started.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ grpc-service.
297297

298298
By default, the grpc-server will be started on port `9090` using `PLAINTEXT` mode.
299299

300-
You can test that your application is working as expected by running these [grpcurl](https://github.com/fullstorydev/grpcurl) commands:
300+
You can test that your application is working as expected by running these [gRPCurl](https://github.com/fullstorydev/grpcurl) commands:
301301

302302
````sh
303303
grpcurl --plaintext localhost:9090 list
@@ -308,6 +308,10 @@ grpcurl --plaintext -d '{"name": "test"}' localhost:9090 net.devh.boot.grpc.exam
308308
grpcurl --plaintext -d "{\"name\": \"test\"}" localhost:9090 net.devh.boot.grpc.example.MyService/sayHello
309309
````
310310

311+
See [here](testing.md#grpcurl) for `gRPCurl` example command output and additional information.
312+
313+
> Note: Don't forget to write [actual/automated tests](testing.md) for your service implementation.
314+
311315
## Additional Topics <!-- omit in toc -->
312316

313317
- *Getting Started*

docs/en/server/testing.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Please refer to [Tests with Grpc-Stubs](../client/testing.md).
1616
- [Standalone Tests](#standalone-tests)
1717
- [Spring-based Tests](#spring-based-tests)
1818
- [Integration Tests](#integration-tests)
19+
- [gRPCurl](#grpcurl)
1920

2021
## Additional Topics <!-- omit in toc -->
2122

@@ -33,10 +34,11 @@ We all know how important it is to test our application, so I will only refer yo
3334
- [Testing with JUnit](https://junit.org/junit5/docs/current/user-guide/#writing-tests)
3435
- [grpc-spring-boot-starter's Tests](https://github.com/yidongnan/grpc-spring-boot-starter/tree/master/tests/src/test/java/net/devh/boot/grpc/test)
3536

36-
Generally there are two ways to test your grpc service:
37+
Generally there are three ways to test your grpc service:
3738

3839
- [Test them directly](#unit-tests)
3940
- [Test them via grpc](#integration-tests)
41+
- [Test them in producation](#grpcurl) (in addition to automated build time tests)
4042

4143
## The Service to Test
4244

@@ -296,6 +298,72 @@ public class MyServiceIntegrationTestConfiguration {
296298

297299
> Note: This code might look shorter/simpler than the unit test one, but the execution time is serveral times longer.
298300
301+
## gRPCurl
302+
303+
[`gRPCurl`](https://github.com/fullstorydev/grpcurl) is a small command line application,
304+
that you can use to query your application at runtime. Or as their Readme states:
305+
306+
> It's basically `curl` for gRPC servers.
307+
308+
You can even use the responses with `jq` and use it in your automation.
309+
310+
Skip the first/this block if you already know what you wish to query.
311+
312+
````bash
313+
$ # First scan the server for available services
314+
$ grpcurl --plaintext localhost:9090 list
315+
net.devh.boot.grpc.example.MyService
316+
$ # Then list the methods available for that call
317+
$ grpcurl --plaintext localhost:9090 list net.devh.boot.grpc.example.MyService
318+
net.devh.boot.grpc.example.MyService.SayHello
319+
$ # Lets check the request and response types
320+
$ grpcurl --plaintext localhost:9090 describe net.devh.boot.grpc.example.MyService/SayHello
321+
net.devh.boot.grpc.example.MyService.SayHello is a method:
322+
rpc SayHello ( .HelloRequest ) returns ( .HelloReply );
323+
$ # Now we only have query for the request body structure
324+
$ grpcurl --plaintext localhost:9898 describe net.devh.boot.grpc.example.HelloRequest
325+
net.devh.boot.grpc.example.HelloRequest is a message:
326+
message HelloRequest {
327+
string name = 1;
328+
}
329+
````
330+
331+
> Note: `gRPCurl` supports both `.` and `/` as separator between the service name and the method name:
332+
>
333+
> - `net.devh.boot.grpc.example.MyService.SayHello`
334+
> - `net.devh.boot.grpc.example.MyService/SayHello`
335+
>
336+
> We recommend the second variant as it matches grpc's internal full method name and the method name is easier to
337+
> detect in the call.
338+
339+
````bash
340+
$ # Finally we can call the actual method
341+
$ grpcurl --plaintext localhost:9090 net.devh.boot.grpc.example.MyService/SayHello
342+
{
343+
"message": "Hello ==> ",
344+
"counter": 1337
345+
}
346+
$ # Or call it with a populated request body
347+
$ grpcurl --plaintext -d '{"name": "Test"}' localhost:9090 net.devh.boot.grpc.example.MyService/SayHello
348+
{
349+
"message": "Hello ==> Test",
350+
"counter": 1337
351+
}
352+
````
353+
354+
> Note: If you use the windows terminal or wish to use variables inside the data block then you have to use `"` instead
355+
> of `'` and escape the `"` that are part of the actual json.
356+
>
357+
> ````cmd
358+
> > grpcurl --plaintext -d "{\"name\": \"Test\"}" localhost:9090 net.devh.boot.grpc.example.MyService/sayHello
359+
> {
360+
> "message": "Hello ==> Test",
361+
> "counter": 1337
362+
> }
363+
> ````
364+
365+
For more information regarding `gRPCurl` please refer to their [official documentation](https://github.com/fullstorydev/grpcurl)
366+
299367
## Additional Topics <!-- omit in toc -->
300368
301369
- [Getting Started](getting-started.md)

0 commit comments

Comments
 (0)