Creating a Mock Service

In BlazeMeter, you can create a Mock Service from transactions, from a recording, or from a template. in BlazeMeter, a "Service" is the representation of the underlying live service, and it serves as a container for the Transactions.

After creating the Mock Service, set up transactions:

For Private Locations

create-a-ms.png

Create a Mock Service from a New Service

In this scenario, you first create a new Service, and you upload transactions from a supported file type to the Service. Then you create a Mock Service from the Service.
If you already have an existing Service contain transactions, see Create a Mock Service from an Existing Service.

Follow these steps:

  1. Navigate to the Service Virtualization tab and click Mock Services.
  2. In the Mock Services section, click the + button to create a new Mock Service, and select Create from Transactions.
    A new row is added to the top of the Mock Services list.
  3. Enter a Mock Service name in the Name field.
  4. Click the arrow next to the Mock Service name to expand the details for the Mock Service.
  5. (Optional) Enter a Description for your Mock Service.
  6. (Optional) Select a Configuration. Define attribute-value pairs for your environment variables on the Configurations tab.
  7. (Private Location only) Under Create Log, enable or disable logging on the Private Location. If enabled, it will create one log file per virtual service on the Private Location, or if the file exists, append the log.
  8. Drag your transaction file into the upload area, or click the Upload area to browse to the file. This file should contain all of the transactions that you want to use for your Mock Service.

    Note: To upload multiple Swagger files using a zip file, the main file in the zip file must be named index.json or index.yaml for the upload to work.

    upload area

    The Import Transactions dialog opens.

    import transactions

  9. Select the Service you want to add these transactions to. The Service is a representation of the underlying live service, and it serves as a container for the Transactions you will upload.
    • If an existing Service contains Transactions that are needed for this Mock Service, select the existing Service.
    • Or create a new service:
      1. Click Add Service.
      2. (Optional) To assign one or more tags, type the tag name(s) in the Tags field and press Enter.

        Tip: Tags make Transactions easier to identify, especially within a large Service. You can provide tag definitions here to apply the defined tags to all imported Transactions. Or you can define tags at the Transaction level after import. To enter multiple tags, press Enter after each tag name.

      3. Click Import.
  10. In the Service drop-down list, choose the Service you just selected or created.
  11. In the Location drop-down list, select the location that you want to deploy your Mock Service to. Select from the available Google Cloud Platform locations (US East or EU West) depending on your location. Or select a Private Location.
  12. Select either HTTPS or HTTP from the Endpoint drop-down list. The default is HTTPS.
  13. (Optional) If you plan to run the Mock Service in a private location, select a preferred port in the Port field.
    preferred-port.png
    For more information about preferred ports, see Select a Preferred Port.

 

Create a Mock Service from an Existing Service

In this scenario, you create a Mock Service by selecting an existing service that already contains the transactions that you need for your Mock Service.

Follow these steps:

  1. Navigate to the Service Virtualization tab and click Mock Services.
  2. In the Mock Services section, click the + button to create a new Mock Service, and select Create from Transactions.
    A new row is added to the top of the Mock Services list.
  3. Enter a Mock Service name in the Name field.
  4. Select the Service that contains the Transactions that you need for your Mock Service.
  5. Select the location that you want to deploy your Mock Service to from the Location drop-down list. Select from the available Google Cloud Platform locations (US East or EU West) depending on your location. Or select a private location.
  6. Select either HTTPS or HTTP from the Endpoint drop-down list. The default is HTTPS.
  7. (Optional) If you plan to run the Mock Service in a private location, select a preferred port in the Port field.
    preferred-port.png
    For more information about preferred ports, see Select a Preferred Port.
  8. Click the arrow next to the Mock Service name to expand the details for the Mock Service.
  9. (Optional) Enter a description for your Mock Service.
  10. (Private Location only) Under Create Log, enable or disable logging on the Private Location. If enabled, it will create one log file per virtual service on the Private Location, or if the file exists, append the log.

Create a Mock Services Using the BlazeMeter Proxy Recorder

You can record a series of interactions from your browser, capture those interactions as transactions, and create a mock service based on those transactions. Use the BlazeMeter Proxy Recorder to record the interactions.

Follow these steps:

  1. Navigate to the Service Virtualization tab and click Mock Services.
  2. In the Mock Services section, click the + button to create a new Mock Service, and select Create from Recording.
    The BlazeMeter Recorder page opens in a separate tab.
  3. Follow the steps (starting with Step 3) in Creating the Proxy Recorder to create your proxy for recording.
  4. Follow the steps for setting up recording based on your operating system:
  5. Click the Record button and record the necessary interactions within your application.
  6. Click Pause when finished.
  7. Click Mock Service to export the recording to a Mock Service.
    This creates a Mock Service under the selected Service with all of the recorded Transactions assigned to it.
  8. Disable any proxy settings you had to enable to create the recording.

Create a Mock Service from a Mock Service Template

At any time after saving the Template, click Create Mock Service to the right of the Template name to dynamically provision a Mock Service that includes the transactions in the Template.

  1. Go to the Mock Service Templates section.
  2. In the Actions column, click the Create Mock Service button.
    template_negative_scenarios.png

Your Mock Service is created, and you can find it in the Mock Services section.

Other template actions include:

  • Assign a template to a Mock Service
  • Create a Mock Service template from a Mock Service

For more information, see Creating a Mock Service Template.

Add/Remove Transactions

After you have created a Mock Service, the next step is always to define its transactions and parameters.

 

On the Transactions tab:

  1. Select transactions that you want to include. You have several options:
    • Search and filter transactions in the columns by entering a tag or search text.

    • To select all transactions visible in the column (not all Transactions in the service), click the check box in the column header.

    • Or, manually select checkboxes in the columns.
  2. Move selected transactions from the Other Transactions in Your Catalog column to the Transactions in This Mock Service column.
    You have several options how to do this:
    • Click the Right Arrow to move selected transactions from Other Transactions in Your Catalog column to the Transactions in This Mock Service column. Select checkboxes in the Transactions in This Mock Service column and click the Left Arrow to remove these transactions from the Mock Service.
      transactions tab
    • Use the quick action to move selected transactions with a single click: Click the Include this transaction in the Mock Service icon in the left column. To remove a transaction from the Mock Service, click the corresponding Remove this transaction from the Mock Service icon in the right column.
      include-transaction-quick.png

      remove-transaction-quick.png

  3. (Optional) In Transactions in This Mock Service column, expand each transaction and define a Priority to control the matching order when a request matches multiple transactions. The transaction with the lowest priority number matches first. For details, see Priority of Multiple Matching Transactions in a Mock Service.
    priorityvaluetransaction.PNG


On the Parameters tab:

  1. (Optional) In the Think Time section, define an artificial delay between the request and the response. For more information, see Simulating Irregular Response Latencies.
    Default: "No Delay".
  2. (Optional) In the No Matching Requests section, choose the correct logic for when a request against the Mock Services does not match any of the provided transactions. The request can either throw an error or be redirected to the live service.
    Default: Return no match found (404)
  3. (Optional) In the Proxy section, define a proxy to connect to the live system endpoint.
    Default: No proxy
    • Proxy URL
    • Username
    • Password
    • Certificate — Upload or select a certificate needed for the connection.
    • No Proxy — Provide a comma-separated list of URLs to exclude from this proxy.
  4. (Private Locations/Docker only) Select an SSL Authentication:

    • No Authentication (default)

    • 1-way SSL

    • 2-way SSL



    Select an existing Keystore or upload a new one. Provide the Keystore Password and the password used to access individual keys in the keystore.

    (Optional) To define how to identify during SSL/TLS communication using an alias for a private key entry defined in your keystore, select the Alias and provide an Alias Password.
  5. Click Save.

    Your Mock Service is saved and added to the list of available Mock Services.

    mock_services_list.png

The Mock Service is not active until you run it.

Click Run Mock Service to run it. For information about the next steps, see Running a Mock Service.

 

Modify Transactions in a Running Mock Service

You can add and remove transactions or modify existing transactions without having to restart the Mock Service.

  • To add a transaction to or remove it from the Mock Service, update the Mock Service's transaction list in the Mock Services tab and then click the Update button. When you run the test again, the changes will be reflected.
  • To modify a transaction, make the changes and click Save in the transaction. Then click the Update button in the Mock Services tab. When you run the test again, the changes will be reflected.

Note: To edit Configurations, stop the running Mock Service, change the configuration, and redeploy the Mock Service.

Add Transactions to the Service

To add Transactions to a Service, you can upload additional Transactions on the Service Virtualization tab without having to switch tabs. Drop a file into the upload area or click the Plus button to create new Transactions. For more information about supported transaction file formats, see Adding Transactions.

Define Priority of Multiple Matching Transactions in a Mock Service

When you test against a Mock Service, the Mock Service first attempts to match incoming requests against any of its Transactions. The Transactions can be explicitly spelled out requests or regular expressions. When a Mock Service receives a request that matches multiple Transactions, the Mock Service chooses the Transaction with the lowest value in the Priority field.

