简体   繁体   中英

overwrite csv file using jmeter beanshell

i'm testing an API service using OAuth tokens. we have to divide the load per api service, therefore i seperated all services in different thread groups (also to make requests in parallel). since extracted OAUTH tokens (you need the acces token to make request to api) are only local to thread groups, i used a small beanshell script to write all tokens to a CSV file. later on, these tokens are used when doing the API calls.

the problem i'm facing is that the 'CSV Dataset Config' element is pre-loaded in memory (correct me if wrong), and because the tokens arent received yet at that point my API calls are failing with regex EOF. this happens only a few times where after the request succeed. i implemented a once only controller for the api requests to implement some thinktime, but this does only helps waiting for all users to get authenticated and receive the tokens.

question 1: how can i read token values in realtime from the CSV file for each api call (using custom code/beanshell)?

question 2: how can i make my beanshell script (see below) REWRITE the whole csv file each time the oauth2 sequence is run (now it keeps on appending to it..) ?

situation:

在此处输入图片说明

Issue fixed using 2 seperate testplans;

plan A) do one iteration with X amount of needed concurrent users to generate needed tokens + write tokens to CSV file.

plan B) call all API services divided in Throughput Controllers using CSV dataset (OAUTH sequence not needed).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM