Jmeter Read Data From Database and Use Use Result to Acall Api

SAP Commerce Cloud (previously known equally SAP Hybris Commerce) is often used as headless service to be used with SAP Spartacus or 3rd-party storefront solutions. The communication between the storefront and the platform happens via the SAP Commerce REST interface called Omni-Channel Connect (OCC). Additionally, SAP Commerce Cloud provides a set up of APIs for integration (Integration APIs), content and product management (CMS and Production Management APIs).

All these APIs are highly customizable, and even smallest changes in configuration, information model or Coffee code may result in performance degradation. Operation testing is especially important in cases where concurrency may be the source of the problem. To recognize and gear up such issues timely, it is recommended to perform regular operation testing, ideally integrated into the build and deployment pipelines.

However, SAP Commerce Cloud intensively uses caching and the exam plans may non reflect the true state of affairs if not designed properly. Nigh all database queries are cached inside the platform so that the thousands of data fetching operations (per a webservice call)  don't fifty-fifty attain the database. If a cache was disabled, an average single telephone call would take minutes. Fortunately, the cache is always on, but depending on many factors information technology may or may non piece of work efficiently.

The test scenarios should be designed in such a manner that they mimic the real-fourth dimension user action happening in the production. If your production catalog has thousands of products, and you wait a normal distribution, it will be a bad idea to test the system against just a small bunch of examination products. You may confront the risk that Commerce Deject demonstrates exceptional performance with this modest bunch of products, but completely different results with the actual traffic.

In society to mimic user behavior, API sample calls tin exist either generated or collected from the logs. For the APIs, this dataset has a combination of when and what: a timestamp, a list of URLs, an HTTP method, a fix of HTTP headers, GET and Mail payloads. Information technology is often easier to simplify the model by firing the calls in some pattern reflecting the actual traffic in its average approximations.

In my project, I needed to generate a listing of URLs and JSON payloads to go them close to what system will experience after go-live. In my test plan, I needed to read the Mail service payload from a file and ship it as a body for a POST request to the Residual API, parse the response, and log the response fourth dimension forth with a response code and webservice response body. I also needed to control the pattern of the load and visualize the results.

For example, you accept 10000 products, and you need to load examination the product details API (customer facing) and product stock update API (used by the internal systems). For both, yous need to inject a product code to the URL (in case of production details API) or in the JSON (for the stock update).

What tool are you using to create such a load for regular checking the functioning? I worked with iii:

  • Apache JMeter (Java)
  • Tsung (Erlang)
  • Custom-made (Python, asyncio+matplotlib).

In this article, I explain how to utilise JMeter for the SAP Commerce API and storefront testing and what challenges you may come up across along this way.

This article is office of a series on functioning testing:

  • Function 1. SAP Commerce Cloud Performance Testing Tools: Apache JMeter
  • Part 2. Operation Testing Tools: Tsung
  • Role 3. Operation Scripting: Writing Load Generators from Scratch

Apache JMeter

Apache JMeter is one of the most pop and oldest open source tools for operation and load testing. It is normally used in the performance testing, simply I believe this tools should be used by the developers too to catch the issues at the earliest and deliver better code.

JMeter can be configured to ship different combinations of unique URLs with the unique Post payloads per URL. In the standard JMeter GUI, you can only specify how many users yous want to use during the test and how fast they should come as well equally specify the URL (with a payload) for generating a load. However, functions and variables allow you to implement complex scenarios.

In order to inject dynamic content to the HTTP Request sampler, y'all should use the variables:

${__FileToString(${__eval(${JSONFILE})},,)} extracts the contents of the file which name is in the JSONFILE variable and use information technology as a POST payload.

JSONFILE is a variable prepare by CSV Information Fix Config Element configured as follows:

If you lot need to employ more than than ane parameter, you can list them in the LIST_OF_JSONS.txt file specified in the Filename section.

For the exam above, this file contains a listing of total paths to the JSONs.