Examples:

  • Say you have a Mock Service for a service that searches by zip code with two transactions. Transaction A matches a parameter value of 75024, and Transaction B matches any five-digit number. You want the Transaction with the more specific matching criteria (Transaction A) to have the higher priority so that it matches first, and the broader matching criteria (Transaction B) shall only match if the specific zip for Transaction A is not entered, so you give it lower priority.
  • After importing 100 transactions, they are all assigned the same default priority of 10. Fifteen of them are generic transactions that should be matched only after the more specific eighty five are matched. You don't want to have to manually change the priority level of eighty five transactions to 9. In this case, it's quicker to give the fifteen generic transactions a priority of 20, below the default of 10.

Consider this matching logic when determining which Transactions to add to a Mock Service, and whether one or more Mock Services are required to meet your testing requirements.

Note: Setting a Priority for a Transaction only applies to that Transaction within the current Mock Service. In other Mock Services or templates, the same Transaction may have a different priority value.

Every transaction is added with the default priority level of 10.

  • To have a Transactions match first, set its priority to 1.

  • To have a Transactions match before another, set its priority to a lower number.

  • To have a Transactions match after another, set its priority to a higher number.

  • To have a Transactions match last, set its priority to 20.

You can assign the same priority to multiple transactions. Therefor it can happen that multiple matching Transactions have the same priority. In this case, the Mock Service chooses the most recent Transaction first (the one with the highest Transaction ID number). To have fine control over the priority over default transactions, assign them unique priorities. Unique priorities use an index counter that defines the order without ambiguity.

To assign unique priorities:

  1. Add transactions that can match.

  2. Enable Unique Priorities.
    The Customize Unique Transaction Priorities window opens and a table lists all included transactions.

  3. Arrange the rows in order of highest to lowest priority. You can use the following methods:

    • Click the handle and drag a transaction up to increase its priority.

    • Click the handle and drag a transaction down to decrease its priority.

    • To reorder a transactions to be first, click Move Transaction to Beginning.

    • To reorder a transactions to be last, click Move Transaction to End.

    • Tip: To reorder multiple transactions, enable their checkboxes and click the Move Transaction to Beginning or Move Transaction to End button (resspectively) above the table.

To reorder priorities after Unique Priority has been enabled, click the Customize button .

 

(Private Locations/Docker) Select a Preferred Port

If you plan to run the Mock Service in a private location and you are creating a Docker-based transaction Mock Service, you can define a preferred port. If the port is available, it will be assigned to the Mock Service.

  • If you leave the Port field blank, a port is chosen from the range defined for the Private location. For more information, see Setting Port Range on Your Agent.
  • If the preferred port is outside of the defined port range, a notification message is shown and a new port within the defined range has to be entered.
  • If an existing service is running on the preferred port already, a notification message appears when you run the Mock Service. BlazeMeter then selects the first available port within the defined range.

To update the preferred port for a Mock Service running in a Docker-based private location, stop the running Mock Service, update the existing preferred port to the new port number, and then run the Mock Service again. If the port is available, it will be assigned to the Mock Service.

(Private Locations/Kubernetes) Rules for Endpoints Generated for Kubernetes Mock Deployment

The URL format is the following:

http(s)://(mock-name[40])(serviceid[9])-<port>-<namespace>.<sub-domain> 
  • Mock name

    First 40 lowercase alpha numeric characters of the mock name.
  • Service ID

    ID associated with the service name. Service ID is used in the endpoints that are generated after you deploy your Mock Service. When you know your service ID, you can predict the format of your Mock Service endpoint.

    Note: You can view the Service ID in the Service drop-down list and copy it to clipboard.

    show-service-id.png

  • Port

    8080 for transaction mock services.
  • Namespace

    Kubernetes namespace
  • Sub-domain

    Configured as a part of an agent set up.

Mock Service names can be more than 40 characters. If the first 40 characters of the name conflict with any other existing mock service name, a unique ID is added to the endpoint in the following format:

http(s)://(mock-name[40])(some uid[4])(serviceid[9])-<port>-<namespace>.<sub-domain>

In a very rare case for private cloud mock deployments: If you specify a mock service name to be a lowercase alphanumeric string with 128-character length, it is treated as an encoded string and the old format for endpoint is used to support backward compatibility.

The old format for Transaction mock services is the following:

http(s)://servicemock<mock_id>-8080-<k8s_namespace>.<sub-domain>