GRPC virtual service architecture

A developer or tester uses a web browser to access the console. The console manages the virtual service. The system under test (application under test) connects directly to the virtual service on different ports.
GRPC architecture

Configuration

Proto files

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.

Server reflection

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:

SSL/TLS

Typically, GRPC is authenticated using SSL/TLS

Traffic Parrot has the following properties that can be used to configure SSL/TLS:
  • trafficparrot.virtualservice.grpc.tls.port
    The port number to use when recording/replaying TLS traffic
  • trafficparrot.virtualservice.grpc.requireClientAuthentication
    Set to true when client authentication is required and false otherwise
  • trafficparrot.virtualservice.grpc.serverTrustPemUrl
    X.509 certificate collection file in PEM format that will be trusted by the virtual GRPC server
  • trafficparrot.virtualservice.grpc.serverPemUrl
    X.509 certificate chain file in PEM format that will be the public key of the virtual GRPC server
  • trafficparrot.virtualservice.grpc.serverKeyUrl
    PKCS#8 private key file in PEM format that will be the private key of the virtual GRPC server
  • trafficparrot.virtualservice.grpc.clientTrustPemUrl
    X.509 certificate collection file in PEM format that will be trusted by the virtual GRPC client
  • trafficparrot.virtualservice.grpc.clientOverrideAuthority
    Overrides the authority used with TLS and HTTP virtual hosting. It does not change what host is actually connected to. Is commonly in the form host:port
If client authentication is required use the following additional properties:
  • trafficparrot.virtualservice.grpc.clientPemUrl
    X.509 certificate chain file in PEM format that will be the public key of the virtual GRPC client
  • trafficparrot.virtualservice.grpc.clientKeyUrl
    PKCS#8 private key file in PEM format that will be the private key of the virtual GRPC client

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/lib/virtualservice-x.y.z/virtualservice-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.

Recording and replaying GRPC

Introduction

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:
GRPC unary communication

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.

Recording and replaying GRPC messages using provided proto files

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.

Recording GRPC messages using provided proto files
Steps to perform a recording using provided proto files
  1. Start Traffic Parrot
  2. Configure Traffic Parrot with your proto files
  3. Go to the GRPC record page
  4. Enter the host and port of the GRPC server to record
  5. Click "Start recording"
  6. Reconfigure your system under test to connect to the virtual service GRPC server (by default this is localhost:50051)
  7. Execute a test case to allow Traffic Parrot to record requests and responses. They will appear on the Messages and Mappings lists on the web page as shown on Mappings and messages lists during recording image.
  8. Click "Stop recording"

As the system under test generates messages and receives responses they are paired into mappings and listed in the 'Mappings' table.

Mappings list during a GRPC recording

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.

Replaying GRPC messages using provided proto files
Steps to perform a replay using provided proto files
  1. Start Traffic Parrot
  2. Configure Traffic Parrot with your proto files
  3. Reconfigure your system under test to connect to the virtual service GRPC server (by default this is localhost:50051)
  4. Traffic Parrot will replay recorded mappings when it is not in record mode

Recording and replaying GRPC messages using GRPC server reflection

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.

Recording GRPC messages using GRPC server reflection
Steps to perform a recording using GRPC server reflection
  1. Start Traffic Parrot
  2. Go to the GRPC record page
  3. Enter the host and port of the GRPC server to record
  4. Click "Start recording"
  5. Reconfigure your system under test to connect to the virtual service GRPC server (by default this is localhost:50051)
  6. Execute a test case to allow Traffic Parrot to record requests and responses. They will appear on the Messages and Mappings lists on the web page as shown on Mappings and messages lists during recording image.
  7. Click "Stop recording"

As the system under test generates messages and receives responses they are paired into mappings and listed in the 'Mappings' table.

Mappings list during a GRPC recording

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.

Replaying GRPC messages using recorded proto files
Steps to perform a replay using provided proto files
  1. Start Traffic Parrot
  2. Reconfigure your system under test to connect to the virtual service GRPC server (by default this is localhost:50051)
  3. Traffic Parrot will replay recorded mappings when it is not in record mode

Edit GRPC mappings

Introduction

On the following GRPC pages, the edit button will allow you to edit an existing mapping:
  • Add/Edit
  • Record

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.

Edit GRPC mapping screenshot
Supported features
  • Edit response message values
  • Edit response message structure (e.g. delete optional fields, add items to list, add nested fields)
  • Use helpers in the response body
  • Use parts of the request message in the response message by extracting with JsonPath
  • Match request messages using the request body matchers (e.g. JsonPath, contains, regexp) on the JSON representation of the message
Currently, editing header values is not yet possible and only the message body can be edited. Please contact help@trafficparrot.com to be notified of when edit functionality is ready.

GRPC streaming modes

Introduction

Traffic Parrot currently supports the following GRPC streaming modes:
  • Unary RPC
  • Server streaming RPC
Please contact help@trafficparrot.com to be notified when other streaming modes are supported.

Unary RPC

In this mode:
  • There is one request and one response per RPC call.
  • Traffic Parrot represents this as a single request/response mapping.

Server streaming RPC

In this mode:
  • There is one request and multiple responses per RPC call.
  • Traffic Parrot represents this as multiple request/response mappings.
  • Each mapping has a MessageNumber in the mapping file that represents the order of the responses.
  • Each mapping has a CallId in the mapping file that represents which RPC call the mapping belongs to.
  • The request matcher is duplicated for each mapping.

Proof of concept with on-premises installation at a large enterprise

See proof of concept in the user guide.

Custom extensions

Have a look at available extensions