If nosotros need to add a new parameter to use it in the URL together with the JSONs, just add a new cavalcade:

          /Users/raaliev/perf/dev_out2/x.json,10          /Users/raaliev/perf/dev_out2/100.json,20          /Users/raaliev/perf/dev_out2/101.json,30          /Users/raaliev/perf/dev_out2/102.json,twoscore        

Then add the mapping into the CSV Data Set Config's Variable Names:

          JSONFILE,NO        

And use the "NO" variable in the HTTP Request sampler:

          Path: /${NO}/post        

In this example, nosotros used a__FileToString  office. This function allows you lot to read the file contents from the specifed file which is a variable in our example.

Some other useful function is__StringFromFile  which is basically the same as CSV Data Set Config, only the CSV Data Ready Config element is express to i file only. Using the office you lot can read multiple files. If the cease of the file is reached, the file is rotated.

For testing Commerce Cloud APIs, you lot volition need to add HTTP Header Manager:

and configure HTTP Authority Director:

If username and password are supposed to exist different for different calls, you can use __StringFromFile to extract the login and password from the CSV file.

For the OAuth-protected endpoints, we need to extract the authorization token and laissez passer it into the next asking.

First of all, we need to add one more "HTTP Request" sampler and configure it appropriately:

The response is a JSON structure with access_token in information technology. Then nosotros need to excerpt the access token. We need to add Regular Expression Extractor equally under the token HTTP request chemical element:

Theaccess_token  variable is used for the subsequent calls:

The similar arroyo tin be used for the storefront pages attainable only for the authenticated users. You need to

  • create a call to the login course, extract CSRF token (HTTP Request + Header Manager + Regular Expression Extractor)

  • create a call to Leap'southward /<context>/j_spring_security_check  with j_username, j_password and a CSRF token extracted from the previous call and extract the JSESSIONID cookie from the response. A Content-Blazon header should be fix to awarding/x-www-course-urlencoded.
  • create a telephone call to a target page using JSESSIONID cookie

For checking Add To Cart for an anonymous user yous need only CSRF extraction phase and populate the CSRF parameter of the add to cart form with the extracted value.

For API testing, y'all may find information technology useful to have multiple thread groups. The first one is responsible for a setup, hallmark and creating a user shopping cart. The last ane is responsible for retriving the results. In between, you lot can utilize a loop where hundreds of products are placed in the cart with the specified charge per unit.

The variables are designed to be local within a thread group. To pass them between different thread groups (such as setup and add together-to-cart), y'all can utilise BeanShell Assertion to save the variable as a global property.

The sample scenario for testing the shopping cart functionality may look as follows:

If yous need to inject a random ID to bypass caching, you tin can utilise a __UUID or __RandomString office.

To use JMeter for testing of storefront pages, you demand to keep a session up during requests. To implement that, you lot need to include HTTP Cookie Managing director config element. If you need to simulate user login, y'all need to include HTTP Request pointing at the spring security URL /j_spring_security_check). For the API testing, you need to extract a token to use it in the subsequent queries.

For the SAP Commerce Cloud Storefront Accelerator, the plans are provided by SAP:

          bin/ext-template/yacceleratortest/resources/jmeter/B2BAcceleratorTestPlan.jmx          bin/ext-template/yacceleratortest/resources/jmeter/MarketplaceAcceleratorTestPlan.jmx          bin/ext-template/yacceleratortest/resource/jmeter/AcceleratorTestPlan.jmx        

In this article, I explained how the original task can be solved with JMeter.

However, JMeter is far not as fast as Tsung and far not as flexible as Python. I am going to share the details near these 2 very presently.

Stay tuned!

washingtonhadvactice.blogspot.com

Source: https://hybrismart.com/2020/02/25/apache-jmeter-sap-commerce-cloud-performance-testing-tools/

0 Response to "Jmeter Read Data From Database and Use Use Result to Acall Api"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel