In BlazeMeter, you can create a Mock Service from existing transactions or from a recording.
- FromTransactions
- From Recording
- From Template
This article also covers the following related procedures and concepts:
- Add, Remove and Modify Transactions in a Running Mock Service
- Select a Preferred Port
- Rules for Endpoints Generated for Kubernetes Mock Deployment
- Adding Transactions to Mock Services
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 newly created service.
If you have an existing service with transactions already, see Create a Mock Service from an Existing Service.
Follow these steps:
- Navigate to the Mock Services tab and click Mock Services.
- 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. - Enter a Mock Service name in the Name field.
- Click the arrow next to the Mock Service name to expand the details for the Mock Service.
- Enter a description for your Mock Service.
- Drag your transaction file into the upload area.
- This file should contain all of the transactions that you want to use for your Mock Service.
Note: If you want 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.
Tip: You can also click the Upload area to browse to the file.
The Import Transactions dialog opens.
- 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:
- Click Add Service.
- (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.
- Click Import.
- In the Service drop-down list, choose the Service you just selected or created.
- 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.
- Select either HTTPS or HTTP from the Endpoint drop-down list. The default is HTTPS.
- (Optional) If you plan to run the Mock Service in a private location, select a preferred port in the Port field.
For more information about preferred ports, see Select a Preferred Port. - In the Transactions tab, select the check box for each Transaction that you want to include in your Mock Service and click the arrow to move them from the Other Transactions in Your Catalog column to the Transactions in This Mock Service column.
Tip: You can use a quick action to move 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, you can click the Remove this transaction from the Mock Service icon in the right column.
Note: You can search by tag or text in the Other Transactions in Your Catalog column to find the Transactions that you want to include. Click the check box in the header to select all Transactions. This check box selects all of the Transactions on the current page. It does not select all Transactions in the service.
- (Optional) In Transactions in This Mock Service column, expand each Transaction in the Mock Service and enter values in the Priority field to control the matching order to follow when a request matches multiple Transactions. For details, see Priority of Multiple Matching Transactions in a Mock Service.
The Transaction with the lowest number matches first. By default, all Transactions have the same Priority value, and a multiple matching scenario matches on the Transaction with the highest ID number. - Click the Parameters tab.
- (Optional) Set the Think Time to control an artificial delay between the request and the response. The default is "No Delay". For more information, see Simulating Irregular Response Latencies.
- In the No Matching Requests field, 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.
- Click Save.
Your Mock Service is saved and added to the list of available Mock Services.
The Mock Service is not active until you run it. Click Run Mock Service to run it. See Running a Mock Service for the next steps.
For more information about supported transaction file formats, see Adding Transactions.
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:
- Navigate to the Mock Services tab and click Mock Services.
- 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. - Enter a Mock Service name in the Name field.
- Select the Service that contains the Transactions that you need for your Mock Service. The Service is a representation of the underlying live service, and it serves as a container for the Transactions.
- 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.
- Select either HTTPS or HTTP from the Endpoint drop-down list. The default is HTTPS.
- (Optional) If you plan to run the Mock Service in a private location, select a preferred port in the Port field.
For more information about preferred ports, see Select a Preferred Port. - Click the arrow next to the Mock Service name to expand the details for the Mock Service.
- (Optional) Enter a description for your Mock Service.
- Select the check box for each Transaction you want to include in your Mock Service and click the arrow to move them from the Other Transactions in Your Catalog to column and add them to the Transactions in This Mock Service.
Tip: You can use a quick action to move 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, you can click the Remove this transaction from the Mock Service icon in the right column.
Note: You can search by tag or text in the Other Transactions in Your Catalogs column to find the Transactions you want to include. Click the check box in the header to select all Transactions. This check box selects all of the Transactions on the current page. It does not select all Transactions in the Service.
- (Optional) In Transactions in This Mock Service column, expand each Transaction in the Mock Service and enter values in the Priority field to control the matching order to follow when a request matches multiple Transactions.
The Transaction with the lowest number matches first. By default, all Transactions have the same Priority value, and a multiple matching scenario matches on the Transaction with the highest ID number.
Setting a priority for a Transaction only applies to that Transaction within the specific Mock Service. In other Mock Services or templates, the Transaction may have a different priority value. - Click the Parameters tab.
- (Optional) Set the Think Time to control an artificial delay between the request and the response. The default is "No Delay". For more information, see Simulating Irregular Response Latencies.
- In the No Matching Requests field, 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.
- Click Save.
Your Mock Service is saved and added to the list of available Mock Services.
The Mock Service is not active until you run it. Click Run Mock Service to run it, and see Running a Mock Service for next steps.
Add, Remove and Modify Transactions in a Running Mock Service
For a transactional Mock Service, you can add and remove transactions or modify existing transactions without having to restart the Mock Service.
- To add or remove a transaction, update your transaction list and click the update button in the Mock Services tab. When you run the test again, the changes will be reflected.
- To modify a transaction, make the changes as needed and click save. Then click the update button in the Mock Services tab. When you run the test again, the changes will be reflected.
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.
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:
- Navigate to the Mock Services tab and click Mock Services.
- 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. - Follow the steps (starting with Step 3) in Creating the Proxy Recorder to create your proxy for recording.
- Follow the steps for setting up recording based on your operating system:
- Click the Record button and record the necessary interactions within your application.
- Click Pause when finished.
- 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. - 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.
- Go to the Mock Service Templates section.
- In the Actions column, click the Create Mock Service button.
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.
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. - 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>
Adding Transactions to Mock Services
If you want to add Transactions to the Service, you can upload additional Transactions on the Mock Services tab without having to switch tabs. As you create your Mock Service, you can select the specific Transactions that you want to include.
Priority of Multiple Matching Transactions in a Mock Service
When you test against a Mock Service, the Mock Service attempts to match an incoming request against any of its Transactions. The Transactions can be fully formed requests or regular expressions that an incoming request will match against. When a Mock Service receives a request that would be a match with multiple Transactions, the Mock Service matches against the Transaction with the lowest number in the Priority field first.
Setting a Priority for a Transaction only applies to that Transaction within the current Mock Service. In other Mock Services or templates, the Transaction may have a different priority value.
Every new transaction is created with a default priority level of 10. To have a Transactions match before any others, set its priority level to a lower number. Priority level 1 is always matched first. To have a Transactions match after all transactions with priority 10, select priority level 20. If multiple Transactions have the same priority, the Mock Service matches the most recent Transaction first (the one with the highest Transaction ID number).
Examples:
- If you have a Mock Service for a service that searches by zip code with two transactions: Transaction A matches on a parameter value of 75024, and Transaction B matches any five-digit number. You may want the Transaction with the more specific matching criteria (Transaction A) to have the higher priority value so that it matches first, and the broader matching criteria (Transaction B) is only matched if the specific zip for Transaction A is not entered.
- 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 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 testing requirements.
0 Comments