Introduction

Data learning is possible in Virtualize for HTTP traffic using the “Learn responses” feature in a Message Proxy. With this feature, Virtualize will learn and emulate responses recorded from a live HTTP endpoint and update a virtual asset to the most current state. The virtualized endpoint can then be used as a reliable failover when the real endpoint is not available. This minimizes the set-up efforts associated with service virtualization and reduces maintenance costs.

Overview

Generally speaking, setting up a data learning environment involves the following steps:

  1. Configure a message proxy for data learning.
  2. Update the AUT to point to the message proxy URL.
  3. From the AUT, invoke the message proxy to begin data learning.
  4. Observe the auto-generated virtual asset and traffic files from data learning.
  5. Update the message proxy to point to the Virtual Asset endpoint.

In this topic, we will discuss the process generally and show it in practice using the public version of ParaBank.

Configure a Message Proxy

  1. Start your Virtualize Server and create a new message proxy. Open the proxy.
  2. On the HTTP Listener tab, configure a listener for the connection (for example, on port 9088). HTTP listeners simplify the connection configuration for recording HTTP traffic.
  3. On the Connections tab, add an HTTP Reverse Message Proxy with the following configuration:
    • Choose the listener you created previously from the Reverse Proxy menu.
    • Set the proxy listen path to [All] to listen on all paths for the service. This will make it easier to update the AUT since the only change needed would be to update the host and port (for example, http://my-machine.domain.com:9088/).
    • Set the primary URL to point to the AUT service endpoint: http://remote-machine.domain.com:8080. Any paths and query parts sent to the proxy URL will be forwarded to the primary URL automatically. See Service Forward Path and Proxy Listen Path.
    • Set the secondary endpoint to point to a path to a virtual asset. This virtual asset does not need to already exist; at runtime, a virtual asset will be automatically generated using the same name as the path specified in the secondary endpoint. So, if you enter /my-virtual-asset as the path, an asset named “my-virtual-asset” will be created for you.
    • Enable Use other connection if selected mode fails.
    • Enable Learn responses.

Doing It with ParaBank

To use the public ParaBank, set the primary URL to http://parabank.parasoft.com and the secondary endpoint to something like /parabank.

Point to the Proxy URL

Modify the client application to point to the where the Virtualize message proxy is running. Because you set up the HTTP Listener earlier, this is as simple as changing the host and port. For example, let's say the following is true:

  • Your REST API service runs at remote-machine.domain.com:8080 
  • The proxy URL is my-machine.domain.com:9088
  • Your client application invokes your REST API service using the following endpoint: http://remote-machine.domain.com:8080/ABC/XYZ/11111/data

With the message proxy configured the way it is, all you need to do to update the client application is change the host and port of that endpoint: http://my-machine.domain.com:9088/ABC/XYZ/11111/data

Doing It with ParaBank

When using ParaBank, the REST API service uses the endpoint http://parabank.parasoft.com:8080/parabank/services/bank/customers/12212/accounts to retrieve all the accounts registered to customer 12212. Running Virtuailze locally with the reverse message proxy we set up, we would use http://localhost:9088/parabank/services/bank/customers/12212/accounts instead.

Invoke the Proxy and Confirm Data Learning Assets Are Created

From your client application, make some calls to invoke the message proxy and begin data learning. Then, open Virtualize and:

  1. Click the Virtual Asset Explorer tab (if it's not already open, go to Window > Show View > Virtual Asset Explorer) and open the /VirtualAssets/generated_by_data_learning directory.
  2. Expand the my-virtual-asset.pva found there. You should see a Request/Response Files responder that was automatically generated.
  3. Click the Project Explorer tab (if it's not already open, go to Window > Show View > Project Explorer) and open the /VirtualAssets/generated_by_data_learning/my-virtual-asset_files/data_learning directory. You should see some traffic files that have been generated. These will be used to match incoming messages.

Doing It with Parabank

Open a browser and go to http://localhost:9088/parabank/services/bank/customers/12212/accounts. That's enough to create the necessary directories and start storing data, with a responder in the Virtual Asset Explorer

and traffic files in the Project Explorer

Point the Message Proxy to the Virtual Asset Endpoint

Go back to the Virtualize Server tab and right-click the message proxy you created at the beginning of this process. Enable Set HTTP Mode: Secondary to route traffic to the Virtual Asset.

With this configuration, traffic will be routed to the Virtual Asset before the live service. If the asset fails to match an incoming request against the generated traffic files, the proxy will fall back to the live service and will generate new traffic files for the new learned data.

  • No labels