Traffic Parrot needs to know about the schema of your messages.
One way to do this is to provide your protocol buffer files. We currently support the proto3 specification.
To do this, simply copy your .proto files into the trafficparrot-enterprise-release-x.y.z/proto directory and Traffic Parrot will use these definitions during record/replay.
Traffic Parrot can discover the schema of your messages during recording if you have server reflection enabled in your gRPC server.
Discovered schemas are saved in the trafficparrot-enterprise-release-x.y.z/proto-bin directory and are used during replay.
To enable server reflection please follow the instructions for your gRPC server language:Typically, gRPC is authenticated using SSL/TLS
Traffic Parrot has the following properties that can be used to configure SSL/TLS:The URL property values can be set to classpath entries e.g. classpath:certificates/grpc/server.pem
By default Traffic Parrot has properties that correspond to the certificates found in the trafficparrot-enterprise-release-x.y.z/certificates/grpc directory.
Alternatively, you can specify file URL entries e.g. file:///path/to/server.pem
The property trafficparrot.virtualservice.grpc.non.tls.port specifies a port that can be used if SSL/TLS is not required (default 5552).The following properties have a significant impact on gRPC performance during replay:
Property | Description |
---|---|
trafficparrot.virtualservice.grpc.server.replay.proto.cache.milliseconds | Proto files can be cached in memory during replay to improve performance. The default value of 0 means do not cache at all. |
trafficparrot.virtualservice.grpc.server.replay.proto.cache.populate.on.startup | When true the proto file cache will be populated immediately on startup. |
trafficparrot.virtualservice.mapping.cache.milliseconds | Mapping files can be cached in memory during replay to improve performance. The default value of 0 means do not cache at all. |
trafficparrot.virtualservice.mapping.cache.populate.on.startup | When true the mapping file cache will be populated immediately on startup. |
trafficparrot.virtualservice.grpc.server.boss.threads | The number of boss threads used to service gRPC requests. Typically best set to either DOUBLE_NUMBER_OF_PROCESSORS or NUMBER_OF_PROCESSORS based on the number of available processors the system has. |
trafficparrot.virtualservice.grpc.server.boss.threads | The number of worker threads used to service gRPC requests. Typically best set to either DOUBLE_NUMBER_OF_PROCESSORS or NUMBER_OF_PROCESSORS based on the number of available processors the system has. |
During recording, incoming and outgoing messages are matched up to provide mappings. Then upon playback receipt of a matching incoming message will trigger generation of an outgoing message.
This diagram shows how two production systems connect:One system sends a gRPC request message to another system, which consumes the messages and returns a gRPC response message to the first system. If our goal is to test the system-under-test in isolation, we must record these interactions in order to replay them.
As you can see in the diagram below, the virtual service acts as a proxy between the gRPC client and gRPC server. The provided proto files are used to determine the message schema of the request and response messages for the requested gRPC method. Mappings are saved representing request/response pairs that have been recorded.
As the system under test generates messages and receives responses they are paired into mappings and listed in the 'Mappings' table.
On replay, the provided proto files are again used to determine the schema of the requested gRPC method. The request is matched against the mappings to find the corresponding response message.
As you can see in the diagram below, the virtual service acts as a proxy between the gRPC client and gRPC server. Server reflection is used to pull the proto files definitions from the gRPC server for the requested gRPC method. These proto files are saved for later use during replay. Mappings are saved representing request/response pairs that have been recorded.
As the system under test generates messages and receives responses they are paired into mappings and listed in the 'Mappings' table.
On replay, the recored proto files used to determine the schema of the requested gRPC method. The request is matched against the mappings to find the corresponding response message.
First, go to gRPC in the top navigation bar and click Add/Edit.
Fill in the Request/Response fields and click Save to configure a mapping.
You can also select from the message skeleton dropdown which will populate the Request/Response fields with a message skeleton for that message type.
After saving the mapping, it will appear in the list of mappings.
Clicking the edit button will allow you to edit an existing mapping.
The request and response body can be edited as if they were a JSON body. You are free to change the JSON as you wish, so long as the edits are compatible with the underlying proto message schema that the JSON represents.
gRPC allows for returning one or more custom detail objects in exception responses. Traffic Parrot currently supports specifying a single details object:
You must specify the fully qualified type e.g. com.example.Details as well as the JSON representation of the object.
The request priority can be set in order to set up a preference order for matching mappings.
The highest priority value is 1. If two or more mappings both match a request, the mapping with the higher priority will be used to provide the response. The default priority is 5.
This can be useful, if you want a "catch-all" mapping that returns a general response for most requests and specific mappings on top that return more specific responses.
Request metadata can be specified as key: value pairs. This means that Traffic Parrot will only match requests that contain the specified metadata values.
You can use the property trafficparrot.virtualservice.grpc.exclude.request.headers.from.matching to exclude request headers from matching. For example typical headers such as content-type,user-agent,grpc-accept-encoding are not typically useful to match on.
To populate the list of message skeletons, you need to configure Traffic Parrot with your proto files.
Then you can select the name of a gRPC method from the list and a sample request and response value will be generated, containing the default values for the message.
This documentation is for an old version of Traffic Parrot. There is a more recent Traffic Parrot version available for download at trafficparrot.com