@@ -16,6 +16,7 @@ Please refer to [Tests with Grpc-Stubs](../client/testing.md).
16
16
- [ Standalone Tests] ( #standalone-tests )
17
17
- [ Spring-based Tests] ( #spring-based-tests )
18
18
- [ Integration Tests] ( #integration-tests )
19
+ - [ gRPCurl] ( #grpcurl )
19
20
20
21
## Additional Topics <!-- omit in toc -->
21
22
@@ -33,10 +34,11 @@ We all know how important it is to test our application, so I will only refer yo
33
34
- [ Testing with JUnit] ( https://junit.org/junit5/docs/current/user-guide/#writing-tests )
34
35
- [ 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 )
35
36
36
- Generally there are two ways to test your grpc service:
37
+ Generally there are three ways to test your grpc service:
37
38
38
39
- [ Test them directly] ( #unit-tests )
39
40
- [ Test them via grpc] ( #integration-tests )
41
+ - [ Test them in producation] ( #grpcurl ) (in addition to automated build time tests)
40
42
41
43
## The Service to Test
42
44
@@ -296,6 +298,72 @@ public class MyServiceIntegrationTestConfiguration {
296
298
297
299
> Note: This code might look shorter/simpler than the unit test one, but the execution time is serveral times longer.
298
300
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
+
299
367
## Additional Topics <!-- omit in toc -->
300
368
301
369
- [Getting Started](getting-started.md)
0 commit comments