grpc-wiremock
Описание
gRPC Mock Server
Языки
- Java96,9%
- Dockerfile3,1%
Overview
grpc-wiremock is a mock server for GRPC services implemented as a wrapper around the WireMock http server.
How It Works
grpc-wiremock starts a gRPC server generated based on provided proto files which will convert a proto grpc request to JSON and redirects it as a POST request to the WireMock then converts a http response back to grpc proto format.
- GRPC server works on tcp://localhost:50000
- WireMock server works on http://localhost:8888
Quick Usage
- Run
- Stub
- Check
Should get response:
Stubbing
Stubbing should be done via WireMock JSON API
Error mapping
Default error (not ) mapping is based on https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto :
| HTTP Status Code | GRPC Status |
|---|---|
| 400 Bad Request | INVALID_ARGUMENT |
| 401 Unauthorized | UNAUTHENTICATED |
| 403 Forbidden | PERMISSION_DENIED |
| 404 Not Found | NOT_FOUND |
| 409 Conflict | ALREADY_EXISTS |
| 429 Too Many Requests | RESOURCE_EXHAUSTED |
| 499 Client Closed Request | CANCELLED |
| 500 Internal Server Error | INTERNAL |
| 501 Not Implemented | UNIMPLEMENTED |
| 503 Service Unavailable | UNAVAILABLE |
| 504 Gateway Timeout | DEADLINE_EXCEEDED |
And could be overridden or augmented by overriding or augmenting the following properties:
For example:
How To:
1. Configure gRPC server
Currently, following grpc server properties are supported:
Could be used like this:
2. Configure WireMock server
WireMock server may be configured by passing command line options
prefixed by :
3. Mock server-side streaming:
Given the service:
Then the following stub may be provided, where specifies
how many responses should be returned during the stream ( - if absent).
The current response iteration number is available in :
4. Speed up container start
In case you don't need to change proto files, you can build your own image with precompiled protos.
See an example
5. Use with snappy compresser/decompresser
Snappy support can be enabled using env variable as follows:
Also in docker-compose:
*gzip compression supported by default
6. Use in load testing
To increase performance some Wiremock related options may be tuned either directly or by enabling the "load" profile. Next two commands are identical:
7. Preserving proto field names in stubs
By default, stub mappings must have proto fields references in lowerCamlCase, e.g. proto field must be referenced as:
To preserve proto field names the following env variable could be used: